diff --git a/tracing/opentracing/endpoint_test.go b/tracing/opentracing/endpoint_test.go index 02da72e27..d89136c93 100644 --- a/tracing/opentracing/endpoint_test.go +++ b/tracing/opentracing/endpoint_test.go @@ -18,24 +18,23 @@ func TestTraceServer(t *testing.T) { contextSpan := tracer.StartSpan("").(*mocktracer.MockSpan) ctx := opentracing.ContextWithSpan(context.Background(), contextSpan) - var innerEndpoint endpoint.Endpoint - innerEndpoint = func(context.Context, interface{}) (interface{}, error) { - return struct{}{}, nil - } - tracedEndpoint := kitot.TraceServer(tracer, "testOp")(innerEndpoint) + tracedEndpoint := kitot.TraceServer(tracer, "testOp")(endpoint.Nop) if _, err := tracedEndpoint(ctx, struct{}{}); err != nil { t.Fatal(err) } - if want, have := 1, len(tracer.FinishedSpans); want != have { + + finishedSpans := tracer.GetFinishedSpans() + if want, have := 1, len(finishedSpans); want != have { t.Fatalf("Want %v span(s), found %v", want, have) } - endpointSpan := tracer.FinishedSpans[0] // Test that the op name is updated + endpointSpan := finishedSpans[0] if want, have := "testOp", endpointSpan.OperationName; want != have { t.Fatalf("Want %q, have %q", want, have) } - // ... and that the ID is unmodified. + + // ...and that the ID is unmodified. if want, have := contextSpan.SpanID, endpointSpan.SpanID; want != have { t.Errorf("Want SpanID %q, have %q", want, have) } @@ -44,21 +43,19 @@ func TestTraceServer(t *testing.T) { func TestTraceServerNoContextSpan(t *testing.T) { tracer := mocktracer.New() - var innerEndpoint endpoint.Endpoint - innerEndpoint = func(context.Context, interface{}) (interface{}, error) { - return struct{}{}, nil - } - tracedEndpoint := kitot.TraceServer(tracer, "testOp")(innerEndpoint) - // Empty/background context: + // Empty/background context. + tracedEndpoint := kitot.TraceServer(tracer, "testOp")(endpoint.Nop) if _, err := tracedEndpoint(context.Background(), struct{}{}); err != nil { t.Fatal(err) } - // tracedEndpoint created a new Span: - if want, have := 1, len(tracer.FinishedSpans); want != have { + + // tracedEndpoint created a new Span. + finishedSpans := tracer.GetFinishedSpans() + if want, have := 1, len(finishedSpans); want != have { t.Fatalf("Want %v span(s), found %v", want, have) } - endpointSpan := tracer.FinishedSpans[0] + endpointSpan := finishedSpans[0] if want, have := "testOp", endpointSpan.OperationName; want != have { t.Fatalf("Want %q, have %q", want, have) } @@ -72,23 +69,22 @@ func TestTraceClient(t *testing.T) { defer parentSpan.Finish() ctx := opentracing.ContextWithSpan(context.Background(), parentSpan) - var innerEndpoint endpoint.Endpoint - innerEndpoint = func(context.Context, interface{}) (interface{}, error) { - return struct{}{}, nil - } - tracedEndpoint := kitot.TraceClient(tracer, "testOp")(innerEndpoint) + tracedEndpoint := kitot.TraceClient(tracer, "testOp")(endpoint.Nop) if _, err := tracedEndpoint(ctx, struct{}{}); err != nil { t.Fatal(err) } - // tracedEndpoint created a new Span: - if want, have := 1, len(tracer.FinishedSpans); want != have { + + // tracedEndpoint created a new Span. + finishedSpans := tracer.GetFinishedSpans() + if want, have := 1, len(finishedSpans); want != have { t.Fatalf("Want %v span(s), found %v", want, have) } - endpointSpan := tracer.FinishedSpans[0] + endpointSpan := finishedSpans[0] if want, have := "testOp", endpointSpan.OperationName; want != have { t.Fatalf("Want %q, have %q", want, have) } + // ... and that the parent ID is set appropriately. if want, have := parentSpan.SpanID, endpointSpan.ParentID; want != have { t.Errorf("Want ParentID %q, have %q", want, have) diff --git a/tracing/opentracing/grpc_test.go b/tracing/opentracing/grpc_test.go index d9de49b05..2db9db373 100644 --- a/tracing/opentracing/grpc_test.go +++ b/tracing/opentracing/grpc_test.go @@ -9,7 +9,6 @@ import ( "google.golang.org/grpc/metadata" kitot "github.com/go-kit/kit/tracing/opentracing" - "github.com/go-kit/kit/transport/grpc" ) func TestTraceGRPCRequestRoundtrip(t *testing.T) { @@ -21,7 +20,7 @@ func TestTraceGRPCRequestRoundtrip(t *testing.T) { beforeSpan.SetBaggageItem("baggage", "check") beforeCtx := opentracing.ContextWithSpan(context.Background(), beforeSpan) - var toGRPCFunc grpc.RequestFunc = kitot.ToGRPCRequest(tracer, nil) + toGRPCFunc := kitot.ToGRPCRequest(tracer, nil) md := metadata.Pairs() // Call the RequestFunc. afterCtx := toGRPCFunc(beforeCtx, &md) @@ -33,12 +32,13 @@ func TestTraceGRPCRequestRoundtrip(t *testing.T) { } // No spans should have finished yet. - if want, have := 0, len(tracer.FinishedSpans); want != have { + finishedSpans := tracer.GetFinishedSpans() + if want, have := 0, len(finishedSpans); want != have { t.Errorf("Want %v span(s), found %v", want, have) } // Use FromGRPCRequest to verify that we can join with the trace given MD. - var fromGRPCFunc grpc.RequestFunc = kitot.FromGRPCRequest(tracer, "joined", nil) + fromGRPCFunc := kitot.FromGRPCRequest(tracer, "joined", nil) joinCtx := fromGRPCFunc(afterCtx, &md) joinedSpan := opentracing.SpanFromContext(joinCtx).(*mocktracer.MockSpan) diff --git a/tracing/opentracing/http_test.go b/tracing/opentracing/http_test.go index d49acbfd6..a6f22bf78 100644 --- a/tracing/opentracing/http_test.go +++ b/tracing/opentracing/http_test.go @@ -9,7 +9,6 @@ import ( "golang.org/x/net/context" kitot "github.com/go-kit/kit/tracing/opentracing" - kithttp "github.com/go-kit/kit/transport/http" ) func TestTraceHTTPRequestRoundtrip(t *testing.T) { @@ -21,7 +20,7 @@ func TestTraceHTTPRequestRoundtrip(t *testing.T) { beforeSpan.SetBaggageItem("baggage", "check") beforeCtx := opentracing.ContextWithSpan(context.Background(), beforeSpan) - var toHTTPFunc kithttp.RequestFunc = kitot.ToHTTPRequest(tracer, nil) + toHTTPFunc := kitot.ToHTTPRequest(tracer, nil) req, _ := http.NewRequest("GET", "http://test.biz/url", nil) // Call the RequestFunc. afterCtx := toHTTPFunc(beforeCtx, req) @@ -33,12 +32,13 @@ func TestTraceHTTPRequestRoundtrip(t *testing.T) { } // No spans should have finished yet. - if want, have := 0, len(tracer.FinishedSpans); want != have { + finishedSpans := tracer.GetFinishedSpans() + if want, have := 0, len(finishedSpans); want != have { t.Errorf("Want %v span(s), found %v", want, have) } // Use FromHTTPRequest to verify that we can join with the trace given a req. - var fromHTTPFunc kithttp.RequestFunc = kitot.FromHTTPRequest(tracer, "joined", nil) + fromHTTPFunc := kitot.FromHTTPRequest(tracer, "joined", nil) joinCtx := fromHTTPFunc(afterCtx, req) joinedSpan := opentracing.SpanFromContext(joinCtx).(*mocktracer.MockSpan)