mirror of
https://github.com/coredns/coredns.git
synced 2025-11-08 13:06:24 -05:00
plugin/trace: make zipkin and datadog reporters log errors using CoreDNS logger (#5452)
This commit is contained in:
20
plugin/trace/logger.go
Normal file
20
plugin/trace/logger.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package trace
|
||||||
|
|
||||||
|
import (
|
||||||
|
clog "github.com/coredns/coredns/plugin/pkg/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// loggerAdapter is a simple adapter around plugin logger made to implement io.Writer and ddtrace.Logger interface
|
||||||
|
// in order to log errors from span reporters as warnings
|
||||||
|
type loggerAdapter struct {
|
||||||
|
clog.P
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *loggerAdapter) Write(p []byte) (n int, err error) {
|
||||||
|
l.P.Warning(string(p))
|
||||||
|
return len(p), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *loggerAdapter) Log(msg string) {
|
||||||
|
l.P.Warning(msg)
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ package trace
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
stdlog "log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@@ -12,7 +13,7 @@ import (
|
|||||||
"github.com/coredns/coredns/plugin"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/plugin/metadata"
|
"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"
|
clog "github.com/coredns/coredns/plugin/pkg/log"
|
||||||
"github.com/coredns/coredns/plugin/pkg/rcode"
|
"github.com/coredns/coredns/plugin/pkg/rcode"
|
||||||
_ "github.com/coredns/coredns/plugin/pkg/trace" // Plugin the trace package.
|
_ "github.com/coredns/coredns/plugin/pkg/trace" // Plugin the trace package.
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
@@ -35,6 +36,8 @@ const (
|
|||||||
metaTraceIdKey = "trace/traceid"
|
metaTraceIdKey = "trace/traceid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var log = clog.NewWithPlugin("trace")
|
||||||
|
|
||||||
type traceTags struct {
|
type traceTags struct {
|
||||||
Name string
|
Name string
|
||||||
Type string
|
Type string
|
||||||
@@ -90,10 +93,11 @@ func (t *trace) OnStartup() error {
|
|||||||
case "datadog":
|
case "datadog":
|
||||||
tracer := opentracer.New(
|
tracer := opentracer.New(
|
||||||
tracer.WithAgentAddr(t.Endpoint),
|
tracer.WithAgentAddr(t.Endpoint),
|
||||||
tracer.WithDebugMode(log.D.Value()),
|
tracer.WithDebugMode(clog.D.Value()),
|
||||||
tracer.WithGlobalTag(ext.SpanTypeDNS, true),
|
tracer.WithGlobalTag(ext.SpanTypeDNS, true),
|
||||||
tracer.WithServiceName(t.serviceName),
|
tracer.WithServiceName(t.serviceName),
|
||||||
tracer.WithAnalyticsRate(t.datadogAnalyticsRate),
|
tracer.WithAnalyticsRate(t.datadogAnalyticsRate),
|
||||||
|
tracer.WithLogger(&loggerAdapter{log}),
|
||||||
)
|
)
|
||||||
t.tracer = tracer
|
t.tracer = tracer
|
||||||
t.tagSet = tagByProvider["datadog"]
|
t.tagSet = tagByProvider["datadog"]
|
||||||
@@ -105,7 +109,8 @@ func (t *trace) OnStartup() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *trace) setupZipkin() error {
|
func (t *trace) setupZipkin() error {
|
||||||
reporter := zipkinhttp.NewReporter(t.Endpoint)
|
logOpt := zipkinhttp.Logger(stdlog.New(&loggerAdapter{log}, "", 0))
|
||||||
|
reporter := zipkinhttp.NewReporter(t.Endpoint, logOpt)
|
||||||
recorder, err := zipkin.NewEndpoint(t.serviceName, t.serviceEndpoint)
|
recorder, err := zipkin.NewEndpoint(t.serviceName, t.serviceEndpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warningf("build Zipkin endpoint found err: %v", err)
|
log.Warningf("build Zipkin endpoint found err: %v", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user