diff --git a/.chloggen/dd-receiver-span-id.yaml b/.chloggen/dd-receiver-span-id.yaml new file mode 100755 index 000000000000..706c3dffcb6a --- /dev/null +++ b/.chloggen/dd-receiver-span-id.yaml @@ -0,0 +1,20 @@ +# Use this changelog template to create an entry for release notes. +# If your change doesn't affect end users, such as a test fix or a tooling change, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# 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: "add datadog trace and span id" + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [23057] + +# (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: diff --git a/receiver/datadogreceiver/translator.go b/receiver/datadogreceiver/translator.go index 2fd2a72a4bcc..3b007aa75da8 100644 --- a/receiver/datadogreceiver/translator.go +++ b/receiver/datadogreceiver/translator.go @@ -10,6 +10,7 @@ import ( "io" "mime" "net/http" + "strconv" "strings" "sync" @@ -22,6 +23,18 @@ import ( const ( datadogSpanKindKey = "span.kind" + // The datadog trace id + // + // Type: string + // Requirement Level: Optional + // Examples: '6249785623524942554' + attributeDatadogTraceID = "datadog.trace.id" + // The datadog span id + // + // Type: string + // Requirement Level: Optional + // Examples: '228114450199004348' + attributeDatadogSpanID = "datadog.span.id" ) func upsertHeadersAttributes(req *http.Request, attrs pcommon.Map) { @@ -89,7 +102,8 @@ func toTraces(payload *pb.TracerPayload, req *http.Request) ptrace.Traces { if span.Error > 0 { newSpan.Status().SetCode(ptrace.StatusCodeError) } - + newSpan.Attributes().PutStr(attributeDatadogSpanID, strconv.FormatUint(span.SpanID, 10)) + newSpan.Attributes().PutStr(attributeDatadogTraceID, strconv.FormatUint(span.TraceID, 10)) for k, v := range span.GetMeta() { if k = translateDataDogKeyToOtel(k); len(k) > 0 { newSpan.Attributes().PutStr(k, v) diff --git a/receiver/datadogreceiver/translator_test.go b/receiver/datadogreceiver/translator_test.go index 46dd95f9369a..94f05eba7342 100644 --- a/receiver/datadogreceiver/translator_test.go +++ b/receiver/datadogreceiver/translator_test.go @@ -74,10 +74,10 @@ func TestTracePayloadV05Unmarshalling(t *testing.T) { assert.Equal(t, 1, translated.SpanCount(), "Span Count wrong") span := translated.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0) assert.NotNil(t, span) - assert.Equal(t, 5, span.Attributes().Len(), "missing tags") + assert.Equal(t, 7, span.Attributes().Len(), "missing attributes") value, exists := span.Attributes().Get("service.name") assert.True(t, exists, "service.name missing") - assert.Equal(t, "my-service", value.AsString(), "service.name tag value incorrect") + assert.Equal(t, "my-service", value.AsString(), "service.name attribute value incorrect") assert.Equal(t, "my-name", span.Name()) spanResource, _ := span.Attributes().Get("dd.span.Resource") assert.Equal(t, "my-resource", spanResource.Str()) @@ -103,10 +103,10 @@ func TestTracePayloadV07Unmarshalling(t *testing.T) { translated, _ := handlePayload(req) span := translated.GetChunks()[0].GetSpans()[0] assert.NotNil(t, span) - assert.Equal(t, 4, len(span.GetMeta()), "missing tags") + assert.Equal(t, 4, len(span.GetMeta()), "missing attributes") value, exists := span.GetMeta()["service.name"] assert.True(t, exists, "service.name missing") - assert.Equal(t, "my-service", value, "service.name tag value incorrect") + assert.Equal(t, "my-service", value, "service.name attribute value incorrect") assert.Equal(t, "my-name", span.GetName()) assert.Equal(t, "my-resource", span.GetResource()) }