Skip to content

Commit

Permalink
[datadogreceiver] Fix set telemetry.sdk.language=dotnet instead of .N…
Browse files Browse the repository at this point in the history
…ET (#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.>
  • Loading branch information
povilasv authored Nov 27, 2023
1 parent b8aac27 commit 506813e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .chloggen/dd-receiver-language.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: datadogreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Fix set telemetry.sdk.language=dotnet instead of .NET"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [29459]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
6 changes: 5 additions & 1 deletion receiver/datadogreceiver/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ func upsertHeadersAttributes(req *http.Request, attrs pcommon.Map) {
attrs.PutStr(semconv.AttributeTelemetrySDKVersion, "Datadog-"+ddTracerVersion)
}
if ddTracerLang := req.Header.Get("Datadog-Meta-Lang"); ddTracerLang != "" {
attrs.PutStr(semconv.AttributeTelemetrySDKLanguage, ddTracerLang)
otelLang := ddTracerLang
if ddTracerLang == ".NET" {
otelLang = "dotnet"
}
attrs.PutStr(semconv.AttributeTelemetrySDKLanguage, otelLang)
}
}

Expand Down
21 changes: 21 additions & 0 deletions receiver/datadogreceiver/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
vmsgp "github.com/vmihailenco/msgpack/v4"
"go.opentelemetry.io/collector/pdata/pcommon"
semconv "go.opentelemetry.io/collector/semconv/v1.16.0"
"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -176,5 +178,24 @@ func agentPayloadFromTraces(traces *pb.Traces) (agentPayload pb.AgentPayload) {
return pb.AgentPayload{
TracerPayloads: tracerPayloads,
}
}

func TestUpsertHeadersAttributes(t *testing.T) {
// Test case 1: Datadog-Meta-Tracer-Version is present in headers
req1, _ := http.NewRequest("GET", "http://example.com", nil)
req1.Header.Set("Datadog-Meta-Tracer-Version", "1.2.3")
attrs1 := pcommon.NewMap()
upsertHeadersAttributes(req1, attrs1)
val, ok := attrs1.Get(semconv.AttributeTelemetrySDKVersion)
assert.True(t, ok)
assert.Equal(t, "Datadog-1.2.3", val.Str())

// Test case 2: Datadog-Meta-Lang is present in headers with ".NET"
req2, _ := http.NewRequest("GET", "http://example.com", nil)
req2.Header.Set("Datadog-Meta-Lang", ".NET")
attrs2 := pcommon.NewMap()
upsertHeadersAttributes(req2, attrs2)
val, ok = attrs2.Get(semconv.AttributeTelemetrySDKLanguage)
assert.True(t, ok)
assert.Equal(t, "dotnet", val.Str())
}

0 comments on commit 506813e

Please sign in to comment.