-
Notifications
You must be signed in to change notification settings - Fork 2
/
sender_honeycomb.go
44 lines (36 loc) · 1.1 KB
/
sender_honeycomb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"context"
"github.com/honeycombio/beeline-go"
)
type SenderHoneycomb struct{}
// make sure it implements Sender
var _ Sender = (*SenderHoneycomb)(nil)
func NewSenderHoneycomb(opts *Options) *SenderHoneycomb {
beeline.Init(beeline.Config{
WriteKey: opts.Telemetry.APIKey,
APIHost: opts.apihost.String(),
ServiceName: opts.Telemetry.Dataset,
Debug: opts.DebugLevel() > 2,
})
return &SenderHoneycomb{}
}
func (t *SenderHoneycomb) Close() {
beeline.Close()
}
func (t *SenderHoneycomb) CreateTrace(ctx context.Context, name string, fielder *Fielder, count int64) (context.Context, Sendable) {
// a beeline span is already a Sendable
ctx, root := beeline.StartSpan(ctx, name)
for k, v := range fielder.GetFields(count, 0) {
root.AddField(k, v)
}
return ctx, root
}
func (t *SenderHoneycomb) CreateSpan(ctx context.Context, name string, level int, fielder *Fielder) (context.Context, Sendable) {
// a beeline span is already a Sendable
ctx, span := beeline.StartSpan(ctx, name)
for k, v := range fielder.GetFields(0, level) {
span.AddField(k, v)
}
return ctx, span
}