Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for some changes in OpenTracing #306

Merged
merged 1 commit into from
Jul 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions tracing/opentracing/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tracing/opentracing/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions tracing/opentracing/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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)

Expand Down