aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'plugin')
-rw-r--r--plugin/trace/README.md10
-rw-r--r--plugin/trace/setup.go34
-rw-r--r--plugin/trace/setup_test.go3
-rw-r--r--plugin/trace/trace.go20
4 files changed, 52 insertions, 15 deletions
diff --git a/plugin/trace/README.md b/plugin/trace/README.md
index a6d3bf82c..31e74ea71 100644
--- a/plugin/trace/README.md
+++ b/plugin/trace/README.md
@@ -16,8 +16,8 @@ The simplest form is just:
trace [ENDPOINT-TYPE] [ENDPOINT]
~~~
-* **ENDPOINT-TYPE** is the type of tracing destination. Currently only `zipkin` is supported
- and that is what it defaults to.
+* **ENDPOINT-TYPE** is the type of tracing destination. Currently only `zipkin` and `datadog` are supported.
+ Defaults to `zipkin`.
* **ENDPOINT** is the tracing destination, and defaults to `localhost:9411`. For Zipkin, if
ENDPOINT does not begin with `http`, then it will be transformed to `http://ENDPOINT/api/v1/spans`.
@@ -69,6 +69,12 @@ the standard Zipkin URL you can do something like:
trace http://tracinghost:9411/zipkin/api/v1/spans
~~~
+Using DataDog:
+
+~~~
+trace datadog localhost:8125
+~~~
+
Trace one query every 10000 queries, rename the service, and enable same span:
~~~
diff --git a/plugin/trace/setup.go b/plugin/trace/setup.go
index 2eb93c3a2..881ddc357 100644
--- a/plugin/trace/setup.go
+++ b/plugin/trace/setup.go
@@ -36,7 +36,7 @@ func setup(c *caddy.Controller) error {
func traceParse(c *caddy.Controller) (*trace, error) {
var (
- tr = &trace{Endpoint: defEP, EndpointType: defEpType, every: 1, serviceName: defServiceName}
+ tr = &trace{every: 1, serviceName: defServiceName}
err error
)
@@ -47,12 +47,12 @@ func traceParse(c *caddy.Controller) (*trace, error) {
args := c.RemainingArgs()
switch len(args) {
case 0:
- tr.Endpoint, err = normalizeEndpoint(tr.EndpointType, defEP)
+ tr.EndpointType, tr.Endpoint, err = normalizeEndpoint(defEpType, "")
case 1:
- tr.Endpoint, err = normalizeEndpoint(defEpType, args[0])
+ tr.EndpointType, tr.Endpoint, err = normalizeEndpoint(defEpType, args[0])
case 2:
- tr.EndpointType = strings.ToLower(args[0])
- tr.Endpoint, err = normalizeEndpoint(tr.EndpointType, args[1])
+ epType := strings.ToLower(args[0])
+ tr.EndpointType, tr.Endpoint, err = normalizeEndpoint(epType, args[1])
default:
err = c.ArgErr()
}
@@ -94,20 +94,30 @@ func traceParse(c *caddy.Controller) (*trace, error) {
return tr, err
}
-func normalizeEndpoint(epType, ep string) (string, error) {
- switch epType {
- case "zipkin":
+func normalizeEndpoint(epType, ep string) (string, string, error) {
+ if _, ok := supportedProviders[epType]; !ok {
+ return "", "", fmt.Errorf("tracing endpoint type '%s' is not supported", epType)
+ }
+
+ if ep == "" {
+ ep = supportedProviders[epType]
+ }
+
+ if epType == "zipkin" {
if !strings.Contains(ep, "http") {
ep = "http://" + ep + "/api/v1/spans"
}
- return ep, nil
- default:
- return "", fmt.Errorf("tracing endpoint type '%s' is not supported", epType)
}
+
+ return epType, ep, nil
+}
+
+var supportedProviders = map[string]string{
+ "zipkin": "localhost:9411",
+ "datadog": "localhost:8126",
}
const (
- defEP = "localhost:9411"
defEpType = "zipkin"
defServiceName = "coredns"
)
diff --git a/plugin/trace/setup_test.go b/plugin/trace/setup_test.go
index 3c12b76e4..06a1b21bc 100644
--- a/plugin/trace/setup_test.go
+++ b/plugin/trace/setup_test.go
@@ -20,7 +20,8 @@ func TestTraceParse(t *testing.T) {
{`trace localhost:1234`, false, "http://localhost:1234/api/v1/spans", 1, `coredns`, false},
{`trace http://localhost:1234/somewhere/else`, false, "http://localhost:1234/somewhere/else", 1, `coredns`, false},
{`trace zipkin localhost:1234`, false, "http://localhost:1234/api/v1/spans", 1, `coredns`, false},
- {`trace zipkin http://localhost:1234/somewhere/else`, false, "http://localhost:1234/somewhere/else", 1, `coredns`, false},
+ {`trace datadog localhost`, false, "localhost", 1, `coredns`, false},
+ {`trace datadog http://localhost:8127`, false, "http://localhost:8127", 1, `coredns`, false},
{"trace {\n every 100\n}", false, "http://localhost:9411/api/v1/spans", 100, `coredns`, false},
{"trace {\n every 100\n service foobar\nclient_server\n}", false, "http://localhost:9411/api/v1/spans", 100, `foobar`, true},
{"trace {\n every 2\n client_server true\n}", false, "http://localhost:9411/api/v1/spans", 2, `coredns`, true},
diff --git a/plugin/trace/trace.go b/plugin/trace/trace.go
index fa561945e..ffcaa760c 100644
--- a/plugin/trace/trace.go
+++ b/plugin/trace/trace.go
@@ -3,6 +3,7 @@ package trace
import (
"fmt"
+ "strings"
"sync"
"sync/atomic"
@@ -10,6 +11,7 @@ import (
// Plugin the trace package.
_ "github.com/coredns/coredns/plugin/pkg/trace"
+ ddtrace "github.com/DataDog/dd-trace-go/opentracing"
"github.com/miekg/dns"
ot "github.com/opentracing/opentracing-go"
zipkin "github.com/openzipkin/zipkin-go-opentracing"
@@ -40,6 +42,8 @@ func (t *trace) OnStartup() error {
switch t.EndpointType {
case "zipkin":
err = t.setupZipkin()
+ case "datadog":
+ err = t.setupDatadog()
default:
err = fmt.Errorf("unknown endpoint type: %s", t.EndpointType)
}
@@ -60,6 +64,22 @@ func (t *trace) setupZipkin() error {
return err
}
+func (t *trace) setupDatadog() error {
+ config := ddtrace.NewConfiguration()
+ config.ServiceName = t.serviceName
+
+ host := strings.Split(t.Endpoint, ":")
+ config.AgentHostname = host[0]
+
+ if len(host) == 2 {
+ config.AgentPort = host[1]
+ }
+
+ tracer, _, err := ddtrace.NewTracer(config)
+ t.tracer = tracer
+ return err
+}
+
// Name implements the Handler interface.
func (t *trace) Name() string {
return "trace"