/
tracer.go
63 lines (46 loc) · 1.68 KB
/
tracer.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package datadog
import (
"context"
"sync"
"github.com/americanas-go/ignite/net/http/client"
"github.com/americanas-go/log"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
// StartTracer starts the tracer like StartTraceWithOptions but with default Options.
func StartTracer(ctx context.Context, startOptions ...tracer.StartOption) {
o, err := NewOptions()
if err != nil {
panic(err)
}
StartTracerWithOptions(ctx, o, startOptions...)
}
var tracerOnce sync.Once
// StartTracerWithOptions starts the tracer with the given set of options. It will stop and replace any running tracer, meaning that calling it several times will result in a restart of the tracer by replacing the current instance with a new one.
func StartTracerWithOptions(ctx context.Context, options *Options, startOptions ...tracer.StartOption) {
if !IsTracerEnabled() {
return
}
tracerOnce.Do(func() {
logger := log.FromContext(ctx)
httpClient := client.NewClientWithOptions(ctx, &options.HttpClient)
so := []tracer.StartOption{
tracer.WithAgentAddr(options.Addr),
tracer.WithEnv(options.Env),
tracer.WithService(options.Service),
tracer.WithServiceVersion(options.Version),
tracer.WithLogger(NewLogger()),
tracer.WithHTTPClient(httpClient),
tracer.WithAnalytics(options.Analytics),
tracer.WithAnalyticsRate(options.AnalyticsRate),
tracer.WithLambdaMode(options.LambdaMode),
tracer.WithDebugMode(options.DebugMode),
tracer.WithDebugStack(options.DebugStack),
}
for k, v := range options.Tags {
so = append(so, tracer.WithGlobalTag(k, v))
}
so = append(so, startOptions...)
tracer.Start(so...)
logger.Infof("started a datadog tracer: %s", options.Service)
})
}