Skip to content

Commit

Permalink
Add logic for stripping the AWS.SDK prefix for Local Root spans (#127)
Browse files Browse the repository at this point in the history
* Add logic for stripping the AWS.SDK prefix for Local Root spans

- Previous change to strip the prefix in other cases open-telemetry@7c037ad

* De-duplicate identical logic
  • Loading branch information
jknollmeyer authored Oct 20, 2023
1 parent a8ff477 commit 8bdf732
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
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 {
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

0 comments on commit 8bdf732

Please sign in to comment.