Add tracing option (#487)
Adds a middleware to enable tracing with OpenTracing/OpenZipkin. Enabling tracing will have a large impact on performance so it is not advisable in production.
This commit is contained in:
parent
c62bd639ff
commit
bc301be5ee
8 changed files with 261 additions and 0 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
ot "github.com/opentracing/opentracing-go"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -70,6 +71,11 @@ func Error(name string, err error) error { return fmt.Errorf("%s/%s: %s", "middl
|
|||
// and a nil error.
|
||||
func NextOrFailure(name string, next Handler, ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
if next != nil {
|
||||
if span := ot.SpanFromContext(ctx); span != nil {
|
||||
child := span.Tracer().StartSpan(next.Name(), ot.ChildOf(span.Context()))
|
||||
defer child.Finish()
|
||||
ctx = ot.ContextWithSpan(ctx, child)
|
||||
}
|
||||
return next.ServeDNS(ctx, w, r)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue