Skip to content

Commit

Permalink
fix(datadogreceiver): set AppVersion on payload so it propagates corr…
Browse files Browse the repository at this point in the history
…ectly (open-telemetry#30225)

**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.-->
This PR sets the AppVersion property for the default fallthrough case if
it exists on any spans in the request. This allows it to properly
propagate through to Datadog. Currently, if using a library such as
datadog/dd-trace-dotnet , the datadog service version property
(dd_version) does not propagate through to datadog at all.

The bug that this fixes is that the Datadog version resource attribute
is currently not flowing through.
**Link to tracking Issue:** <Issue number if applicable>
Closes open-telemetry#30526 

**Testing:** <Describe what testing was performed and which tests were
added.>
Local testing using delve to confirm expected behavior, added existing
version tag to tests. Deployed patch internally on OpenTelemetry
collector and observed desired behavior.
**Documentation:** <Describe the documentation added.>
  • Loading branch information
Jonah Back authored and cparkins committed Feb 1, 2024
1 parent 34741f9 commit 6ea8c6a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
27 changes: 27 additions & 0 deletions .chloggen/fix_dd-app-version.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: Set AppVersion to allow Datadog version property to transform properly to service.version resource attribute

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

# (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: []
24 changes: 22 additions & 2 deletions receiver/datadogreceiver/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,15 @@ func handlePayload(req *http.Request) (tp []*pb.TracerPayload, err error) {
return nil, err
}

traceChunks := traceChunksFromTraces(traces)
appVersion := appVersionFromTraceChunks(traceChunks)

tracerPayload := &pb.TracerPayload{
LanguageName: req.Header.Get("Datadog-Meta-Lang"),
LanguageVersion: req.Header.Get("Datadog-Meta-Lang-Version"),
TracerVersion: req.Header.Get("Datadog-Meta-Tracer-Version"),
Chunks: traceChunksFromTraces(traces),
Chunks: traceChunks,
AppVersion: appVersion,
}
tracerPayloads = append(tracerPayloads, tracerPayload)

Expand Down Expand Up @@ -269,11 +273,14 @@ func handlePayload(req *http.Request) (tp []*pb.TracerPayload, err error) {
if err = decodeRequest(req, &traces); err != nil {
return nil, err
}
traceChunks := traceChunksFromTraces(traces)
appVersion := appVersionFromTraceChunks(traceChunks)
tracerPayload := &pb.TracerPayload{
LanguageName: req.Header.Get("Datadog-Meta-Lang"),
LanguageVersion: req.Header.Get("Datadog-Meta-Lang-Version"),
TracerVersion: req.Header.Get("Datadog-Meta-Tracer-Version"),
Chunks: traceChunksFromTraces(traces),
Chunks: traceChunks,
AppVersion: appVersion,
}
tracerPayloads = append(tracerPayloads, tracerPayload)
}
Expand Down Expand Up @@ -342,6 +349,19 @@ func traceChunksFromTraces(traces pb.Traces) []*pb.TraceChunk {
return traceChunks
}

func appVersionFromTraceChunks(traces []*pb.TraceChunk) string {
appVersion := ""
for _, trace := range traces {
for _, span := range trace.Spans {
if span != nil && span.Meta["version"] != "" {
appVersion = span.Meta["version"]
return appVersion
}
}
}
return appVersion
}

func getMediaType(req *http.Request) string {
mt, _, err := mime.ParseMediaType(req.Header.Get("Content-Type"))
if err != nil {
Expand Down
11 changes: 8 additions & 3 deletions receiver/datadogreceiver/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var data = [2]any{
9: "value whatever",
10: "sql",
11: "service.name",
12: "1.0.1",
13: "version",
},
1: [][][12]any{
{
Expand All @@ -51,6 +53,7 @@ var data = [2]any{
0: 1,
2: 3,
11: 6,
13: 12,
},
map[any]float64{
5: 1.2,
Expand Down Expand Up @@ -89,11 +92,13 @@ 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, 7, span.Attributes().Len(), "missing attributes")
assert.Equal(t, 8, span.Attributes().Len(), "missing attributes")
value, exists := span.Attributes().Get("service.name")
serviceVersionValue, _ := span.Attributes().Get("service.version")
assert.True(t, exists, "service.name missing")
assert.Equal(t, "my-service", value.AsString(), "service.name attribute value incorrect")
assert.Equal(t, "my-name", span.Name())
assert.Equal(t, "1.0.1", serviceVersionValue.AsString())
spanResource, _ := span.Attributes().Get("dd.span.Resource")
assert.Equal(t, "my-resource", spanResource.Str())
}
Expand All @@ -115,7 +120,7 @@ func TestTracePayloadV07Unmarshalling(t *testing.T) {
translated := translatedPayloads[0]
span := translated.GetChunks()[0].GetSpans()[0]
assert.NotNil(t, span)
assert.Equal(t, 4, len(span.GetMeta()), "missing attributes")
assert.Equal(t, 5, 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 attribute value incorrect")
Expand Down Expand Up @@ -155,7 +160,7 @@ func TestTracePayloadApiV02Unmarshalling(t *testing.T) {
span := translated.Chunks[0].Spans[0]

assert.NotNil(t, span)
assert.Equal(t, 4, len(span.Meta), "missing attributes")
assert.Equal(t, 5, len(span.Meta), "missing attributes")
assert.Equal(t, "my-service", span.Meta["service.name"])
assert.Equal(t, "my-name", span.Name)
assert.Equal(t, "my-resource", span.Resource)
Expand Down

0 comments on commit 6ea8c6a

Please sign in to comment.