mirror of
https://github.com/coredns/coredns.git
synced 2025-11-02 02:03:13 -05:00
plugin/trace - Use compatible tag name for datadog (#4408)
Traces are currently working properly with datadog with the exception of having the ability to facet the tags  In order to get valuable graph in dashboard the tag on the metrics need to be faceted by datadog. This PR update the tags with facetable path. While keeping backward compatibility with existing path for zipkin. Graph like:      Signed-off-by: bob <bob.bouteillier@datadoghq.com>
This commit is contained in:
@@ -25,14 +25,34 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
tagName = "coredns.io/name"
|
||||
tagType = "coredns.io/type"
|
||||
tagRcode = "coredns.io/rcode"
|
||||
tagProto = "coredns.io/proto"
|
||||
tagRemote = "coredns.io/remote"
|
||||
defaultTopLevelSpanName = "servedns"
|
||||
)
|
||||
|
||||
type traceTags struct {
|
||||
Name string
|
||||
Type string
|
||||
Rcode string
|
||||
Proto string
|
||||
Remote string
|
||||
}
|
||||
|
||||
var tagByProvider = map[string]traceTags{
|
||||
"default": {
|
||||
Name: "coredns.io/name",
|
||||
Type: "coredns.io/type",
|
||||
Rcode: "coredns.io/rcode",
|
||||
Proto: "coredns.io/proto",
|
||||
Remote: "coredns.io/remote",
|
||||
},
|
||||
"datadog": {
|
||||
Name: "coredns.io@name",
|
||||
Type: "coredns.io@type",
|
||||
Rcode: "coredns.io@rcode",
|
||||
Proto: "coredns.io@proto",
|
||||
Remote: "coredns.io@remote",
|
||||
},
|
||||
}
|
||||
|
||||
type trace struct {
|
||||
count uint64 // as per Go spec, needs to be first element in a struct
|
||||
|
||||
@@ -46,6 +66,7 @@ type trace struct {
|
||||
every uint64
|
||||
datadogAnalyticsRate float64
|
||||
Once sync.Once
|
||||
tagSet traceTags
|
||||
}
|
||||
|
||||
func (t *trace) Tracer() ot.Tracer {
|
||||
@@ -68,6 +89,7 @@ func (t *trace) OnStartup() error {
|
||||
tracer.WithAnalyticsRate(t.datadogAnalyticsRate),
|
||||
)
|
||||
t.tracer = tracer
|
||||
t.tagSet = tagByProvider["datadog"]
|
||||
default:
|
||||
err = fmt.Errorf("unknown endpoint type: %s", t.EndpointType)
|
||||
}
|
||||
@@ -90,6 +112,8 @@ func (t *trace) setupZipkin() error {
|
||||
return err
|
||||
}
|
||||
t.tracer = zipkinot.Wrap(tracer)
|
||||
|
||||
t.tagSet = tagByProvider["default"]
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -119,11 +143,11 @@ func (t *trace) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
||||
ctx = ot.ContextWithSpan(ctx, span)
|
||||
status, err := plugin.NextOrFailure(t.Name(), t.Next, ctx, rw, r)
|
||||
|
||||
span.SetTag(tagName, req.Name())
|
||||
span.SetTag(tagType, req.Type())
|
||||
span.SetTag(tagProto, req.Proto())
|
||||
span.SetTag(tagRemote, req.IP())
|
||||
span.SetTag(tagRcode, rcode.ToString(rw.Rcode))
|
||||
span.SetTag(t.tagSet.Name, req.Name())
|
||||
span.SetTag(t.tagSet.Type, req.Type())
|
||||
span.SetTag(t.tagSet.Proto, req.Proto())
|
||||
span.SetTag(t.tagSet.Remote, req.IP())
|
||||
span.SetTag(t.tagSet.Rcode, rcode.ToString(rw.Rcode))
|
||||
|
||||
return status, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user