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

Add ctx in SpanDecorator option #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions go/otgrpc/client.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package otgrpc

import (
"github.com/opentracing/opentracing-go"
"io"
"runtime"
"sync/atomic"

opentracing "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
"github.com/opentracing/opentracing-go/log"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"io"
"runtime"
"sync/atomic"
)

// OpenTracingClientInterceptor returns a grpc.UnaryClientInterceptor suitable
Expand Down Expand Up @@ -67,7 +68,7 @@ func OpenTracingClientInterceptor(tracer opentracing.Tracer, optFuncs ...Option)
clientSpan.LogFields(log.String("event", "error"), log.String("message", err.Error()))
}
if otgrpcOpts.decorator != nil {
otgrpcOpts.decorator(clientSpan, method, req, resp, err)
otgrpcOpts.decorator(ctx, clientSpan, method, req, resp, err)
}
return err
}
Expand Down Expand Up @@ -147,7 +148,7 @@ func newOpenTracingClientStream(cs grpc.ClientStream, method string, desc *grpc.
SetSpanTags(clientSpan, err, true)
}
if otgrpcOpts.decorator != nil {
otgrpcOpts.decorator(clientSpan, method, nil, nil, err)
otgrpcOpts.decorator(context.Background(), clientSpan, method, nil, nil, err)
Copy link

@fho fho Sep 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass ctx also to the streaming interceptors:

Suggested change
otgrpcOpts.decorator(context.Background(), clientSpan, method, nil, nil, err)
otgrpcOpts.decorator(cs.Context(), clientSpan, method, nil, nil, err)

}
}
go func() {
Expand Down
6 changes: 5 additions & 1 deletion go/otgrpc/options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package otgrpc

import "github.com/opentracing/opentracing-go"
import (
opentracing "github.com/opentracing/opentracing-go"
"golang.org/x/net/context"
)

// Option instances may be used in OpenTracing(Server|Client)Interceptor
// initialization.
Expand Down Expand Up @@ -39,6 +42,7 @@ func IncludingSpans(inclusionFunc SpanInclusionFunc) Option {
// arbitrary tags/logs/etc to the opentracing.Span associated with client
// and/or server RPCs.
type SpanDecoratorFunc func(
ctx context.Context,
span opentracing.Span,
method string,
req, resp interface{},
Expand Down
6 changes: 3 additions & 3 deletions go/otgrpc/server.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package otgrpc

import (
"github.com/opentracing/opentracing-go"
opentracing "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
"github.com/opentracing/opentracing-go/log"
"golang.org/x/net/context"
Expand Down Expand Up @@ -64,7 +64,7 @@ func OpenTracingServerInterceptor(tracer opentracing.Tracer, optFuncs ...Option)
serverSpan.LogFields(log.String("event", "error"), log.String("message", err.Error()))
}
if otgrpcOpts.decorator != nil {
otgrpcOpts.decorator(serverSpan, info.FullMethod, req, resp, err)
otgrpcOpts.decorator(ctx, serverSpan, info.FullMethod, req, resp, err)
}
return resp, err
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func OpenTracingStreamServerInterceptor(tracer opentracing.Tracer, optFuncs ...O
serverSpan.LogFields(log.String("event", "error"), log.String("message", err.Error()))
}
if otgrpcOpts.decorator != nil {
otgrpcOpts.decorator(serverSpan, info.FullMethod, nil, nil, err)
otgrpcOpts.decorator(context.Background(), serverSpan, info.FullMethod, nil, nil, err)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
otgrpcOpts.decorator(context.Background(), serverSpan, info.FullMethod, nil, nil, err)
otgrpcOpts.decorator(ss.Context(), serverSpan, info.FullMethod, nil, nil, err)

}
return err
}
Expand Down