- Notifications
You must be signed in to change notification settings - Fork 327
Capture S3 bucket+key as otel attributes #3136
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
Merged
SylvainJuge merged 12 commits into elastic:main from SylvainJuge:s3-bucket-otel-attributes May 5, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits Select commit Hold shift + click to select a range
769ff80 refactor tests a bit with common span assertions
SylvainJuge fa1d7c4 enhance ability to provide otel attributes
SylvainJuge 4b43892 implement s3 otel attributes for sdk v1
SylvainJuge 298766f implement s3 for sdk v2 + improve tests
SylvainJuge e0d4b8a migrate dynamodb tests
SylvainJuge 4b175f7 migrate sqs tests
SylvainJuge 2a5fcd8 remove old test methods
SylvainJuge c1e7118 remove todo for not-normalized SQS action name
SylvainJuge 76efee6 Merge branch 'main' of github.com:elastic/apm-agent-java into s3-buck…
SylvainJuge e39e8c7 update changelog
SylvainJuge aaef646 remove useless duplication
SylvainJuge 736b81c fix compilation error
SylvainJuge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -19,7 +19,6 @@ | |
| package co.elastic.apm.agent.awssdk.v1; | ||
| | ||
| import co.elastic.apm.agent.awssdk.common.AbstractAwsClientIT; | ||
| import co.elastic.apm.agent.impl.transaction.AbstractSpan; | ||
| import co.elastic.apm.agent.impl.transaction.Span; | ||
| import co.elastic.apm.agent.impl.transaction.Transaction; | ||
| import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
| | @@ -75,40 +74,63 @@ public void setupClient() { | |
| public void testDynamoDbClient() { | ||
| Transaction transaction = startTestRootTransaction("s3-test"); | ||
| | ||
| executeTest("CreateTable", "query", TABLE_NAME, () -> dynamoDB.createTable(new CreateTableRequest().withTableName(TABLE_NAME) | ||
| .withAttributeDefinitions(List.of( | ||
| new AttributeDefinition("attributeOne", ScalarAttributeType.S), | ||
| new AttributeDefinition("attributeTwo", ScalarAttributeType.N) | ||
| )) | ||
| .withKeySchema(List.of( | ||
| new KeySchemaElement("attributeOne", KeyType.HASH), | ||
| new KeySchemaElement("attributeTwo", KeyType.RANGE) | ||
| )) | ||
| .withBillingMode(BillingMode.PAY_PER_REQUEST)), | ||
| dbAssert); | ||
| | ||
| executeTest("ListTables", "query", null, () -> dynamoDB.listTables(), | ||
| dbAssert); | ||
| | ||
| executeTest("PutItem", "query", TABLE_NAME, () -> dynamoDB.putItem( | ||
| newTest(() -> dynamoDB.createTable(new CreateTableRequest().withTableName(TABLE_NAME) | ||
| .withAttributeDefinitions(List.of( | ||
| new AttributeDefinition("attributeOne", ScalarAttributeType.S), | ||
| new AttributeDefinition("attributeTwo", ScalarAttributeType.N) | ||
| )) | ||
| .withKeySchema(List.of( | ||
| new KeySchemaElement("attributeOne", KeyType.HASH), | ||
| new KeySchemaElement("attributeTwo", KeyType.RANGE) | ||
| )) | ||
| .withBillingMode(BillingMode.PAY_PER_REQUEST))) | ||
| .operationName("CreateTable") | ||
| .entityName(TABLE_NAME) | ||
| .action("query") | ||
| .withSpanAssertions(dbAssert) | ||
| .execute(); | ||
| Comment on lines +77 to +91 Member Author 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 reviewer] this is mostly automatic refactoring with a "test builder" that allows to combine assertions on the spans in a more declarative way. | ||
| | ||
| newTest(() -> dynamoDB.listTables()) | ||
| .operationName("ListTables") | ||
| .action("query") | ||
| .withSpanAssertions(dbAssert) | ||
| .execute(); | ||
| | ||
| newTest(() -> dynamoDB.putItem( | ||
| new PutItemRequest(TABLE_NAME, | ||
| Map.of("attributeOne", new AttributeValue("valueOne"), "attributeTwo", new AttributeValue().withN("10")))), | ||
| dbAssert); | ||
| | ||
| executeTest("Query", "query", TABLE_NAME, () -> dynamoDB.query( | ||
| Map.of("attributeOne", new AttributeValue("valueOne"), "attributeTwo", new AttributeValue().withN("10"))))) | ||
| .operationName("PutItem") | ||
| .entityName(TABLE_NAME) | ||
| .action("query") | ||
| .withSpanAssertions(dbAssert) | ||
| .execute(); | ||
| | ||
| newTest(() -> dynamoDB.query( | ||
| new QueryRequest(TABLE_NAME) | ||
| .withKeyConditionExpression(KEY_CONDITION_EXPRESSION) | ||
| .withExpressionAttributeValues(Map.of(":one", new AttributeValue("valueOne")))), | ||
| dbAssert | ||
| .andThen(span -> assertThat(span.getContext().getDb()).hasStatement(KEY_CONDITION_EXPRESSION))); | ||
| | ||
| executeTest("DeleteTable", "query", TABLE_NAME, () -> dynamoDB.deleteTable(TABLE_NAME), | ||
| dbAssert); | ||
| | ||
| executeTestWithException(ResourceNotFoundException.class, "PutItem", "query", TABLE_NAME + "-exception", () -> dynamoDB.putItem( | ||
| .withExpressionAttributeValues(Map.of(":one", new AttributeValue("valueOne"))))) | ||
| .operationName("Query") | ||
| .entityName(TABLE_NAME) | ||
| .action("query") | ||
| .withSpanAssertions(dbAssert | ||
| .andThen(span -> assertThat(span.getContext().getDb()).hasStatement(KEY_CONDITION_EXPRESSION))) | ||
| .execute(); | ||
| | ||
| newTest(() -> dynamoDB.deleteTable(TABLE_NAME)) | ||
| .operationName("DeleteTable") | ||
| .entityName(TABLE_NAME) | ||
| .action("query") | ||
| .withSpanAssertions(dbAssert) | ||
| .execute(); | ||
| | ||
| newTest(() -> dynamoDB.putItem( | ||
| new PutItemRequest(TABLE_NAME + "-exception", | ||
| Map.of("attributeOne", new AttributeValue("valueOne"), "attributeTwo", new AttributeValue().withN("10")))), | ||
| dbAssert); | ||
| Map.of("attributeOne", new AttributeValue("valueOne"), "attributeTwo", new AttributeValue().withN("10"))))) | ||
| .operationName("PutItem") | ||
| .action("query") | ||
| .entityName(TABLE_NAME + "-exception") | ||
| .withSpanAssertions(dbAssert) | ||
| .executeWithException(ResourceNotFoundException.class); | ||
| | ||
| assertThat(reporter.getSpans().size()).isEqualTo(6); | ||
| | ||
| | @@ -122,41 +144,64 @@ public void testDynamoDbClient() { | |
| public void testDynamoDbClientAsync() { | ||
| Transaction transaction = startTestRootTransaction("s3-test"); | ||
| | ||
| executeTest("CreateTable", "query", TABLE_NAME, () -> dynamoDBAsync.createTableAsync(new CreateTableRequest().withTableName(TABLE_NAME) | ||
| .withAttributeDefinitions(List.of( | ||
| new AttributeDefinition("attributeOne", ScalarAttributeType.S), | ||
| new AttributeDefinition("attributeTwo", ScalarAttributeType.N) | ||
| )) | ||
| .withKeySchema(List.of( | ||
| new KeySchemaElement("attributeOne", KeyType.HASH), | ||
| new KeySchemaElement("attributeTwo", KeyType.RANGE) | ||
| )) | ||
| .withBillingMode(BillingMode.PAY_PER_REQUEST)), | ||
| dbAssert); | ||
| | ||
| executeTest("ListTables", "query", null, () -> dynamoDBAsync.listTablesAsync(), | ||
| dbAssert); | ||
| | ||
| executeTest("PutItem", "query", TABLE_NAME, () -> dynamoDBAsync.putItemAsync( | ||
| newTest(() -> dynamoDBAsync.createTableAsync(new CreateTableRequest().withTableName(TABLE_NAME) | ||
| .withAttributeDefinitions(List.of( | ||
| new AttributeDefinition("attributeOne", ScalarAttributeType.S), | ||
| new AttributeDefinition("attributeTwo", ScalarAttributeType.N) | ||
| )) | ||
| .withKeySchema(List.of( | ||
| new KeySchemaElement("attributeOne", KeyType.HASH), | ||
| new KeySchemaElement("attributeTwo", KeyType.RANGE) | ||
| )) | ||
| .withBillingMode(BillingMode.PAY_PER_REQUEST))) | ||
| .operationName("CreateTable") | ||
| .entityName(TABLE_NAME) | ||
| .action("query") | ||
| .withSpanAssertions(dbAssert) | ||
| .async() | ||
| .execute(); | ||
| | ||
| newTest(() -> dynamoDBAsync.listTablesAsync()) | ||
| .operationName("ListTables") | ||
| .action("query") | ||
| .withSpanAssertions(dbAssert) | ||
| .async() | ||
| .execute(); | ||
| | ||
| newTest(() -> dynamoDBAsync.putItemAsync( | ||
| new PutItemRequest(TABLE_NAME, | ||
| Map.of("attributeOne", new AttributeValue("valueOne"), "attributeTwo", new AttributeValue().withN("10")))), | ||
| dbAssert); | ||
| | ||
| executeTest("Query", "query", TABLE_NAME, () -> dynamoDBAsync.queryAsync( | ||
| Map.of("attributeOne", new AttributeValue("valueOne"), "attributeTwo", new AttributeValue().withN("10"))))) | ||
| .operationName("PutItem") | ||
| .entityName(TABLE_NAME) | ||
| .action("query") | ||
| .withSpanAssertions(dbAssert) | ||
| .async() | ||
| .execute(); | ||
| | ||
| newTest(() -> dynamoDBAsync.queryAsync( | ||
| new QueryRequest(TABLE_NAME) | ||
| .withKeyConditionExpression(KEY_CONDITION_EXPRESSION) | ||
| .withExpressionAttributeValues(Map.of(":one", new AttributeValue("valueOne")))), | ||
| dbAssert | ||
| .andThen(span -> assertThat(span.getContext().getDb()).hasStatement(KEY_CONDITION_EXPRESSION))); | ||
| | ||
| executeTest("DeleteTable", "query", TABLE_NAME, () -> dynamoDBAsync.deleteTableAsync(TABLE_NAME), | ||
| dbAssert); | ||
| .withExpressionAttributeValues(Map.of(":one", new AttributeValue("valueOne"))))) | ||
| .operationName("Query") | ||
| .entityName(TABLE_NAME) | ||
| .action("query") | ||
| .withSpanAssertions(dbAssert | ||
| .andThen(span -> | ||
| assertThat(span.getContext().getDb()).hasStatement(KEY_CONDITION_EXPRESSION))) | ||
| .async() | ||
| .execute(); | ||
| | ||
| newTest(() -> dynamoDBAsync.deleteTableAsync(TABLE_NAME)) | ||
| .operationName("DeleteTable") | ||
| .entityName(TABLE_NAME) | ||
| .action("query") | ||
| .withSpanAssertions(dbAssert) | ||
| .async() | ||
| .execute(); | ||
| | ||
| assertThat(reporter.getSpans().size()).isEqualTo(5); | ||
| | ||
| transaction.deactivate().end(); | ||
| | ||
| assertThat(reporter.getSpans()).noneMatch(AbstractSpan::isSync); | ||
| } | ||
| | ||
| @Override | ||
| | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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.
[for reviewer] with SDK v1 we have to use some manual parsing of an HTTP header, this is not the case with v2.