Skip to content

Commit 7832b66

Browse files
committed
Add fix for old otel
1 parent 17c9d03 commit 7832b66

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Activity/ActivityStopIntegration.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ internal static CallTargetReturn OnMethodEnd<TTarget>(TTarget instance, Exceptio
9292
ApplyStatusFallback(activity6, span);
9393
}
9494

95+
// OTel < 1.6 path: TelemetrySpan.SetStatus(Status.Error) writes "otel.status_code" via Activity.SetTag
96+
// without ever calling Activity.SetStatus, so ActivitySetStatusIntegration never fires and
97+
// span.Error stays false. Mirror OtlpHelpers.UpdateSpanFromActivity (the listener-path branch
98+
// for the same case) here so older OTel versions get the same error mapping.
99+
if (!span.Error
100+
&& span.Tags is OpenTelemetryTags errorTags
101+
&& string.Equals(errorTags.OtelStatusCode, "STATUS_CODE_ERROR", StringComparison.Ordinal))
102+
{
103+
span.Error = true;
104+
if (span.GetTag(Tags.ErrorMsg) is null
105+
&& span.GetTag("otel.status_description") is { Length: > 0 } desc)
106+
{
107+
span.SetTag(Tags.ErrorMsg, desc);
108+
}
109+
}
110+
95111
// If the span is in Error state, look in Activity.Events for an OTel "exception" event
96112
// (created by RecordException()) and copy its attributes into error.type/error.msg/error.stack.
97113
// The managed listener path does this via AgentStatus2ErrorActivity{5,6}; in the interception

0 commit comments

Comments
 (0)