Skip to content

Commit

Permalink
ddtrace/tracer: fix top_level computation with DD_SERVICE_MAPPING (#1150
Browse files Browse the repository at this point in the history
)

Fixes a bug where the service name can be changed via DD_SERVICE_MAPPING after the top level span is computed.
  • Loading branch information
mackjmr committed Mar 1, 2022
1 parent 07c5508 commit 585a18a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ddtrace/tracer/tracer.go
Expand Up @@ -394,6 +394,11 @@ func (t *tracer) StartSpan(operationName string, options ...ddtrace.StartSpanOpt
for k, v := range t.config.globalTags {
span.SetTag(k, v)
}
if t.config.serviceMappings != nil {
if newSvc, ok := t.config.serviceMappings[span.Service]; ok {
span.Service = newSvc
}
}
if context == nil || context.span == nil || context.span.Service != span.Service {
span.setMetric(keyTopLevel, 1)
// all top level spans are measured. So the measured tag is redundant.
Expand All @@ -412,11 +417,6 @@ func (t *tracer) StartSpan(operationName string, options ...ddtrace.StartSpanOpt
if t.config.profilerHotspots || t.config.profilerEndpoints {
t.applyPPROFLabels(pprofContext, span)
}
if t.config.serviceMappings != nil {
if newSvc, ok := t.config.serviceMappings[span.Service]; ok {
span.Service = newSvc
}
}
log.Debug("Started Span: %v, Operation: %s, Resource: %s, Tags: %v, %v", span, span.Name, span.Resource, span.Meta, span.Metrics)
return span
}
Expand Down

0 comments on commit 585a18a

Please sign in to comment.