From 16a9b37cf56402744325b68a1908160a19fc11cc Mon Sep 17 00:00:00 2001 From: John Knollmeyer Date: Thu, 19 Oct 2023 13:58:49 -0700 Subject: [PATCH 1/2] Add logic for stripping the AWS.SDK prefix for Local Root spans - Previous change to strip the prefix in other cases https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/27232/commits/7c037ad3022a2d5d0dcb09bf43cde89760fb5f8b --- .chloggen/strip-aws-sdk-local-root.yaml | 27 +++++++++++++++ .../internal/translator/segment.go | 6 +++- .../internal/translator/segment_test.go | 33 +++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 .chloggen/strip-aws-sdk-local-root.yaml 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..5fc66a3362c4 100644 --- a/exporter/awsxrayexporter/internal/translator/segment.go +++ b/exporter/awsxrayexporter/internal/translator/segment.go @@ -155,7 +155,11 @@ func MakeDependencySubsegmentForLocalRootDependencySpan(span ptrace.Span, resour } if myAwsRemoteService, ok := span.Attributes().Get(awsRemoteService); ok { - dependencySubsegment.Name = awsxray.String(myAwsRemoteService.Str()) + subsegmentName := myAwsRemoteService.Str() + if isAwsSdkSpan(span) && strings.HasPrefix(subsegmentName, "AWS.SDK.") { + subsegmentName = strings.TrimPrefix(subsegmentName, "AWS.SDK.") + } + dependencySubsegment.Name = awsxray.String(subsegmentName) } return dependencySubsegment, err 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() From c5e9a7c393e55eb52b5c7252283e263d63892e01 Mon Sep 17 00:00:00 2001 From: John Knollmeyer Date: Thu, 19 Oct 2023 14:21:50 -0700 Subject: [PATCH 2/2] De-duplicate identical logic --- .../internal/translator/segment.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/exporter/awsxrayexporter/internal/translator/segment.go b/exporter/awsxrayexporter/internal/translator/segment.go index 5fc66a3362c4..0ff0199016e3 100644 --- a/exporter/awsxrayexporter/internal/translator/segment.go +++ b/exporter/awsxrayexporter/internal/translator/segment.go @@ -156,10 +156,7 @@ func MakeDependencySubsegmentForLocalRootDependencySpan(span ptrace.Span, resour if myAwsRemoteService, ok := span.Attributes().Get(awsRemoteService); ok { subsegmentName := myAwsRemoteService.Str() - if isAwsSdkSpan(span) && strings.HasPrefix(subsegmentName, "AWS.SDK.") { - subsegmentName = strings.TrimPrefix(subsegmentName, "AWS.SDK.") - } - dependencySubsegment.Name = awsxray.String(subsegmentName) + dependencySubsegment.Name = awsxray.String(trimAwsSdkPrefix(subsegmentName, span)) } return dependencySubsegment, err @@ -374,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) } } @@ -756,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 +}