-
Couldn't load subscription status.
- Fork 1k
Added dynamodb instrumenter for aws v1_11 sdk #12756
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
Changes from 9 commits
fceec97
647d433
fd2f694
9857868
3c0acac
70daf4e
61c014c
1b0a198
09e823a
d2b7fed
b86f2de
1a93d0d
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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.awssdk.v1_11; | ||
|
|
||
| import com.amazonaws.Request; | ||
| import com.amazonaws.Response; | ||
| import io.opentelemetry.api.common.AttributeKey; | ||
| import io.opentelemetry.api.common.AttributesBuilder; | ||
| import io.opentelemetry.context.Context; | ||
| import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; | ||
| import io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| public class DynamoDbAttributesExtractor implements AttributesExtractor<Request<?>, Response<?>> { | ||
|
|
||
| private static final AttributeKey<String> DB_SYSTEM = AttributeKey.stringKey("db.system"); | ||
| private static final AttributeKey<List<String>> AWS_TABLE_NAMES = | ||
akats7 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| AttributeKey.stringArrayKey("aws.dynamodb.table_names"); | ||
|
|
||
| private static final String DYNAMODB = "dynamodb"; | ||
|
|
||
| @Override | ||
| public void onStart(AttributesBuilder attributes, Context parentContext, Request<?> request) { | ||
| AttributesExtractorUtil.internalSet(attributes, DB_SYSTEM, DYNAMODB); | ||
| String tableName = RequestAccess.getTableName(request.getOriginalRequest()); | ||
| AttributesExtractorUtil.internalSet( | ||
| attributes, AWS_TABLE_NAMES, Collections.singletonList(tableName)); | ||
| } | ||
|
|
||
| @Override | ||
| public void onEnd( | ||
| AttributesBuilder attributes, | ||
| Context context, | ||
| Request<?> request, | ||
| @Nullable Response<?> response, | ||
| @Nullable Throwable error) {} | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,21 +31,27 @@ final class TracingRequestHandler extends RequestHandler2 { | |||||||||||||
| ContextKey.named(TracingRequestHandler.class.getName() + ".Timer"); | ||||||||||||||
| private static final ContextKey<Boolean> REQUEST_SPAN_SUPPRESSED_KEY = | ||||||||||||||
| ContextKey.named(TracingRequestHandler.class.getName() + ".RequestSpanSuppressed"); | ||||||||||||||
| private static final String SEND_MESSAGE_REQUEST = | ||||||||||||||
| "com.amazonaws.services.sqs.model.SendMessageRequest"; | ||||||||||||||
| private static final String DYNAMODBV2 = "com.amazonaws.services.dynamodbv2.model."; | ||||||||||||||
|
||||||||||||||
| private static final String SEND_MESSAGE_REQUEST = | |
| "com.amazonaws.services.sqs.model.SendMessageRequest"; | |
| private static final String DYNAMODBV2 = "com.amazonaws.services.dynamodbv2.model."; | |
| private static final String SEND_MESSAGE_REQUEST_CLASS = | |
| "com.amazonaws.services.sqs.model.SendMessageRequest"; | |
| private static final String DYNAMODBV2_CLASS = "com.amazonaws.services.dynamodbv2.model."; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,13 +5,20 @@ | |
|
|
||
| package io.opentelemetry.instrumentation.awssdk.v1_11; | ||
|
|
||
| import static io.opentelemetry.api.common.AttributeKey.stringArrayKey; | ||
| import static io.opentelemetry.api.common.AttributeKey.stringKey; | ||
| import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; | ||
| import static java.util.Collections.singletonList; | ||
|
|
||
| import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; | ||
| import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; | ||
| import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; | ||
| import com.google.common.collect.ImmutableMap; | ||
| 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.Arrays; | ||
| import java.util.List; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public abstract class AbstractDynamoDbClientTest extends AbstractBaseAwsClientTest { | ||
|
|
@@ -34,13 +41,14 @@ public void sendRequestWithMockedResponse() throws Exception { | |
|
|
||
| server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, "")); | ||
|
|
||
| List<AttributeAssertion> additionalAttributes = | ||
| Arrays.asList( | ||
| equalTo(stringKey("aws.table.name"), "sometable"), | ||
| equalTo(stringKey("db.system"), "dynamodb"), | ||
| equalTo(stringArrayKey("aws.dynamodb.table_names"), singletonList("sometable"))); | ||
|
||
|
|
||
| Object response = client.createTable(new CreateTableRequest("sometable", null)); | ||
| assertRequestWithMockedResponse( | ||
| response, | ||
| client, | ||
| "DynamoDBv2", | ||
| "CreateTable", | ||
| "POST", | ||
| ImmutableMap.of("aws.table.name", "sometable")); | ||
| response, client, "DynamoDBv2", "CreateTable", "POST", additionalAttributes); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.