diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java index 4f196a39ba7d..5cbd8353b093 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkInstrumenterFactory.java @@ -103,6 +103,7 @@ private AttributesExtractor messagingAttr .build(); } + Instrumenter> consumerReceiveInstrumenter() { MessageOperation operation = MessageOperation.RECEIVE; SqsReceiveRequestAttributesGetter getter = SqsReceiveRequestAttributesGetter.INSTANCE; @@ -186,6 +187,18 @@ Instrumenter, Response> producerInstrumenter() { true); } + Instrumenter, Response> dynamoInstrumenter() { + DynamoAttributesExtractor dynamoAttributesExtractor = new DynamoAttributesExtractor(); + + return createInstrumenter( + openTelemetry, + spanName, + SpanKindExtractor.alwaysClient(), + attributesExtractors(), + singletonList(dynamoAttributesExtractor), + true); + } + private static Instrumenter createInstrumenter( OpenTelemetry openTelemetry, SpanNameExtractor spanNameExtractor, diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkTelemetry.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkTelemetry.java index a5b7df063be3..02a883d47659 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkTelemetry.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkTelemetry.java @@ -49,6 +49,7 @@ public static AwsSdkTelemetryBuilder builder(OpenTelemetry openTelemetry) { private final Instrumenter> consumerReceiveInstrumenter; private final Instrumenter> consumerProcessInstrumenter; private final Instrumenter, Response> producerInstrumenter; + private final Instrumenter, Response> dynamoInstrumenter; AwsSdkTelemetry( OpenTelemetry openTelemetry, @@ -65,6 +66,7 @@ public static AwsSdkTelemetryBuilder builder(OpenTelemetry openTelemetry) { consumerReceiveInstrumenter = instrumenterFactory.consumerReceiveInstrumenter(); consumerProcessInstrumenter = instrumenterFactory.consumerProcessInstrumenter(); producerInstrumenter = instrumenterFactory.producerInstrumenter(); + dynamoInstrumenter = instrumenterFactory.dynamoInstrumenter(); } /** @@ -76,6 +78,7 @@ public RequestHandler2 newRequestHandler() { requestInstrumenter, consumerReceiveInstrumenter, consumerProcessInstrumenter, - producerInstrumenter); + producerInstrumenter, + dynamoInstrumenter); } } diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoAttributesExtractor.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoAttributesExtractor.java new file mode 100644 index 000000000000..51e80493b6ac --- /dev/null +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoAttributesExtractor.java @@ -0,0 +1,37 @@ +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 javax.annotation.Nullable; +import java.util.Collections; +import java.util.List; + +public class DynamoAttributesExtractor implements AttributesExtractor, Response> { + + private static final AttributeKey DB_SYSTEM = + AttributeKey.stringKey("db.system"); + private static final AttributeKey> AWS_TABLE_NAMES = + 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) {} +} diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/TracingRequestHandler.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/TracingRequestHandler.java index 1cf74e6147c5..cd47d476d6f7 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/TracingRequestHandler.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/TracingRequestHandler.java @@ -31,21 +31,26 @@ final class TracingRequestHandler extends RequestHandler2 { ContextKey.named(TracingRequestHandler.class.getName() + ".Timer"); private static final ContextKey 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 final Instrumenter, Response> requestInstrumenter; private final Instrumenter> consumerReceiveInstrumenter; private final Instrumenter> consumerProcessInstrumenter; private final Instrumenter, Response> producerInstrumenter; + private final Instrumenter, Response> dynamoInstrumenter; TracingRequestHandler( Instrumenter, Response> requestInstrumenter, Instrumenter> consumerReceiveInstrumenter, Instrumenter> consumerProcessInstrumenter, - Instrumenter, Response> producerInstrumenter) { + Instrumenter, Response> producerInstrumenter, + Instrumenter, Response> dynamoInstrumenter) { this.requestInstrumenter = requestInstrumenter; this.consumerReceiveInstrumenter = consumerReceiveInstrumenter; this.consumerProcessInstrumenter = consumerProcessInstrumenter; this.producerInstrumenter = producerInstrumenter; + this.dynamoInstrumenter = dynamoInstrumenter; } @Override @@ -53,6 +58,7 @@ public void beforeRequest(Request request) { // GeneratePresignedUrlRequest doesn't result in actual request, beforeRequest is the only // method called for it. Span created here would never be ended and scope would be leaked when // running with java agent. + System.out.println(request.getOriginalRequest().getClass().getName()); if ("com.amazonaws.services.s3.model.GeneratePresignedUrlRequest" .equals(request.getOriginalRequest().getClass().getName())) { return; @@ -151,14 +157,17 @@ private void finish(Request request, Response response, @Nullable Throwabl } return; } - instrumenter.end(context, request, response, error); } private Instrumenter, Response> getInstrumenter(Request request) { - boolean isSqsProducer = - "com.amazonaws.services.sqs.model.SendMessageRequest" - .equals(request.getOriginalRequest().getClass().getName()); - return isSqsProducer ? producerInstrumenter : requestInstrumenter; + String className = request.getOriginalRequest().getClass().getName(); + if (className.startsWith(DYNAMODBV2)) { + return dynamoInstrumenter; + } + else if (className.equals(SEND_MESSAGE_REQUEST)) { + return producerInstrumenter; + } + return requestInstrumenter; } }