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

Add logic for stripping the AWS.SDK prefix for Local Root spans #127

Merged
merged 2 commits into from
Oct 20, 2023
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/strip-aws-sdk-local-root.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: 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]
14 changes: 10 additions & 4 deletions exporter/awsxrayexporter/internal/translator/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ func MakeDependencySubsegmentForLocalRootDependencySpan(span ptrace.Span, resour
}

if myAwsRemoteService, ok := span.Attributes().Get(awsRemoteService); ok {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking: Would have been good to break this out into a helper to reduce code duplication.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated with de-duped logic

dependencySubsegment.Name = awsxray.String(myAwsRemoteService.Str())
subsegmentName := myAwsRemoteService.Str()
dependencySubsegment.Name = awsxray.String(trimAwsSdkPrefix(subsegmentName, span))
}

return dependencySubsegment, err
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
}
33 changes: 33 additions & 0 deletions exporter/awsxrayexporter/internal/translator/segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading