dd-trace-go icon indicating copy to clipboard operation
dd-trace-go copied to clipboard

[BUG] Fatal issue in sqlcomment.go

Open fdc-michael-grosshans opened this issue 1 year ago • 2 comments

There is a mismatch in SQLCommentCarrier & textmap propagator about the fact that a span in spanContext can be nil, which leads to panics in code.

  1. In sqlcomment.go the SQLCommentCarrier assumes that a spanContext always has a non-nil span,
func (c *spanContext) meta(key string) (val string, ok bool) {
        // will panic if c.span is nil
	c.span.RLock()
	defer c.span.RUnlock()
	val, ok = c.span.Meta[key]
	return val, ok
}

func (c *SQLCommentCarrier) Inject(spanCtx ddtrace.SpanContext) error {
        .....
	case DBMPropagationModeService:
		if ctx, ok := spanCtx.(*spanContext); ok {
                        // calling meta assumes ctx.span to me non-nil
			if e, ok := ctx.meta(ext.Environment); ok && e != "" {
				tags[sqlCommentEnv] = e
			}
  1. In textmap.go the extractor creates a spanContext without an actual span.

Version latest

Describe what happened: A spanContext extracted from a textmap propagator that is injected into an SQLCommentCarrier will lead to panic.

Describe what you expected: Definetly no panic in a tracing library.

Steps to reproduce the issue:

  • Extract the context using textmap.go
  • Inject via sqlcomment.go

Additional environment details (Version of Go, Operating System, etc.):

fdc-michael-grosshans avatar Aug 30 '24 14:08 fdc-michael-grosshans