propagation tests fixed pending change in mocktracer
Bas van Beek
7 years ago
32 | 32 | if want, have := "testOp", endpointSpan.OperationName; want != have { |
33 | 33 | t.Fatalf("Want %q, have %q", want, have) |
34 | 34 | } |
35 | ||
35 | contextContext := contextSpan.Context().(*mocktracer.MockSpanContext) | |
36 | endpointContext := endpointSpan.Context().(*mocktracer.MockSpanContext) | |
36 | 37 | // ...and that the ID is unmodified. |
37 | if want, have := contextSpan.SpanID, endpointSpan.SpanID; want != have { | |
38 | if want, have := contextContext.SpanID, endpointContext.SpanID; want != have { | |
38 | 39 | t.Errorf("Want SpanID %q, have %q", want, have) |
39 | 40 | } |
40 | 41 | } |
84 | 85 | t.Fatalf("Want %q, have %q", want, have) |
85 | 86 | } |
86 | 87 | |
88 | parentContext := parentSpan.Context().(*mocktracer.MockSpanContext) | |
89 | endpointContext := parentSpan.Context().(*mocktracer.MockSpanContext) | |
90 | ||
87 | 91 | // ... and that the parent ID is set appropriately. |
88 | if want, have := parentSpan.SpanID, endpointSpan.ParentID; want != have { | |
92 | if want, have := parentContext.SpanID, endpointContext.SpanID; want != have { | |
89 | 93 | t.Errorf("Want ParentID %q, have %q", want, have) |
90 | 94 | } |
91 | 95 | } |
7 | 7 | "golang.org/x/net/context" |
8 | 8 | "google.golang.org/grpc/metadata" |
9 | 9 | |
10 | "github.com/go-kit/kit/log" | |
10 | 11 | kitot "github.com/go-kit/kit/tracing/opentracing" |
11 | 12 | ) |
12 | 13 | |
13 | 14 | func TestTraceGRPCRequestRoundtrip(t *testing.T) { |
15 | logger := log.NewNopLogger() | |
14 | 16 | tracer := mocktracer.New() |
15 | 17 | |
16 | 18 | // Initialize the ctx with a Span to inject. |
17 | 19 | beforeSpan := tracer.StartSpan("to_inject").(*mocktracer.MockSpan) |
18 | 20 | defer beforeSpan.Finish() |
19 | beforeSpan.SetBaggageItem("baggage", "check") | |
21 | beforeSpan.Context().SetBaggageItem("baggage", "check") | |
20 | 22 | beforeCtx := opentracing.ContextWithSpan(context.Background(), beforeSpan) |
21 | 23 | |
22 | toGRPCFunc := kitot.ToGRPCRequest(tracer, nil) | |
24 | toGRPCFunc := kitot.ToGRPCRequest(tracer, logger) | |
23 | 25 | md := metadata.Pairs() |
24 | 26 | // Call the RequestFunc. |
25 | 27 | afterCtx := toGRPCFunc(beforeCtx, &md) |
37 | 39 | } |
38 | 40 | |
39 | 41 | // Use FromGRPCRequest to verify that we can join with the trace given MD. |
40 | fromGRPCFunc := kitot.FromGRPCRequest(tracer, "joined", nil) | |
42 | fromGRPCFunc := kitot.FromGRPCRequest(tracer, "joined", logger) | |
41 | 43 | joinCtx := fromGRPCFunc(afterCtx, &md) |
42 | 44 | joinedSpan := opentracing.SpanFromContext(joinCtx).(*mocktracer.MockSpan) |
43 | 45 | |
44 | if joinedSpan.SpanID == beforeSpan.SpanID { | |
45 | t.Error("SpanID should have changed", joinedSpan.SpanID, beforeSpan.SpanID) | |
46 | joinedContext := joinedSpan.Context().(*mocktracer.MockSpanContext) | |
47 | beforeContext := beforeSpan.Context().(*mocktracer.MockSpanContext) | |
48 | ||
49 | if joinedContext.SpanID == beforeContext.SpanID { | |
50 | t.Error("SpanID should have changed", joinedContext.SpanID, beforeContext.SpanID) | |
46 | 51 | } |
47 | 52 | |
48 | 53 | // Check that the parent/child relationship is as expected for the joined span. |
49 | if want, have := beforeSpan.SpanID, joinedSpan.ParentID; want != have { | |
54 | if want, have := beforeContext.SpanID, joinedSpan.ParentID; want != have { | |
50 | 55 | t.Errorf("Want ParentID %q, have %q", want, have) |
51 | 56 | } |
52 | 57 | if want, have := "joined", joinedSpan.OperationName; want != have { |
53 | 58 | t.Errorf("Want %q, have %q", want, have) |
54 | 59 | } |
55 | if want, have := "check", joinedSpan.BaggageItem("baggage"); want != have { | |
60 | if want, have := "check", joinedSpan.Context().BaggageItem("baggage"); want != have { | |
56 | 61 | t.Errorf("Want %q, have %q", want, have) |
57 | 62 | } |
58 | 63 | } |
7 | 7 | "github.com/opentracing/opentracing-go/mocktracer" |
8 | 8 | "golang.org/x/net/context" |
9 | 9 | |
10 | "github.com/go-kit/kit/log" | |
10 | 11 | kitot "github.com/go-kit/kit/tracing/opentracing" |
11 | 12 | ) |
12 | 13 | |
13 | 14 | func TestTraceHTTPRequestRoundtrip(t *testing.T) { |
15 | logger := log.NewNopLogger() | |
14 | 16 | tracer := mocktracer.New() |
15 | 17 | |
16 | 18 | // Initialize the ctx with a Span to inject. |
17 | 19 | beforeSpan := tracer.StartSpan("to_inject").(*mocktracer.MockSpan) |
18 | 20 | defer beforeSpan.Finish() |
19 | beforeSpan.SetBaggageItem("baggage", "check") | |
21 | beforeSpan.Context().SetBaggageItem("baggage", "check") | |
20 | 22 | beforeCtx := opentracing.ContextWithSpan(context.Background(), beforeSpan) |
21 | 23 | |
22 | toHTTPFunc := kitot.ToHTTPRequest(tracer, nil) | |
24 | toHTTPFunc := kitot.ToHTTPRequest(tracer, logger) | |
23 | 25 | req, _ := http.NewRequest("GET", "http://test.biz/url", nil) |
24 | 26 | // Call the RequestFunc. |
25 | 27 | afterCtx := toHTTPFunc(beforeCtx, req) |
37 | 39 | } |
38 | 40 | |
39 | 41 | // Use FromHTTPRequest to verify that we can join with the trace given a req. |
40 | fromHTTPFunc := kitot.FromHTTPRequest(tracer, "joined", nil) | |
42 | fromHTTPFunc := kitot.FromHTTPRequest(tracer, "joined", logger) | |
41 | 43 | joinCtx := fromHTTPFunc(afterCtx, req) |
42 | 44 | joinedSpan := opentracing.SpanFromContext(joinCtx).(*mocktracer.MockSpan) |
43 | 45 | |
44 | if joinedSpan.SpanID == beforeSpan.SpanID { | |
45 | t.Error("SpanID should have changed", joinedSpan.SpanID, beforeSpan.SpanID) | |
46 | joinedContext := joinedSpan.Context().(*mocktracer.MockSpanContext) | |
47 | beforeContext := beforeSpan.Context().(*mocktracer.MockSpanContext) | |
48 | ||
49 | if joinedContext.SpanID == beforeContext.SpanID { | |
50 | t.Error("SpanID should have changed", joinedContext.SpanID, beforeContext.SpanID) | |
46 | 51 | } |
47 | 52 | |
48 | 53 | // Check that the parent/child relationship is as expected for the joined span. |
49 | if want, have := beforeSpan.SpanID, joinedSpan.ParentID; want != have { | |
54 | if want, have := beforeContext.SpanID, joinedSpan.ParentID; want != have { | |
50 | 55 | t.Errorf("Want ParentID %q, have %q", want, have) |
51 | 56 | } |
52 | 57 | if want, have := "joined", joinedSpan.OperationName; want != have { |
53 | 58 | t.Errorf("Want %q, have %q", want, have) |
54 | 59 | } |
55 | if want, have := "check", joinedSpan.BaggageItem("baggage"); want != have { | |
60 | if want, have := "check", joinedSpan.Context().BaggageItem("baggage"); want != have { | |
56 | 61 | t.Errorf("Want %q, have %q", want, have) |
57 | 62 | } |
58 | 63 | } |