-
Notifications
You must be signed in to change notification settings - Fork 3
/
datadog.go
40 lines (33 loc) · 928 Bytes
/
datadog.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
package datadog
import (
"context"
"fmt"
"github.com/alexfalkowski/go-service/os"
"github.com/alexfalkowski/go-service/trace/opentracing/logger"
"github.com/opentracing/opentracing-go"
"go.uber.org/fx"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentracer"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
// TracerParams for datadog.
type TracerParams struct {
Lifecycle fx.Lifecycle
Name string
Host string
}
// NewTracer for datadog.
func NewTracer(params TracerParams) opentracing.Tracer {
opts := []tracer.StartOption{
tracer.WithService(fmt.Sprintf("%s:%s", os.ExecutableName(), params.Name)),
tracer.WithAgentAddr(params.Host),
tracer.WithLogger(logger.NewLogger()),
}
t := opentracer.New(opts...)
params.Lifecycle.Append(fx.Hook{
OnStop: func(ctx context.Context) error {
tracer.Stop() // important for data integrity (flushes any leftovers)
return nil
},
})
return t
}