I am using zipkin-go-opentracing, which is an implementation of the opentracing API for zipkin in go.
For (reasons) I need to get the traceId from a span. So the question: given a opentracing.Span, how do I get the TraceId? Everything I've tried has given me some kind of type assertion error.
Thanks,
import (
"github.com/opentracing/opentracing-go"
"github.com/openzipkin/zipkin-go-opentracing"
)
func IdFromSpan(aspan interface{}) uint64 {
zspan := aspan.(zipkintracer.Span)
return zspan.Context().TraceID
}
I'm not sure this is the right way to do it but this should normally works
stdopentracing "github.com/opentracing/opentracing-go"
zipkin "github.com/openzipkin/zipkin-go-opentracing"
[...]
var traceID string
sp := stdopentracing.SpanFromContext(ctx)
if sp != nil {
traceID = sp.Context().(zipkin.SpanContext).TraceID.ToHex()
}