-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: Add auto-instrumentation support for AWS Secrets Manager SDK v1 #14027
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
87aae70
feat: Add auto-instrumentation support for AWS Secrets Manager SDK v1
lukeina2z e13f80a
Address code review feedback:
lukeina2z 7d9d617
./gradlew spotlessApply
otelbot[bot] 5ab1706
Removed redundant null check.
lukeina2z 6fd5587
Improve dependency configuration to support testing with the latest v…
lukeina2z 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
32 changes: 32 additions & 0 deletions
32
...sManager/java/io/opentelemetry/instrumentation/awssdk/v1_11/SecretsManagerClientTest.java
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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.awssdk.v1_11; | ||
|
|
||
| import com.amazonaws.services.secretsmanager.AWSSecretsManagerClientBuilder; | ||
| import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
| import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
||
| class SecretsManagerClientTest extends AbstractSecretsManagerClientTest { | ||
| @RegisterExtension | ||
| private static final InstrumentationExtension testing = LibraryInstrumentationExtension.create(); | ||
|
|
||
| @Override | ||
| protected InstrumentationExtension testing() { | ||
| return testing; | ||
| } | ||
|
|
||
| @Override | ||
| public AWSSecretsManagerClientBuilder configureClient( | ||
| AWSSecretsManagerClientBuilder clientBuilder) { | ||
|
|
||
| return clientBuilder.withRequestHandlers( | ||
| AwsSdkTelemetry.builder(testing().getOpenTelemetry()) | ||
| .setCaptureExperimentalSpanAttributes(true) | ||
| .build() | ||
| .newRequestHandler()); | ||
| } | ||
| } |
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
93 changes: 93 additions & 0 deletions
93
.../java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSecretsManagerClientTest.java
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 |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.awssdk.v1_11; | ||
|
|
||
| import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; | ||
| import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_SECRETSMANAGER_SECRET_ARN; | ||
| import static java.util.Collections.singletonList; | ||
|
|
||
| import com.amazonaws.services.secretsmanager.AWSSecretsManager; | ||
| import com.amazonaws.services.secretsmanager.AWSSecretsManagerClientBuilder; | ||
| import com.amazonaws.services.secretsmanager.model.CreateSecretRequest; | ||
| import com.amazonaws.services.secretsmanager.model.DescribeSecretRequest; | ||
| import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; | ||
| import io.opentelemetry.testing.internal.armeria.common.HttpResponse; | ||
| import io.opentelemetry.testing.internal.armeria.common.HttpStatus; | ||
| import io.opentelemetry.testing.internal.armeria.common.MediaType; | ||
| import java.util.List; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public abstract class AbstractSecretsManagerClientTest extends AbstractBaseAwsClientTest { | ||
|
|
||
| public abstract AWSSecretsManagerClientBuilder configureClient( | ||
| AWSSecretsManagerClientBuilder client); | ||
|
|
||
| @Override | ||
| protected boolean hasRequestId() { | ||
| return false; | ||
| } | ||
|
|
||
| @Test | ||
| public void sendCreateSecretRequestWithMockedResponse() throws Exception { | ||
| AWSSecretsManagerClientBuilder clientBuilder = AWSSecretsManagerClientBuilder.standard(); | ||
| AWSSecretsManager client = | ||
| configureClient(clientBuilder) | ||
| .withEndpointConfiguration(endpoint) | ||
| .withCredentials(credentialsProvider) | ||
| .build(); | ||
|
|
||
| String body = | ||
| "{" | ||
| + "\"ARN\": \"arn:aws:secretsmanager:us-west-2:123456789012:secret:MyTestDatabaseSecret-a1b2c3\"," | ||
| + "\"Name\": \"MyTestDatabaseSecret\"," | ||
| + "\"VersionId\": \"EXAMPLE1-90ab-cdef-fedc-ba987SECRET1\"" | ||
| + "}"; | ||
| server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, body)); | ||
|
|
||
| Object response = | ||
| client.createSecret( | ||
| new CreateSecretRequest().withName("secretName").withSecretString("secretValue")); | ||
|
|
||
| List<AttributeAssertion> additionalAttributes = | ||
| singletonList( | ||
| equalTo( | ||
| AWS_SECRETSMANAGER_SECRET_ARN, | ||
| "arn:aws:secretsmanager:us-west-2:123456789012:secret:MyTestDatabaseSecret-a1b2c3")); | ||
|
|
||
| assertRequestWithMockedResponse( | ||
| response, client, "AWSSecretsManager", "CreateSecret", "POST", additionalAttributes); | ||
| } | ||
|
|
||
| @Test | ||
| public void sendDescribeSecretRequestWithMockedResponse() throws Exception { | ||
| AWSSecretsManagerClientBuilder clientBuilder = AWSSecretsManagerClientBuilder.standard(); | ||
| AWSSecretsManager client = | ||
| configureClient(clientBuilder) | ||
| .withEndpointConfiguration(endpoint) | ||
| .withCredentials(credentialsProvider) | ||
| .build(); | ||
|
|
||
| String body = | ||
| "{" | ||
| + "\"ARN\": \"arn:aws:secretsmanager:us-east-1:123456789012:secret:My-Secret-Id-WzAXar\"," | ||
| + "\"Name\": \"My-Secret-Id\"," | ||
| + "\"VersionId\": \"EXAMPLE1-90ab-cdef-fedc-ba987SECRET1\"" | ||
| + "}"; | ||
|
|
||
| server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, body)); | ||
| Object response = | ||
| client.describeSecret(new DescribeSecretRequest().withSecretId("My-Secret-Id")); | ||
|
|
||
| List<AttributeAssertion> additionalAttributes = | ||
| singletonList( | ||
| equalTo( | ||
| AWS_SECRETSMANAGER_SECRET_ARN, | ||
| "arn:aws:secretsmanager:us-east-1:123456789012:secret:My-Secret-Id-WzAXar")); | ||
|
|
||
| assertRequestWithMockedResponse( | ||
| response, client, "AWSSecretsManager", "DescribeSecret", "POST", additionalAttributes); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Perhaps there should be a null check for
awsRespso you wouldn't need to do it inRequestAccess.One thing that is confusing for me is that in case of secret manager you test
CreateSecretRequestso it is understandable that the arn is on the response. For step functions you testDescribeStateMachineRequestandDescribeActivityRequestthere in a real application shouldn't the arn already be set on the request when running these agains real aws service? I guess there is alsoCreateStateMachineRequestwhere you'd need to read the arn from the response, but aws2 version doesn't seem to handle that. It would be nice to have all paths tested and aligned between aws1 and 2 sdks.In this PR reading the secret arn from the request isn't really tested. And as far as I can tell it wouldn't work for
DescribeSecretRequestsince that one seems to usegetSecretIdinstead ofgetARN.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.
These are great feedback. Thank you @laurit.