aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugin/trace/README.md7
-rw-r--r--plugin/trace/trace.go10
2 files changed, 17 insertions, 0 deletions
diff --git a/plugin/trace/README.md b/plugin/trace/README.md
index b6a59fd6c..d0b955409 100644
--- a/plugin/trace/README.md
+++ b/plugin/trace/README.md
@@ -93,6 +93,13 @@ trace tracinghost:9411 {
}
~~~
+## Metadata
+
+The trace plugin will publish the following metadata, if the *metadata*
+plugin is also enabled:
+
+* `trace/traceid`: identifier of (zipkin/datadog) trace of processed request
+
## See Also
See the *debug* plugin for more information about debug logging.
diff --git a/plugin/trace/trace.go b/plugin/trace/trace.go
index 1b74dcbc3..d476d3b3f 100644
--- a/plugin/trace/trace.go
+++ b/plugin/trace/trace.go
@@ -8,6 +8,7 @@ import (
"sync/atomic"
"github.com/coredns/coredns/plugin"
+ "github.com/coredns/coredns/plugin/metadata"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/rcode"
@@ -21,6 +22,7 @@ import (
zipkinot "github.com/openzipkin-contrib/zipkin-go-opentracing"
"github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
+ "gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentracer"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
@@ -28,6 +30,7 @@ import (
const (
defaultTopLevelSpanName = "servedns"
+ metaTraceIdKey = "trace/traceid"
)
type traceTags struct {
@@ -141,6 +144,13 @@ func (t *trace) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
span = t.Tracer().StartSpan(defaultTopLevelSpanName)
defer span.Finish()
+ switch spanCtx := span.Context().(type) {
+ case zipkinot.SpanContext:
+ metadata.SetValueFunc(ctx, metaTraceIdKey, func() string{ return spanCtx.TraceID.String() })
+ case ddtrace.SpanContext:
+ metadata.SetValueFunc(ctx, metaTraceIdKey, func() string{ return fmt.Sprint(spanCtx.TraceID()) })
+ }
+
rw := dnstest.NewRecorder(w)
ctx = ot.ContextWithSpan(ctx, span)
status, err := plugin.NextOrFailure(t.Name(), t.Next, ctx, rw, r)