Skip to content

[BUG] Fatal issue in sqlcomment.go #2837

Description

@fdc-michael-grosshans

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.):

Metadata

Metadata

Assignees

Labels

bugunintended behavior that has to be fixed

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions