Skip to content

Commit 506813e

Browse files
authored
[datadogreceiver] Fix set telemetry.sdk.language=dotnet instead of .NET (#29460)
**Description:** <Describe what has changed.> <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> Looks like DataDog's library uses ".NET" as value instead of "dotnet" in their instrumentation: See: https://github.com/DataDog/dd-trace-dotnet/blob/ecb5d5949f6c29dbe99a451c7a3574013cfeb1bd/tracer/src/Datadog.Trace/AgentHttpHeaderNames.cs#L76 So we need to remap ".NET" to "dotnet" to follow OTEL semantic conventions. **Link to tracking Issue:** #29459 **Testing:** <Describe what testing was performed and which tests were added.> - added unit test **Documentation:** <Describe the documentation added.>
1 parent b8aac27 commit 506813e

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

.chloggen/dd-receiver-language.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: datadogreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Fix set telemetry.sdk.language=dotnet instead of .NET"
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [29459]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

receiver/datadogreceiver/translator.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ func upsertHeadersAttributes(req *http.Request, attrs pcommon.Map) {
4343
attrs.PutStr(semconv.AttributeTelemetrySDKVersion, "Datadog-"+ddTracerVersion)
4444
}
4545
if ddTracerLang := req.Header.Get("Datadog-Meta-Lang"); ddTracerLang != "" {
46-
attrs.PutStr(semconv.AttributeTelemetrySDKLanguage, ddTracerLang)
46+
otelLang := ddTracerLang
47+
if ddTracerLang == ".NET" {
48+
otelLang = "dotnet"
49+
}
50+
attrs.PutStr(semconv.AttributeTelemetrySDKLanguage, otelLang)
4751
}
4852
}
4953

receiver/datadogreceiver/translator_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"github.com/stretchr/testify/assert"
1515
"github.com/stretchr/testify/require"
1616
vmsgp "github.com/vmihailenco/msgpack/v4"
17+
"go.opentelemetry.io/collector/pdata/pcommon"
18+
semconv "go.opentelemetry.io/collector/semconv/v1.16.0"
1719
"google.golang.org/protobuf/proto"
1820
)
1921

@@ -176,5 +178,24 @@ func agentPayloadFromTraces(traces *pb.Traces) (agentPayload pb.AgentPayload) {
176178
return pb.AgentPayload{
177179
TracerPayloads: tracerPayloads,
178180
}
181+
}
179182

183+
func TestUpsertHeadersAttributes(t *testing.T) {
184+
// Test case 1: Datadog-Meta-Tracer-Version is present in headers
185+
req1, _ := http.NewRequest("GET", "http://example.com", nil)
186+
req1.Header.Set("Datadog-Meta-Tracer-Version", "1.2.3")
187+
attrs1 := pcommon.NewMap()
188+
upsertHeadersAttributes(req1, attrs1)
189+
val, ok := attrs1.Get(semconv.AttributeTelemetrySDKVersion)
190+
assert.True(t, ok)
191+
assert.Equal(t, "Datadog-1.2.3", val.Str())
192+
193+
// Test case 2: Datadog-Meta-Lang is present in headers with ".NET"
194+
req2, _ := http.NewRequest("GET", "http://example.com", nil)
195+
req2.Header.Set("Datadog-Meta-Lang", ".NET")
196+
attrs2 := pcommon.NewMap()
197+
upsertHeadersAttributes(req2, attrs2)
198+
val, ok = attrs2.Get(semconv.AttributeTelemetrySDKLanguage)
199+
assert.True(t, ok)
200+
assert.Equal(t, "dotnet", val.Str())
180201
}

0 commit comments

Comments
 (0)