diff --git a/tracing/opentracing/endpoint_test.go b/tracing/opentracing/endpoint_test.go index d89136c..f7727b4 100644 --- a/tracing/opentracing/endpoint_test.go +++ b/tracing/opentracing/endpoint_test.go @@ -33,9 +33,10 @@ if want, have := "testOp", endpointSpan.OperationName; want != have { t.Fatalf("Want %q, have %q", want, have) } - + contextContext := contextSpan.Context().(*mocktracer.MockSpanContext) + endpointContext := endpointSpan.Context().(*mocktracer.MockSpanContext) // ...and that the ID is unmodified. - if want, have := contextSpan.SpanID, endpointSpan.SpanID; want != have { + if want, have := contextContext.SpanID, endpointContext.SpanID; want != have { t.Errorf("Want SpanID %q, have %q", want, have) } } @@ -85,8 +86,11 @@ t.Fatalf("Want %q, have %q", want, have) } + parentContext := parentSpan.Context().(*mocktracer.MockSpanContext) + endpointContext := parentSpan.Context().(*mocktracer.MockSpanContext) + // ... and that the parent ID is set appropriately. - if want, have := parentSpan.SpanID, endpointSpan.ParentID; want != have { + if want, have := parentContext.SpanID, endpointContext.SpanID; 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 2db9db3..c23b63b 100644 --- a/tracing/opentracing/grpc_test.go +++ b/tracing/opentracing/grpc_test.go @@ -8,19 +8,21 @@ "golang.org/x/net/context" "google.golang.org/grpc/metadata" + "github.com/go-kit/kit/log" kitot "github.com/go-kit/kit/tracing/opentracing" ) func TestTraceGRPCRequestRoundtrip(t *testing.T) { + logger := log.NewNopLogger() tracer := mocktracer.New() // Initialize the ctx with a Span to inject. beforeSpan := tracer.StartSpan("to_inject").(*mocktracer.MockSpan) defer beforeSpan.Finish() - beforeSpan.SetBaggageItem("baggage", "check") + beforeSpan.Context().SetBaggageItem("baggage", "check") beforeCtx := opentracing.ContextWithSpan(context.Background(), beforeSpan) - toGRPCFunc := kitot.ToGRPCRequest(tracer, nil) + toGRPCFunc := kitot.ToGRPCRequest(tracer, logger) md := metadata.Pairs() // Call the RequestFunc. afterCtx := toGRPCFunc(beforeCtx, &md) @@ -38,22 +40,25 @@ } // Use FromGRPCRequest to verify that we can join with the trace given MD. - fromGRPCFunc := kitot.FromGRPCRequest(tracer, "joined", nil) + fromGRPCFunc := kitot.FromGRPCRequest(tracer, "joined", logger) joinCtx := fromGRPCFunc(afterCtx, &md) joinedSpan := opentracing.SpanFromContext(joinCtx).(*mocktracer.MockSpan) - if joinedSpan.SpanID == beforeSpan.SpanID { - t.Error("SpanID should have changed", joinedSpan.SpanID, beforeSpan.SpanID) + joinedContext := joinedSpan.Context().(*mocktracer.MockSpanContext) + beforeContext := beforeSpan.Context().(*mocktracer.MockSpanContext) + + if joinedContext.SpanID == beforeContext.SpanID { + t.Error("SpanID should have changed", joinedContext.SpanID, beforeContext.SpanID) } // Check that the parent/child relationship is as expected for the joined span. - if want, have := beforeSpan.SpanID, joinedSpan.ParentID; want != have { + if want, have := beforeContext.SpanID, joinedSpan.ParentID; want != have { t.Errorf("Want ParentID %q, have %q", want, have) } if want, have := "joined", joinedSpan.OperationName; want != have { t.Errorf("Want %q, have %q", want, have) } - if want, have := "check", joinedSpan.BaggageItem("baggage"); want != have { + if want, have := "check", joinedSpan.Context().BaggageItem("baggage"); want != have { t.Errorf("Want %q, have %q", want, have) } } diff --git a/tracing/opentracing/http_test.go b/tracing/opentracing/http_test.go index a6f22bf..5035db8 100644 --- a/tracing/opentracing/http_test.go +++ b/tracing/opentracing/http_test.go @@ -8,19 +8,21 @@ "github.com/opentracing/opentracing-go/mocktracer" "golang.org/x/net/context" + "github.com/go-kit/kit/log" kitot "github.com/go-kit/kit/tracing/opentracing" ) func TestTraceHTTPRequestRoundtrip(t *testing.T) { + logger := log.NewNopLogger() tracer := mocktracer.New() // Initialize the ctx with a Span to inject. beforeSpan := tracer.StartSpan("to_inject").(*mocktracer.MockSpan) defer beforeSpan.Finish() - beforeSpan.SetBaggageItem("baggage", "check") + beforeSpan.Context().SetBaggageItem("baggage", "check") beforeCtx := opentracing.ContextWithSpan(context.Background(), beforeSpan) - toHTTPFunc := kitot.ToHTTPRequest(tracer, nil) + toHTTPFunc := kitot.ToHTTPRequest(tracer, logger) req, _ := http.NewRequest("GET", "http://test.biz/url", nil) // Call the RequestFunc. afterCtx := toHTTPFunc(beforeCtx, req) @@ -38,22 +40,25 @@ } // Use FromHTTPRequest to verify that we can join with the trace given a req. - fromHTTPFunc := kitot.FromHTTPRequest(tracer, "joined", nil) + fromHTTPFunc := kitot.FromHTTPRequest(tracer, "joined", logger) joinCtx := fromHTTPFunc(afterCtx, req) joinedSpan := opentracing.SpanFromContext(joinCtx).(*mocktracer.MockSpan) - if joinedSpan.SpanID == beforeSpan.SpanID { - t.Error("SpanID should have changed", joinedSpan.SpanID, beforeSpan.SpanID) + joinedContext := joinedSpan.Context().(*mocktracer.MockSpanContext) + beforeContext := beforeSpan.Context().(*mocktracer.MockSpanContext) + + if joinedContext.SpanID == beforeContext.SpanID { + t.Error("SpanID should have changed", joinedContext.SpanID, beforeContext.SpanID) } // Check that the parent/child relationship is as expected for the joined span. - if want, have := beforeSpan.SpanID, joinedSpan.ParentID; want != have { + if want, have := beforeContext.SpanID, joinedSpan.ParentID; want != have { t.Errorf("Want ParentID %q, have %q", want, have) } if want, have := "joined", joinedSpan.OperationName; want != have { t.Errorf("Want %q, have %q", want, have) } - if want, have := "check", joinedSpan.BaggageItem("baggage"); want != have { + if want, have := "check", joinedSpan.Context().BaggageItem("baggage"); want != have { t.Errorf("Want %q, have %q", want, have) } }