StartSpanFromContext starts a new opentracing span if opentracing is registered, otherwise it starts a new otel span.
(ctx context.Context, operation string, options ...SpanOption)
| 21 | |
| 22 | // StartSpanFromContext starts a new opentracing span if opentracing is registered, otherwise it starts a new otel span. |
| 23 | func StartSpanFromContext(ctx context.Context, operation string, options ...SpanOption) (*Span, context.Context) { |
| 24 | if opentracing.IsGlobalTracerRegistered() { |
| 25 | var opentracingOptions []opentracing.StartSpanOption |
| 26 | for _, opt := range options { |
| 27 | opentracingOptions = append(opentracingOptions, opt.opentracingSpanOptions()...) |
| 28 | } |
| 29 | span, ctx := opentracing.StartSpanFromContext(ctx, operation, opentracingOptions...) |
| 30 | s := &Span{opentracingSpan: span} |
| 31 | for _, opt := range options { |
| 32 | opt.apply(s) |
| 33 | } |
| 34 | return s, ctx |
| 35 | } |
| 36 | |
| 37 | var otelOptions []trace.SpanStartOption |
| 38 | for _, opt := range options { |
| 39 | otelOptions = append(otelOptions, opt.otelSpanOptions()...) |
| 40 | } |
| 41 | ctx, span := tracer.Start(ctx, operation, otelOptions...) |
| 42 | s := &Span{otelSpan: span} |
| 43 | for _, opt := range options { |
| 44 | opt.apply(s) |
| 45 | } |
| 46 | return s, ctx |
| 47 | } |
| 48 | |
| 49 | func (s *Span) SetTag(name string, value any) { |
| 50 | if s.opentracingSpan != nil { |