Commit 936b483a authored by Ondřej Benkovský's avatar Ondřej Benkovský Committed by GitHub

publish trace id as metadata from trace plugin (#4749)

Signed-off-by: default avatarOndrej Benkovsky <ondrej.benkovsky@wandera.com>
parent e62600a1
...@@ -93,6 +93,13 @@ trace tracinghost:9411 { ...@@ -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 Also
See the *debug* plugin for more information about debug logging. See the *debug* plugin for more information about debug logging.
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"sync/atomic" "sync/atomic"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metadata"
"github.com/coredns/coredns/plugin/pkg/dnstest" "github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/pkg/log" "github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/rcode" "github.com/coredns/coredns/plugin/pkg/rcode"
...@@ -21,6 +22,7 @@ import ( ...@@ -21,6 +22,7 @@ import (
zipkinot "github.com/openzipkin-contrib/zipkin-go-opentracing" zipkinot "github.com/openzipkin-contrib/zipkin-go-opentracing"
"github.com/openzipkin/zipkin-go" "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http" 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/ext"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentracer" "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentracer"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
...@@ -28,6 +30,7 @@ import ( ...@@ -28,6 +30,7 @@ import (
const ( const (
defaultTopLevelSpanName = "servedns" defaultTopLevelSpanName = "servedns"
metaTraceIdKey = "trace/traceid"
) )
type traceTags struct { type traceTags struct {
...@@ -141,6 +144,13 @@ func (t *trace) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) ...@@ -141,6 +144,13 @@ func (t *trace) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
span = t.Tracer().StartSpan(defaultTopLevelSpanName) span = t.Tracer().StartSpan(defaultTopLevelSpanName)
defer span.Finish() 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) rw := dnstest.NewRecorder(w)
ctx = ot.ContextWithSpan(ctx, span) ctx = ot.ContextWithSpan(ctx, span)
status, err := plugin.NextOrFailure(t.Name(), t.Next, ctx, rw, r) status, err := plugin.NextOrFailure(t.Name(), t.Next, ctx, rw, r)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment