Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(datadogreceiver): set AppVersion on payload so it propagates correctly #30225

Merged
merged 6 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading