Package list golang-github-go-kit-kit / 0bc00f3
OpenTracing breaking API change: SpanContext Bas van Beek 5 years ago
3 changed file(s) with 21 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
3636 return func(next endpoint.Endpoint) endpoint.Endpoint {
3737 return func(ctx context.Context, request interface{}) (interface{}, error) {
3838 parentSpan := opentracing.SpanFromContext(ctx)
39 clientSpan := tracer.StartSpanWithOptions(opentracing.StartSpanOptions{
40 OperationName: operationName,
41 Parent: parentSpan, // may be nil
42 })
39 clientSpan := tracer.StartSpan(
40 operationName,
41 opentracing.ChildOf(parentSpan.Context()),
42 )
4343 defer clientSpan.Finish()
4444 otext.SpanKind.Set(clientSpan, otext.SpanKindRPCClient)
4545 ctx = opentracing.ContextWithSpan(ctx, clientSpan)
44 "strings"
55
66 "github.com/opentracing/opentracing-go"
7 "github.com/opentracing/opentracing-go/ext"
78 "golang.org/x/net/context"
89 "google.golang.org/grpc/metadata"
910
1920 return func(ctx context.Context, md *metadata.MD) context.Context {
2021 if span := opentracing.SpanFromContext(ctx); span != nil {
2122 // There's nothing we can do with an error here.
22 if err := tracer.Inject(span, opentracing.TextMap, metadataReaderWriter{md}); err != nil {
23 if err := tracer.Inject(span.Context(), opentracing.TextMap, metadataReaderWriter{md}); err != nil {
2324 logger.Log("err", err)
2425 }
2526 }
3637 // The logger is used to report errors and may be nil.
3738 func FromGRPCRequest(tracer opentracing.Tracer, operationName string, logger log.Logger) func(ctx context.Context, md *metadata.MD) context.Context {
3839 return func(ctx context.Context, md *metadata.MD) context.Context {
39 span, err := tracer.Join(operationName, opentracing.TextMap, metadataReaderWriter{md})
40 var span opentracing.Span
41 wireContext, err := tracer.Extract(opentracing.TextMap, metadataReaderWriter{md})
4042 if err != nil {
43 logger.Log("err", err)
44 }
45 if wireContext != nil {
46 span = tracer.StartSpan(operationName, ext.RPCServerOption(wireContext))
47 } else {
4148 span = tracer.StartSpan(operationName)
42 if err != opentracing.ErrTraceNotFound {
43 logger.Log("err", err)
44 }
4549 }
4650 return opentracing.ContextWithSpan(ctx, span)
4751 }
3535
3636 // There's nothing we can do with any errors here.
3737 if err = tracer.Inject(
38 span,
38 span.Context(),
3939 opentracing.TextMap,
4040 opentracing.HTTPHeaderTextMapCarrier(req.Header),
4141 ); err != nil {
5656 func FromHTTPRequest(tracer opentracing.Tracer, operationName string, logger log.Logger) kithttp.RequestFunc {
5757 return func(ctx context.Context, req *http.Request) context.Context {
5858 // Try to join to a trace propagated in `req`.
59 span, err := tracer.Join(
60 operationName,
59 var span opentracing.Span
60 wireContext, err := tracer.Extract(
6161 opentracing.TextMap,
6262 opentracing.HTTPHeaderTextMapCarrier(req.Header),
6363 )
6464 if err != nil {
65 logger.Log("err", err)
66 }
67 if wireContext != nil {
68 span = tracer.StartSpan(operationName, ext.RPCServerOption(wireContext))
69 } else {
6570 span = tracer.StartSpan(operationName)
66 if err != opentracing.ErrTraceNotFound {
67 logger.Log("err", err)
68 }
6971 }
7072 return opentracing.ContextWithSpan(ctx, span)
7173 }