Skip to content

Commit 36b603d

Browse files
[receiver/datadog][bug-fix] Add DD span metrics as attributes (#35087)
**Description:** <Describe what has changed.> Datadog [divides the span's tags](https://github.com/DataDog/dd-trace-java/blob/master/dd-trace-core/src/main/java/datadog/trace/common/writer/ddagent/TraceMapperV0_5.java#L210-L212) into [two fields](https://github.com/DataDog/datadog-agent/blob/1739a048156d968bbe5fd8a1ace8e07c997d16d9/pkg/proto/datadog/trace/span.proto#L50-L55), `meta` for string values and `metrics` for numeric ones. Currently, the receiver isn't considering the `metrics` field when building the OTel span's attributes, losing this metadata during the conversion. This PR fixes this issue. **Link to tracking Issue:** <Issue number if applicable> **Testing:** <Describe what testing was performed and which tests were added.> **Documentation:** <Describe the documentation added.> --------- Co-authored-by: Sean Marciniak <[email protected]>
1 parent 1187fdd commit 36b603d

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed
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 numeric span attributes
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: [35087]
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/internal/translator/traces_translator.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ func ToTraces(payload *pb.TracerPayload, req *http.Request) ptrace.Traces {
119119
newSpan.Attributes().PutStr(k, v)
120120
}
121121
}
122+
for k, v := range span.GetMetrics() {
123+
if k = translateDatadogKeyToOTel(k); len(k) > 0 {
124+
newSpan.Attributes().PutDouble(k, v)
125+
}
126+
}
122127

123128
switch span.Meta[datadogSpanKindKey] {
124129
case "server":

receiver/datadogreceiver/internal/translator/traces_translator_test.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"io"
1010
"net/http"
11+
"strconv"
1112
"testing"
1213

1314
pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/trace"
@@ -28,7 +29,7 @@ var data = [2]any{
2829
2: "elasticsearch.version",
2930
3: "7.0",
3031
4: "my-name",
31-
5: "X",
32+
5: "numeric_attribute",
3233
6: "my-service",
3334
7: "my-resource",
3435
8: "_sampling_priority_v1",
@@ -86,26 +87,27 @@ func TestTracePayloadV05Unmarshalling(t *testing.T) {
8687
require.NoError(t, traces.UnmarshalMsgDictionary(payload), "Must not error when marshaling content")
8788
req, _ := http.NewRequest(http.MethodPost, "/v0.5/traces", io.NopCloser(bytes.NewReader(payload)))
8889

89-
translated := ToTraces(&pb.TracerPayload{
90-
LanguageName: req.Header.Get(header.Lang),
91-
LanguageVersion: req.Header.Get(header.LangVersion),
92-
TracerVersion: req.Header.Get(header.TracerVersion),
93-
Chunks: traceChunksFromTraces(traces),
94-
}, req)
90+
tracePayloads, _ := HandleTracesPayload(req)
91+
assert.Len(t, tracePayloads, 1, "Expected one translated payload")
92+
tracePayload := tracePayloads[0]
93+
translated := ToTraces(tracePayload, req)
9594
assert.Equal(t, 1, translated.SpanCount(), "Span Count wrong")
9695
span := translated.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0)
9796
assert.NotNil(t, span)
98-
assert.Equal(t, 9, span.Attributes().Len(), "missing attributes")
97+
assert.Equal(t, "my-name", span.Name())
98+
assert.Equal(t, 10, span.Attributes().Len(), "missing attributes")
9999
value, exists := span.Attributes().Get("service.name")
100-
serviceVersionValue, _ := span.Attributes().Get("service.version")
101100
assert.True(t, exists, "service.name missing")
102101
assert.Equal(t, "my-service", value.AsString(), "service.name attribute value incorrect")
103-
assert.Equal(t, "my-name", span.Name())
102+
serviceVersionValue, _ := span.Attributes().Get("service.version")
104103
assert.Equal(t, "1.0.1", serviceVersionValue.AsString())
105104
spanResource, _ := span.Attributes().Get("dd.span.Resource")
106105
assert.Equal(t, "my-resource", spanResource.Str())
107106
spanResource1, _ := span.Attributes().Get("sampling.priority")
108107
assert.Equal(t, fmt.Sprintf("%f", 1.0), spanResource1.Str())
108+
numericAttributeValue, _ := span.Attributes().Get("numeric_attribute")
109+
numericAttributeFloat, _ := strconv.ParseFloat(numericAttributeValue.AsString(), 64)
110+
assert.Equal(t, 1.2, numericAttributeFloat)
109111
}
110112

111113
func TestTracePayloadV07Unmarshalling(t *testing.T) {

0 commit comments

Comments
 (0)