do not log "SpanContext not found in Extract carrier" as this is expected behavior if client is not instrumented
Bas van Beek
7 years ago
14 | 14 |
// ToGRPCRequest returns a grpc RequestFunc that injects an OpenTracing Span
|
15 | 15 |
// found in `ctx` into the grpc Metadata. If no such Span can be found, the
|
16 | 16 |
// RequestFunc is a noop.
|
17 | |
//
|
18 | |
// The logger is used to report errors and may be nil.
|
19 | 17 |
func ToGRPCRequest(tracer opentracing.Tracer, logger log.Logger) func(ctx context.Context, md *metadata.MD) context.Context {
|
20 | 18 |
return func(ctx context.Context, md *metadata.MD) context.Context {
|
21 | 19 |
if span := opentracing.SpanFromContext(ctx); span != nil {
|
|
33 | 31 |
// `operationName` accordingly. If no trace could be found in `req`, the Span
|
34 | 32 |
// will be a trace root. The Span is incorporated in the returned Context and
|
35 | 33 |
// can be retrieved with opentracing.SpanFromContext(ctx).
|
36 | |
//
|
37 | |
// The logger is used to report errors and may be nil.
|
38 | 34 |
func FromGRPCRequest(tracer opentracing.Tracer, operationName string, logger log.Logger) func(ctx context.Context, md *metadata.MD) context.Context {
|
39 | 35 |
return func(ctx context.Context, md *metadata.MD) context.Context {
|
40 | 36 |
var span opentracing.Span
|
41 | 37 |
wireContext, err := tracer.Extract(opentracing.TextMap, metadataReaderWriter{md})
|
42 | |
if err != nil {
|
|
38 |
if err != nil && err != opentracing.ErrSpanContextNotFound {
|
43 | 39 |
logger.Log("err", err)
|
44 | 40 |
}
|
45 | 41 |
span = tracer.StartSpan(operationName, ext.RPCServerOption(wireContext))
|
15 | 15 |
// ToHTTPRequest returns an http RequestFunc that injects an OpenTracing Span
|
16 | 16 |
// found in `ctx` into the http headers. If no such Span can be found, the
|
17 | 17 |
// RequestFunc is a noop.
|
18 | |
//
|
19 | |
// The logger is used to report errors and may be nil.
|
20 | 18 |
func ToHTTPRequest(tracer opentracing.Tracer, logger log.Logger) kithttp.RequestFunc {
|
21 | 19 |
return func(ctx context.Context, req *http.Request) context.Context {
|
22 | 20 |
// Try to find a Span in the Context.
|
|
51 | 49 |
// `operationName` accordingly. If no trace could be found in `req`, the Span
|
52 | 50 |
// will be a trace root. The Span is incorporated in the returned Context and
|
53 | 51 |
// can be retrieved with opentracing.SpanFromContext(ctx).
|
54 | |
//
|
55 | |
// The logger is used to report errors and may be nil.
|
56 | 52 |
func FromHTTPRequest(tracer opentracing.Tracer, operationName string, logger log.Logger) kithttp.RequestFunc {
|
57 | 53 |
return func(ctx context.Context, req *http.Request) context.Context {
|
58 | 54 |
// Try to join to a trace propagated in `req`.
|
|
61 | 57 |
opentracing.TextMap,
|
62 | 58 |
opentracing.HTTPHeaderTextMapCarrier(req.Header),
|
63 | 59 |
)
|
64 | |
if err != nil {
|
|
60 |
if err != nil && err != opentracing.ErrSpanContextNotFound {
|
65 | 61 |
logger.Log("err", err)
|
66 | 62 |
}
|
67 | 63 |
span = tracer.StartSpan(operationName, ext.RPCServerOption(wireContext))
|