Skip to content

Commit

Permalink
net: add custom open tracing tag example (#2103)
Browse files Browse the repository at this point in the history
Updates #2102

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
  • Loading branch information
AlexanderYastrebov authored Oct 14, 2022
1 parent 608ac46 commit ae00af9
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions net/httpclient_example_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package net_test

import (
"fmt"
"log"
stdlibnet "net"
"net/http"
"net/http/httptest"
"time"

"github.com/lightstep/lightstep-tracer-go"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/mocktracer"
"github.com/zalando/skipper/net"
"github.com/zalando/skipper/secrets"
)
Expand Down Expand Up @@ -194,6 +197,35 @@ func ExampleClient_staticSecret() {
}
}

type customTracer struct {
opentracing.Tracer
}

func (t *customTracer) StartSpan(operationName string, opts ...opentracing.StartSpanOption) opentracing.Span {
span := t.Tracer.StartSpan(operationName, opts...)
span.SetTag("customtag", "test")
return span
}

func ExampleClient_customTracer() {
mockTracer := mocktracer.New()
cli := net.NewClient(net.Options{
Tracer: &customTracer{mockTracer},
OpentracingSpanName: "clientSpan",
})
defer cli.Close()

srv := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
defer srv.Close()

cli.Get("http://" + srv.Listener.Addr().String() + "/")

fmt.Printf("customtag: %s", mockTracer.FinishedSpans()[0].Tags()["customtag"])

// Output:
// customtag: test
}

type testSecretsReader struct {
h map[string][]byte
}
Expand Down

0 comments on commit ae00af9

Please sign in to comment.