census-instrumentation / opencensus-go

A stats collection and distributed tracing framework
http://opencensus.io
Apache License 2.0
2.06k stars 327 forks source link

ochttp public traceparent/tracestate marshal/unmarshal #1208

Closed slinkydeveloper closed 4 years ago

slinkydeveloper commented 4 years ago

NB: Before opening a feature request against this repo, consider whether the feature should/could be implemented in OpenCensus libraries in other languages. If so, please open an issue on opencensus-specs first.

Is your feature request related to a problem? Please describe. I wish to read and write traceparent/tracestate, encoded using trace context, without passing an http.Request

Describe the solution you'd like Two new methods should be added to HttpFormat or as public functions:

SpanContextFromHeaders(traceparent string, tracestate string) (sc trace.SpanContext, ok bool)
SpanContextToRequest(sc trace.SpanContext) (traceparent string, tracestate string)

Describe alternatives you've considered AFAIK no alternatives are available in this library, except copy pasting that code in my own code.

llhhbc commented 4 years ago

This method has already has in package: go.opencensus.io/plugin/ochttp/propagation/b3

HTTPFormat{}

func (f *HTTPFormat) SpanContextFromRequest(req *http.Request) (sc trace.SpanContext, ok bool)

func (f *HTTPFormat) SpanContextToRequest(sc trace.SpanContext, req *http.Request)
slinkydeveloper commented 4 years ago

What I mean is that I want to extract manually the traceparent/tracestate headers and then i want to pass them to a method, while these two methods interacts already with http request