diff --git a/go.mod b/go.mod index 0661ef2057e..8868f343adf 100644 --- a/go.mod +++ b/go.mod @@ -88,6 +88,7 @@ require ( google.golang.org/api v0.9.0 google.golang.org/genproto v0.0.0-20190926190326-7ee9db18f195 // indirect google.golang.org/grpc v1.24.0 + gopkg.in/DataDog/dd-trace-go.v1 v1.17.0 gopkg.in/asn1-ber.v1 v1.0.0-20150924051756-4e86f4367175 // indirect gopkg.in/ldap.v2 v2.5.0 honnef.co/go/tools v0.0.1-2019.2.3 diff --git a/go.sum b/go.sum index cb9c1f13a95..8ea036903a7 100644 --- a/go.sum +++ b/go.sum @@ -617,13 +617,13 @@ golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190719005602-e377ae9d6386/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= golang.org/x/tools v0.0.0-20190830154057-c17b040389b9 h1:5/jaG/gKlo3xxvUn85ReNyTlN7BvlPPsxC6sHZKjGEE= golang.org/x/tools v0.0.0-20190830154057-c17b040389b9/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191209225234-22774f7dae43 h1:NfPq5mgc5ArFgVLCpeS4z07IoxSAqVfV/gQ5vxdgaxI= -golang.org/x/tools v0.0.0-20191209225234-22774f7dae43/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190910044552-dd2b5c81c578/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911151314-feee8acb394c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190930201159-7c411dea38b0/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191010075000-0337d82405ff h1:XdBG6es/oFDr1HwaxkxgVve7NB281QhxgK/i4voubFs= golang.org/x/tools v0.0.0-20191010075000-0337d82405ff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191209225234-22774f7dae43 h1:NfPq5mgc5ArFgVLCpeS4z07IoxSAqVfV/gQ5vxdgaxI= +golang.org/x/tools v0.0.0-20191209225234-22774f7dae43/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191217033636-bbbf87ae2631/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20191219041853-979b82bfef62 h1:vDaiisQl0rGVXqk3wT2yc43gSnwlj4haEG5J78IGZP4= golang.org/x/tools v0.0.0-20191219041853-979b82bfef62/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= @@ -658,6 +658,7 @@ google.golang.org/grpc v1.21.1 h1:j6XxA85m/6txkUCHvzlV5f+HBNl/1r5cZ2A/3IEFOO8= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.24.0 h1:vb/1TCsVn3DcJlQ0Gs1yB1pKI6Do2/QNwxdKqmc/b0s= google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= +gopkg.in/DataDog/dd-trace-go.v1 v1.17.0/go.mod h1:DVp8HmDh8PuTu2Z0fVVlBsyWaC++fzwVCaGWylTe3tg= gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/asn1-ber.v1 v1.0.0-20150924051756-4e86f4367175 h1:nn6Zav2sOQHCFJHEspya8KqxhFwKci30UxHy3HXPTyQ= diff --git a/go/trace/plugin_datadog.go b/go/trace/plugin_datadog.go new file mode 100644 index 00000000000..87809d9bc50 --- /dev/null +++ b/go/trace/plugin_datadog.go @@ -0,0 +1,56 @@ +package trace + +import ( + "flag" + "fmt" + "io" + + "github.com/opentracing/opentracing-go" + "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentracer" + ddtracer "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" +) + +var ( + dataDogHost = flag.String("datadog-agent-host", "", "host to send spans to. if empty, no tracing will be done") + dataDogPort = flag.String("datadog-agent-port", "", "port to send spans to. if empty, no tracing will be done") +) + +func newDatadogTracer(serviceName string) (tracingService, io.Closer, error) { + if *dataDogHost == "" || *dataDogPort == "" { + return nil, nil, fmt.Errorf("need host and port to datadog agent to use datadog tracing") + } + + t := opentracer.New( + ddtracer.WithAgentAddr(*dataDogHost+":"+*dataDogPort), + ddtracer.WithServiceName(serviceName), + ddtracer.WithDebugMode(true), + ddtracer.WithSampler(ddtracer.NewRateSampler(*samplingRate)), + ) + + opentracing.SetGlobalTracer(t) + + return openTracingService{Tracer: &datadogTracer{actual: t}}, &ddCloser{}, nil +} + +var _ io.Closer = (*ddCloser)(nil) + +type ddCloser struct{} + +func (ddCloser) Close() error { + ddtracer.Stop() + return nil +} + +func init() { + tracingBackendFactories["opentracing-datadog"] = newDatadogTracer +} + +var _ tracer = (*datadogTracer)(nil) + +type datadogTracer struct { + actual opentracing.Tracer +} + +func (dt *datadogTracer) GetOpenTracingTracer() opentracing.Tracer { + return dt.actual +}