Repository navigation
🪞 12598 - Add AWS resource ARN tags to AWS SDK client spans #12812
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
base: master
Are you sure you want to change the base?
Changes from all commits
19f47d3
c7fce10
160c048
02c935d
59b8e4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,6 +154,7 @@ protected void doOnRequest(final AgentSpan span, final Request request) { | |
| String topicName = null; | ||
| String topicArn = access.getTopicArn(originalRequest); | ||
| if (null != topicArn) { | ||
| span.setTag(InstrumentationTags.AWS_TOPIC_ARN, topicArn); | ||
| topicName = topicArn.substring(topicArn.lastIndexOf(':') + 1); | ||
| span.setTag(InstrumentationTags.AWS_TOPIC_NAME, topicName); | ||
| span.setTag(InstrumentationTags.TOPIC_NAME, topicName); | ||
|
|
@@ -169,6 +170,7 @@ protected void doOnRequest(final AgentSpan span, final Request request) { | |
| } | ||
| String streamArn = access.getStreamARN(originalRequest); | ||
| if (null != streamArn) { | ||
| span.setTag(InstrumentationTags.AWS_STREAM_ARN, streamArn); | ||
| int streamNameStart = streamArn.indexOf(":stream/"); | ||
| if (streamNameStart >= 0) { | ||
| streamName = streamArn.substring(streamNameStart + 8); | ||
|
|
@@ -185,6 +187,20 @@ protected void doOnRequest(final AgentSpan span, final Request request) { | |
| bestPrecursor = InstrumentationTags.AWS_TABLE_NAME; | ||
| bestPeerService = tableName; | ||
| } | ||
| String stateMachineArn = access.getStateMachineArn(originalRequest); | ||
| if (null != stateMachineArn) { | ||
| span.setTag(InstrumentationTags.AWS_STATE_MACHINE_ARN, stateMachineArn); | ||
| } | ||
| String executionArn = access.getExecutionArn(originalRequest); | ||
| if (null != executionArn) { | ||
| span.setTag(InstrumentationTags.AWS_EXECUTION_ARN, executionArn); | ||
| } | ||
| if ("AWSLambda".equalsIgnoreCase(awsServiceName)) { | ||
| String functionName = access.getFunctionName(originalRequest); | ||
| if (null != functionName) { | ||
| setFunctionIdentity(span, functionName); | ||
| } | ||
| } | ||
|
|
||
| // Set peer.service based on Config for serverless functions | ||
| if (Config.get().isAwsServerless()) { | ||
|
|
@@ -248,6 +264,39 @@ protected void doOnRequest(final AgentSpan span, final Request request) { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Normalizes a Lambda {@code FunctionName} request value. {@code aws.function.name} is always the | ||
| * bare function name (account, {@code function:} prefix and {@code :qualifier} suffix stripped), | ||
| * and {@code aws.function.arn} is set only when the value is a full ARN. A partial ARN ({@code | ||
| * account:function:name}) yields the name but no ARN, because its Region and partition are | ||
| * unknown and must not be invented. | ||
| */ | ||
| private static void setFunctionIdentity(AgentSpan span, String functionName) { | ||
| if (functionName == null || functionName.isEmpty()) { | ||
| return; | ||
| } | ||
| if (functionName.startsWith("arn:")) { | ||
| // arn:<partition>:lambda:<region>:<account>:function:<name>[:<qualifier>] | ||
| span.setTag(InstrumentationTags.AWS_FUNCTION_ARN, functionName); | ||
| } | ||
| span.setTag(InstrumentationTags.AWS_FUNCTION_NAME, lambdaFunctionName(functionName)); | ||
| } | ||
|
|
||
| /** Extracts the bare function name from any accepted {@code FunctionName} form. */ | ||
| static String lambdaFunctionName(String functionName) { | ||
| String[] parts = functionName.split(":"); | ||
| // Full ARN: arn:<partition>:lambda:<region>:<account>:function:<name>[:<qualifier>] | ||
| if (parts.length >= 7 && "arn".equals(parts[0]) && "function".equals(parts[5])) { | ||
| return parts[6]; | ||
| } | ||
| // Partial ARN: <account>:function:<name>[:<qualifier>] | ||
| if (parts.length >= 3 && "function".equals(parts[1])) { | ||
| return parts[2]; | ||
| } | ||
| // Bare name, optionally with a :alias or :version qualifier (parts[0] is the name). | ||
| return parts[0]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For a Lambda FunctionName such as ":" or "::", split(":") returns an empty array and parts[0] throws ArrayIndexOutOfBoundsException. Instead of allowing normal SDK/service validation, tracing aborts the request. In SDK v1, the exception occurs before the new span is stored in handler context, leaving it unfinished. The SDK v2 parser has the same unchecked access; guard empty split results in both implementations. React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it What each reaction means
🤖 Bits Code Review · Open Bits AI session |
||
| } | ||
|
|
||
| public void onServiceResponse( | ||
| final AgentSpan span, final String awsService, final Response response) { | ||
| if ("s3".equalsIgnoreCase(simplifyServiceName(awsService)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requests in AWS1SnsClientTest, AWS1KinesisClientTest, and SnsClientTest in both SNS instrumentation modules now emit additional ARN tags, but their unchanged expectations omit them. The default tags assertion rejects every unverified tag, so these tests fail in assertTagsAllVerified(). Update those expectations for aws.topic.arn, aws.sns.topic_arn, and aws.stream.arn, alongside the SDK v2 expectations already updated in this PR.
Was this helpful? React 👍 or 👎
🤖 Bits Code Review · Open Bits AI session
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. I updated the strict SDK v1 SNS and Kinesis DSM assertions and both SNS instrumentation-module test suites. I also reran all 17 affected minimum, latest-dependency, forked, and DSM test tasks successfully.