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

added capturing s3 otel attributes from lamba S3Event #3364

Merged
merged 5 commits into from
Oct 24, 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
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Use subheadings with the "=====" level for adding notes for unreleased changes:
===== Features
* Added protection against invalid timestamps provided by manual instrumentation - {pull}3363[#3363]
* Added support for AWS SDK 2.21 - {pull}3373[#3373]
* Capture bucket and object key to Lambda transaction as OTel attributes - `aws.s3.bueckt`, `aws.s3.key` - {pull}3364[#3364]

[float]
===== Bug fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,20 @@ protected void setTransactionTriggerData(Transaction transaction, S3Event s3Even

cloudOrigin.withRegion(s3NotificationRecord.getAwsRegion());

if (null != s3NotificationRecord.getS3() && null != s3NotificationRecord.getS3().getBucket()) {
if (null != s3NotificationRecord.getS3()) {
S3EventNotification.S3BucketEntity bucket = s3NotificationRecord.getS3().getBucket();
ServiceOrigin serviceOrigin = transaction.getContext().getServiceOrigin();
serviceOrigin.withId(bucket.getArn());
serviceOrigin.withName(bucket.getName());
serviceOrigin.withVersion(s3NotificationRecord.getEventVersion());
if (null != bucket) {
ServiceOrigin serviceOrigin = transaction.getContext().getServiceOrigin();
serviceOrigin.withId(bucket.getArn());
serviceOrigin.withName(bucket.getName());
serviceOrigin.withVersion(s3NotificationRecord.getEventVersion());

transaction.withOtelAttribute("aws.s3.bucket", bucket.getName());
}
S3EventNotification.S3ObjectEntity object = s3NotificationRecord.getS3().getObject();
if (null != object) {
transaction.withOtelAttribute("aws.s3.key", object.getKey());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ protected boolean supportsContextPropagation() {
private S3EventNotification.S3EventNotificationRecord createS3NotificationRecord() {
S3EventNotification.ResponseElementsEntity responseElements = new S3EventNotification.ResponseElementsEntity("xAmzId2", S3_REQUEST_ID);
S3EventNotification.S3BucketEntity bucket = new S3EventNotification.S3BucketEntity(S3_BUCKET_NAME, null, S3_BUCKET_ARN);
S3EventNotification.S3Entity s3 = new S3EventNotification.S3Entity("configId", bucket, null, "3.3");
S3EventNotification.S3ObjectEntity object = new S3EventNotification.S3ObjectEntity("b21b84d653bb07b05b1e6b33684dc11b", 1305107, "b21b84d653bb07b05b1e6b33684dc11b", "0C0F6F405D6ED209E1");
S3EventNotification.S3Entity s3 = new S3EventNotification.S3Entity("configId", bucket, object, "3.3");
return new S3EventNotification.S3EventNotificationRecord(EVENT_SOURCE_REGION, S3_EVENT_NAME, S3_EVENT_SOURCE, null,
S3_EVENT_VERSION, null, responseElements, s3, null);
}
Expand Down Expand Up @@ -102,6 +103,8 @@ public void testBasicCall() {
assertThat(faas.getId()).isEqualTo(TestContext.FUNCTION_ARN);
assertThat(faas.getTrigger().getType()).isEqualTo("datasource");
assertThat(faas.getTrigger().getRequestId()).isEqualTo(S3_REQUEST_ID);

verifyOtelAttributes(transaction);
}

@Test
Expand Down Expand Up @@ -174,4 +177,12 @@ private void validateResultsForUnspecifiedRecord() {
assertThat(faas.getTrigger().getType()).isEqualTo("datasource");
assertThat(faas.getTrigger().getRequestId()).isNull();
}

private void verifyOtelAttributes(Transaction transaction) {
Object s3keyAttribute = transaction.getOtelAttributes().get("aws.s3.key");
assertThat(s3keyAttribute).isInstanceOf(String.class).isEqualTo("b21b84d653bb07b05b1e6b33684dc11b");

Object s3bucketAttribute = transaction.getOtelAttributes().get("aws.s3.bucket");
assertThat(s3bucketAttribute).isInstanceOf(String.class).isEqualTo(S3_BUCKET_NAME);
}
}
Loading