From 500389219057f9a6a1463ba0ad8d5f2172acba6a Mon Sep 17 00:00:00 2001 From: Brian Marks Date: Thu, 27 Aug 2026 17:06:42 -0400 Subject: [PATCH 1/3] Support stable OTel deployment environment attribute --- .../Configuration/MutableSettings.cs | 4 ++- .../Configuration/MutableSettingsTests.cs | 32 ++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/tracer/src/Datadog.Trace/Configuration/MutableSettings.cs b/tracer/src/Datadog.Trace/Configuration/MutableSettings.cs index caf31e49e2d5..c8c3ede81b71 100644 --- a/tracer/src/Datadog.Trace/Configuration/MutableSettings.cs +++ b/tracer/src/Datadog.Trace/Configuration/MutableSettings.cs @@ -1107,8 +1107,10 @@ private static ConfigurationBuilder.ClassConfigurationResultWithKey Date: Thu, 3 Sep 2026 10:54:03 -0700 Subject: [PATCH 2/3] Update one more location where we parse deployment.environment so that we prefer deployment.environment.name --- .../src/Datadog.Trace/Activity/OtlpHelpers.cs | 2 +- .../Tagging/ActivityTagsTests.cs | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/tracer/src/Datadog.Trace/Activity/OtlpHelpers.cs b/tracer/src/Datadog.Trace/Activity/OtlpHelpers.cs index 490a1f426e03..9a3a06187446 100644 --- a/tracer/src/Datadog.Trace/Activity/OtlpHelpers.cs +++ b/tracer/src/Datadog.Trace/Activity/OtlpHelpers.cs @@ -127,7 +127,7 @@ private static void AgentConvertSpan(TInner activity, Span span, bool op // Fixup "env" tag if (traceContext is not null && traceContext.Environment is null - && span.GetTag("deployment.environment") is { Length: > 0 } otelServiceEnv) + && (span.GetTag("deployment.environment.name") ?? span.GetTag("deployment.environment")) is { Length: > 0 } otelServiceEnv) { traceContext.Environment = otelServiceEnv; } diff --git a/tracer/test/Datadog.Trace.Tests/Tagging/ActivityTagsTests.cs b/tracer/test/Datadog.Trace.Tests/Tagging/ActivityTagsTests.cs index 796710d17b22..aa8a11479ea5 100644 --- a/tracer/test/Datadog.Trace.Tests/Tagging/ActivityTagsTests.cs +++ b/tracer/test/Datadog.Trace.Tests/Tagging/ActivityTagsTests.cs @@ -160,4 +160,46 @@ public async Task ActivityLink_PreservesTraceStateWithoutParsingOtelTraceState() spanLinkContext.AdditionalW3CTraceState.Should().Be("ot=rv:ef284ace7a91e1;th:e6666666666668"); spanLinkContext.OtelTraceState.Should().BeNull(); } + + [Theory] + [InlineData("deployment.environment.name", "stable_env")] + [InlineData("deployment.environment", "legacy_env")] + public async Task Environment_ShouldBe_FixedUpFromActivityTag(string tagKey, string tagValue) + { + var activityMock = new Mock(); + activityMock.Setup(x => x.Kind).Returns(ActivityKind.Producer); + + var tagObjects = new Dictionary { { tagKey, tagValue } }; + activityMock.Setup(x => x.TagObjects).Returns(tagObjects); + + // UpdateSpanFromActivity implicitly accesses Tracer.Instance if there's no associated Tracer in the span + await using var tracer = TracerHelper.CreateWithFakeAgent(); + using var span = tracer.StartSpan("operation", new OpenTelemetryTags()); + + OtlpHelpers.UpdateSpanFromActivity(activityMock.Object, span); + + span.Context.TraceContext!.Environment.Should().Be(tagValue); + } + + [Fact] + public async Task Environment_StableTagName_ShouldTakePrecedenceOverLegacyTagName() + { + var activityMock = new Mock(); + activityMock.Setup(x => x.Kind).Returns(ActivityKind.Producer); + + var tagObjects = new Dictionary + { + { "deployment.environment", "legacy_env" }, + { "deployment.environment.name", "stable_env" } + }; + activityMock.Setup(x => x.TagObjects).Returns(tagObjects); + + // UpdateSpanFromActivity implicitly accesses Tracer.Instance if there's no associated Tracer in the span + await using var tracer = TracerHelper.CreateWithFakeAgent(); + using var span = tracer.StartSpan("operation", new OpenTelemetryTags()); + + OtlpHelpers.UpdateSpanFromActivity(activityMock.Object, span); + + span.Context.TraceContext!.Environment.Should().Be("stable_env"); + } } From 08968bcb78ca4eaadf574e39a4e0697bb85d76f4 Mon Sep 17 00:00:00 2001 From: Zach Montoya Date: Thu, 17 Sep 2026 16:03:13 -0400 Subject: [PATCH 3/3] Update handling of empty deployment.environment.name resource attribute so that it falls back to the legacy deployment.environment resource attribute --- .../Configuration/MutableSettings.cs | 3 +- .../Configuration/MutableSettingsTests.cs | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/tracer/src/Datadog.Trace/Configuration/MutableSettings.cs b/tracer/src/Datadog.Trace/Configuration/MutableSettings.cs index c8c3ede81b71..171dd9d40f75 100644 --- a/tracer/src/Datadog.Trace/Configuration/MutableSettings.cs +++ b/tracer/src/Datadog.Trace/Configuration/MutableSettings.cs @@ -1107,7 +1107,8 @@ private static ConfigurationBuilder.ClassConfigurationResultWithKey