Skip to content

Commit b847fe7

Browse files
authored
[receiver/datadog]: Fix #23150 (missing span.Resource) (#23814)
**Description:** Fixes #23150 by include the original `dd.span.Resource` in the attributes of the translated span **Link to tracking Issue:** [23150](#23150) **Testing:** Added test that span.Resource is included in translate attributes **Documentation:** Added note on `dd.span.Resource` to datadog receiver README
1 parent dcb4f04 commit b847fe7

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

.chloggen/issue-23150.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use this changelog template to create an entry for release notes.
2+
# If your change doesn't affect end users, such as a test fix or a tooling change,
3+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
4+
5+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
6+
change_type: bug_fix
7+
8+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
9+
component: datadogreceiver
10+
11+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
12+
note: Include datadog span.Resource in translated span attributes
13+
14+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
15+
issues: [23150]
16+
17+
# (Optional) One or more lines of additional information to render under the primary note.
18+
# These lines will be padded with 2 spaces and then inserted directly into the document.
19+
# Use pipe (|) for multiline entries.
20+
subtext:

receiver/datadogreceiver/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ All config params here are valid as well
4343
4444
https://github.com/open-telemetry/opentelemetry-collector/tree/main/config/confighttp#server-configuration
4545
46+
### Default Attributes
4647
48+
- `dd.span.Resource`: The datadog resource name (as distinct from the span name)

receiver/datadogreceiver/translator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func toTraces(payload *pb.TracerPayload, req *http.Request) ptrace.Traces {
8484
newSpan.SetParentSpanID(uInt64ToSpanID(span.ParentID))
8585
newSpan.SetName(span.Name)
8686
newSpan.Status().SetCode(ptrace.StatusCodeOk)
87+
newSpan.Attributes().PutStr("dd.span.Resource", span.Resource)
8788

8889
if span.Error > 0 {
8990
newSpan.Status().SetCode(ptrace.StatusCodeError)

receiver/datadogreceiver/translator_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@ func TestTracePayloadV05Unmarshalling(t *testing.T) {
7474
assert.Equal(t, 1, translated.SpanCount(), "Span Count wrong")
7575
span := translated.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0)
7676
assert.NotNil(t, span)
77-
assert.Equal(t, 4, span.Attributes().Len(), "missing tags")
77+
assert.Equal(t, 5, span.Attributes().Len(), "missing tags")
7878
value, exists := span.Attributes().Get("service.name")
7979
assert.True(t, exists, "service.name missing")
8080
assert.Equal(t, "my-service", value.AsString(), "service.name tag value incorrect")
8181
assert.Equal(t, "my-name", span.Name())
82+
spanResource, _ := span.Attributes().Get("dd.span.Resource")
83+
assert.Equal(t, "my-resource", spanResource.Str())
8284
}
8385

8486
func TestTracePayloadV07Unmarshalling(t *testing.T) {
@@ -106,6 +108,7 @@ func TestTracePayloadV07Unmarshalling(t *testing.T) {
106108
assert.True(t, exists, "service.name missing")
107109
assert.Equal(t, "my-service", value, "service.name tag value incorrect")
108110
assert.Equal(t, "my-name", span.GetName())
111+
assert.Equal(t, "my-resource", span.GetResource())
109112
}
110113

111114
func BenchmarkTranslatorv05(b *testing.B) {

0 commit comments

Comments
 (0)