Skip to content

Commit 53cffcf

Browse files
committed
extend interface
1 parent 525940f commit 53cffcf

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

pkg/beholder/chip_ingress_emitter.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ func (c *ChipIngressEmitter) Close() error {
2626
}
2727

2828
func (c *ChipIngressEmitter) Emit(ctx context.Context, body []byte, attrKVs ...any) error {
29-
return c.BatchEmit(ctx, Message{
30-
Body: body,
31-
Attrs: ExtractAttributes(attrKVs...),
32-
})
29+
return c.BatchEmit(ctx, NewMessage(body, attrKVs...))
3330
}
3431

3532
func (c *ChipIngressEmitter) BatchEmit(ctx context.Context, messages ...Message) error {

pkg/beholder/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ import (
3131
const defaultGRPCCompressor = "gzip"
3232

3333
type Emitter interface {
34-
// Sends message with bytes and attributes to OTel Collector
34+
// Emit Sends message with bytes and attributes to OTel Collector
3535
Emit(ctx context.Context, body []byte, attrKVs ...any) error
36+
BatchEmit(ctx context.Context, messages ...Message) error
3637
io.Closer
3738
}
3839

pkg/beholder/message_emitter.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ func (e messageEmitter) Close() error { return nil }
2222
// Emits logs the message, but does not wait for the message to be processed.
2323
// Open question: what are pros/cons for using use map[]any vs use otellog.KeyValue
2424
func (e messageEmitter) Emit(ctx context.Context, body []byte, attrKVs ...any) error {
25-
message := NewMessage(body, attrKVs...)
26-
if err := message.Validate(); err != nil {
27-
return err
25+
return e.BatchEmit(ctx, NewMessage(body, attrKVs...))
26+
}
27+
28+
func (e messageEmitter) BatchEmit(ctx context.Context, messages ...Message) error {
29+
for _, message := range messages {
30+
if err := message.Validate(); err != nil {
31+
return err
32+
}
33+
e.messageLogger.Emit(ctx, message.OtelRecord())
2834
}
29-
e.messageLogger.Emit(ctx, message.OtelRecord())
3035
return nil
3136
}

0 commit comments

Comments
 (0)