Closed mgale closed 2 years ago
Instead of overwriting the UpdateRequest
what do you think of just adding the tracing info to the context.Context
which is passed to Getter.Get(ctx context.Context, key string, dest Sink) error
then makeRequest()
will check for the tracing info in the context, if it exists it's injected into the header. Thoughts?
@thrawn01 With OpenTracing, your tracing lifecycle looks like:
import "github.com/opentracing/opentracing-go"
tracer := opentracing.GlobalTracer()
span := tracer.StartSpan("My span name")
defer span.Finish()
ctx = opentracing.ContextWithSpan(ctx, span)
ctx
.httpReq, _ := http.NewRequest("GET", "http://myservice/", nil)
if span := opentracing.SpanFromContext(ctx); span != nil {
tracer.Inject(
span.Context(),
opentracing.HTTPHeaders,
opentracing.HTTPHeadersCarrier(httpReq.Header))
}
import (
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
)
wireContext, err := tracer.Extract(
opentracing.HTTPHeaders,
opentracing.HTTPHeadersCarrier(req.Header))
serverSpan = opentracing.StartSpan(
appSpecificOperationName,
ext.RPCServerOption(wireContext))
defer serverSpan.Finish()
ctx := opentracing.ContextWithSpan(context.Background(), serverSpan)
See example: https://github.com/opentracing/opentracing-go#serializing-to-the-wire
I like that approach but I ran into the scenario of wanting to pass opentracing context plus custom data for my own purposes.
However, after thinking about it some more, I think I can just add the data I need to the span, maybe via bagged items or something: https://opentracing.io/docs/overview/tags-logs-baggage/
I will run some tests locally and hopefully, the above workflow will work for me.
@mgale Trace baggage seems like the right tool.
I think we are going to pass on this PR for now. We should be able to do this by using the context or introducing trace support.
Initial idea on how this feature could be implemented.