Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request vitessio#5681 from kalfonso/kalfonso.200109-datado…
Browse files Browse the repository at this point in the history
…g-tracing-plugin

Add datadog plugin for tracing
  • Loading branch information
sougou authored Jan 19, 2020
2 parents 824f835 + 2455082 commit c4e06a1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,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
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,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=
Expand Down
56 changes: 56 additions & 0 deletions go/trace/plugin_datadog.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit c4e06a1

Please sign in to comment.