/
datadog.go
42 lines (35 loc) · 1.08 KB
/
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
41
42
package datadog
import (
"context"
"errors"
datadog "github.com/DataDog/opencensus-go-exporter-datadog"
opencensus "github.com/Dorkside/opencensus"
)
func init() {
opencensus.RegisterExporterFactories(func(ctx context.Context, cfg opencensus.Config) (interface{}, error) {
return Exporter(ctx, cfg)
})
}
func Exporter(ctx context.Context, cfg opencensus.Config) (*datadog.Exporter, error) {
if cfg.Exporters.DataDog == nil {
return nil, errDisabled
}
e, err := datadog.NewExporter(datadog.Options{
Namespace: cfg.Exporters.DataDog.Namespace,
Service: cfg.Exporters.DataDog.Service,
TraceAddr: cfg.Exporters.DataDog.TraceAddr,
StatsAddr: cfg.Exporters.DataDog.StatsAddr,
Tags: cfg.Exporters.DataDog.Tags,
GlobalTags: cfg.Exporters.DataDog.GlobalTags,
DisableCountPerBuckets: cfg.Exporters.DataDog.DisableCountPerBuckets,
})
if err != nil {
return e, err
}
go func() {
<-ctx.Done()
e.Stop()
}()
return e, nil
}
var errDisabled = errors.New("opencensus datadog exporter disabled")