This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request vitessio#5681 from kalfonso/kalfonso.200109-datado…
…g-tracing-plugin Add datadog plugin for tracing
- Loading branch information
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |