diff --git a/.chloggen/strip-aws-sdk-local-root.yaml b/.chloggen/strip-aws-sdk-local-root.yaml new file mode 100644 index 000000000000..4c43b5405339 --- /dev/null +++ b/.chloggen/strip-aws-sdk-local-root.yaml @@ -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: awsxrayexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Extend the AWSK.SDK prefix stripping to cover a previously missed case, for local root spans + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [27232] + +# (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: Follow-up from https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/27232 + +# 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: [user] \ No newline at end of file diff --git a/exporter/awsxrayexporter/internal/translator/segment.go b/exporter/awsxrayexporter/internal/translator/segment.go index efda3ed22f2e..0ff0199016e3 100644 --- a/exporter/awsxrayexporter/internal/translator/segment.go +++ b/exporter/awsxrayexporter/internal/translator/segment.go @@ -155,7 +155,8 @@ func MakeDependencySubsegmentForLocalRootDependencySpan(span ptrace.Span, resour } if myAwsRemoteService, ok := span.Attributes().Get(awsRemoteService); ok { - dependencySubsegment.Name = awsxray.String(myAwsRemoteService.Str()) + subsegmentName := myAwsRemoteService.Str() + dependencySubsegment.Name = awsxray.String(trimAwsSdkPrefix(subsegmentName, span)) } return dependencySubsegment, err @@ -370,9 +371,7 @@ func MakeSegment(span ptrace.Span, resource pcommon.Resource, indexedAttrs []str if remoteServiceName, ok := attributes.Get(awsRemoteService); ok { name = remoteServiceName.Str() // only strip the prefix for AWS spans - if isAwsSdkSpan(span) && strings.HasPrefix(name, "AWS.SDK.") { - name = strings.TrimPrefix(name, "AWS.SDK.") - } + name = trimAwsSdkPrefix(name, span) } } @@ -752,3 +751,10 @@ func fixAnnotationKey(key string) string { } }, key) } + +func trimAwsSdkPrefix(name string, span ptrace.Span) string { + if isAwsSdkSpan(span) && strings.HasPrefix(name, "AWS.SDK.") { + return strings.TrimPrefix(name, "AWS.SDK.") + } + return name +} diff --git a/exporter/awsxrayexporter/internal/translator/segment_test.go b/exporter/awsxrayexporter/internal/translator/segment_test.go index dd5978c61309..18fdd70771ee 100644 --- a/exporter/awsxrayexporter/internal/translator/segment_test.go +++ b/exporter/awsxrayexporter/internal/translator/segment_test.go @@ -1333,6 +1333,39 @@ func TestLocalRootClient(t *testing.T) { assert.Equal(t, segments[0].EndTime, segments[1].EndTime) } +func TestLocalRootClientAwsServiceMetrics(t *testing.T) { + spanName := "SQS ReceiveMessage" + resource := getBasicResource() + + parentSpanID := newSegmentID() + + attributes := getBasicAttributes() + attributes[awsSpanKind] = "LOCAL_ROOT" + attributes[conventions.AttributeRPCSystem] = "aws-api" + attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPScheme] = "https" + attributes[conventions.AttributeRPCService] = "SQS" + attributes[awsRemoteService] = "AWS.SDK.SQS" + + span := constructClientSpan(parentSpanID, spanName, 200, "OK", attributes) + + spanLink := span.Links().AppendEmpty() + spanLink.SetTraceID(newTraceID()) + spanLink.SetSpanID(newSegmentID()) + + segments, err := MakeSegmentsFromSpan(span, resource, []string{awsRemoteService, "myAnnotationKey"}, false, nil, false) + + assert.NotNil(t, segments) + assert.Equal(t, 2, len(segments)) + assert.Nil(t, err) + + subsegment := segments[0] + + assert.Equal(t, "subsegment", *subsegment.Type) + assert.Equal(t, "SQS", *subsegment.Name) + assert.Equal(t, "aws", *subsegment.Namespace) +} + func TestLocalRootProducer(t *testing.T) { spanName := "destination operation" resource := getBasicResource()