Skip to content

Commit

Permalink
add db client metrics for dynamo db (#13033)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger authored Jan 15, 2025
1 parent 4d2ea25 commit 44bea8d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ tasks {
}
}

val testStableSemconv by registering(Test::class) {
jvmArgs("-Dotel.semconv-stability.opt-in=database")
}

check {
dependsOn(testStableSemconv)
}

test {
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service)
}
Expand Down
10 changes: 10 additions & 0 deletions instrumentation/aws-sdk/aws-sdk-1.11/library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ if (!(findProperty("testLatestDeps") as Boolean)) {
}
}
}

tasks {
val testStableSemconv by registering(Test::class) {
jvmArgs("-Dotel.semconv-stability.opt-in=database")
}

check {
dependsOn(testStableSemconv)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientMetrics;
import io.opentelemetry.instrumentation.api.incubator.semconv.messaging.MessageOperation;
import io.opentelemetry.instrumentation.api.incubator.semconv.messaging.MessagingAttributesExtractor;
import io.opentelemetry.instrumentation.api.incubator.semconv.messaging.MessagingAttributesGetter;
Expand All @@ -27,6 +28,7 @@
import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -189,13 +191,12 @@ Instrumenter<Request<?>, Response<?>> producerInstrumenter() {
Instrumenter<Request<?>, Response<?>> dynamoDbInstrumenter() {
DynamoDbAttributesExtractor dynamoDbAttributesExtractor = new DynamoDbAttributesExtractor();

return createInstrumenter(
openTelemetry,
spanName,
SpanKindExtractor.alwaysClient(),
attributesExtractors(),
singletonList(dynamoDbAttributesExtractor),
true);
return Instrumenter.<Request<?>, Response<?>>builder(
openTelemetry, INSTRUMENTATION_NAME, spanName)
.addAttributesExtractors(attributesExtractors())
.addAttributesExtractors(Collections.singletonList(dynamoDbAttributesExtractor))
.addOperationMetrics(DbClientMetrics.get())
.buildInstrumenter(SpanKindExtractor.alwaysClient());
}

private static <REQUEST, RESPONSE> Instrumenter<REQUEST, RESPONSE> createInstrumenter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
package io.opentelemetry.instrumentation.awssdk.v1_11;

import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.instrumentation.testing.junit.db.DbClientMetricsTestUtil.assertDurationMetric;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_DYNAMODB_TABLE_NAMES;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DbSystemIncubatingValues.DYNAMODB;
Expand Down Expand Up @@ -52,5 +55,8 @@ public void sendRequestWithMockedResponse() throws Exception {
Object response = client.createTable(new CreateTableRequest("sometable", null));
assertRequestWithMockedResponse(
response, client, "DynamoDBv2", "CreateTable", "POST", additionalAttributes);

assertDurationMetric(
testing(), "io.opentelemetry.aws-sdk-1.11", DB_SYSTEM, SERVER_ADDRESS, SERVER_PORT);
}
}

0 comments on commit 44bea8d

Please sign in to comment.