-
Notifications
You must be signed in to change notification settings - Fork 964
AWS SDK v2 -> OpenTelemetry metrics bridge #13831
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
base: main
Are you sure you want to change the base?
Conversation
- Added missing AWS SDK metric dependencies to test configuration - Fixed Javadoc, static method, and error-prone warnings in main and test sources - Replaced wildcard and unused imports in test code - Ensured all tests in OpenTelemetryMetricPublisherTest pass successfully
22b0fa9
to
41e5e3e
Compare
- Move metric publisher classes from internal to metrics package - Create dedicated test suite for metric publisher tests - Remove AWS SDK metric dependencies from main test scope - Add AWS SDK metric dependencies specifically to metric publisher test suite - Add the main source set as dependency to metric publisher test suite
9023b71
to
7942f2b
Compare
@breedx-splk , @trask - sorry for the mention, but may I request a code review? |
.build(); | ||
|
||
// For metrics (can be used independently of tracing) | ||
MetricPublisher metricPublisher = new OpenTelemetryMetricPublisher(openTelemetry); |
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.
did you consider building the metric publisher through AwsSdkTelemetry
?
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.
I thought about it, and it seems the AwsSdkTelemetry
is more focused on tracing and propagation.
It could be as simple as the attached patch.
The main pros are the unified access point, but the con is that a person who only requires metrics will have to initiate an AwsSdkTelemetry
via the builder, which contains many irrelevant fields.
Subject: Metrics in `AwsSdkTelemetry`
---
Index: instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkTelemetry.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkTelemetry.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkTelemetry.java
--- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkTelemetry.java (revision 542fdbf96ace578a0f4eb74a497b66a180adf069)
+++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkTelemetry.java (date 1746692159838)
@@ -6,6 +6,7 @@
package io.opentelemetry.instrumentation.awssdk.v2_2;
import io.opentelemetry.api.OpenTelemetry;
+import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.logs.Logger;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
@@ -16,12 +17,15 @@
import io.opentelemetry.instrumentation.awssdk.v2_2.internal.SqsProcessRequest;
import io.opentelemetry.instrumentation.awssdk.v2_2.internal.SqsReceiveRequest;
import io.opentelemetry.instrumentation.awssdk.v2_2.internal.TracingExecutionInterceptor;
+import io.opentelemetry.instrumentation.awssdk.v2_2.metrics.OpenTelemetryMetricPublisher;
import io.opentelemetry.javaagent.tooling.muzzle.NoMuzzle;
import java.util.List;
+import java.util.concurrent.Executor;
import javax.annotation.Nullable;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
+import software.amazon.awssdk.metrics.MetricPublisher;
import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeAsyncClient;
import software.amazon.awssdk.services.sqs.SqsAsyncClient;
import software.amazon.awssdk.services.sqs.SqsClient;
@@ -61,6 +65,7 @@
return new AwsSdkTelemetryBuilder(openTelemetry);
}
+ private final OpenTelemetry openTelemetry;
private final Instrumenter<ExecutionAttributes, Response> requestInstrumenter;
private final Instrumenter<SqsReceiveRequest, Response> consumerReceiveInstrumenter;
private final Instrumenter<SqsProcessRequest, Response> consumerProcessInstrumenter;
@@ -96,6 +101,7 @@
messagingReceiveInstrumentationEnabled,
useXrayPropagator);
+ this.openTelemetry = openTelemetry;
this.requestInstrumenter = instrumenterFactory.requestInstrumenter();
this.consumerReceiveInstrumenter = instrumenterFactory.consumerReceiveInstrumenter();
this.consumerProcessInstrumenter = instrumenterFactory.consumerProcessInstrumenter();
@@ -154,4 +160,20 @@
BedrockRuntimeAsyncClient bedrockClient) {
return BedrockRuntimeImpl.wrap(bedrockClient, eventLogger, genAiCaptureMessageContent);
}
+
+ public MetricPublisher createMetricPublisher() {
+ return new OpenTelemetryMetricPublisher(openTelemetry);
+ }
+
+ public MetricPublisher createMetricPublisher(String metricPrefix) {
+ return new OpenTelemetryMetricPublisher(openTelemetry, metricPrefix);
+ }
+
+ public MetricPublisher createMetricPublisher(String metricPrefix, Executor executor) {
+ return new OpenTelemetryMetricPublisher(openTelemetry, metricPrefix, executor);
+ }
+
+ public MetricPublisher createMetricPublisher(String metricPrefix, Executor executor, Attributes baseAttributes) {
+ return new OpenTelemetryMetricPublisher(openTelemetry, metricPrefix, executor, baseAttributes);
+ }
}
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.
Personally, I don't like these additions to the AwsSdkTelemetry
. They muddy that class and force some odd fields into its builder that are unrelated to its traces aspect.
Example: the Executor executor
and Attributesn't baseAttributes
are used by the metrics but not by the traces.
@laurit, what do you think?
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.
My understanding it that the intention was that end users will interact Telemetry
classes to apply the manual instrumentation libraries. If you disagree with that approach you are welcome to raise this at the SIG meeting. Java SIG meeting is on Thursday, you can find the time in the OTEL community calendar. @open-telemetry/java-instrumentation-approvers do you have any suggestions?
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.
I don't disagree with that approach, it makes plenty of sense from the end-user perspective.
I'll need to refactor the AwsSdkTelemetry
class and expand the scope of this PR to address that, though.
Let me think if I can find a clean approach here.
Any specific suggestions are welcome :)
AWS SDK v2 -> OpenTelemetry metrics bridge
This PR adds an
OpenTelemetryMetricPublisher
that implementssoftware.amazon.awssdk.metrics.MetricPublisher
and converts the internal AWS SDK v2 metric stream into OpenTelemetry instruments.Why?
Metrics such as ApiCallDuration, RetryCount, or HttpStatusCode (see the official metric list) are available inside the SDK but cannot be exported to OTel without custom plumbing.
Key features
MetricSpec
maps every AWS metric to the correct OpenTelemetry instrument type (histograms, mostly) with unit, description, and attribute set.aws.sdk
by default), executor for asynchronous publishing, and optional static attributes such asenv
,tenant
, and more.ClientOverrideConfiguration
, with no agent flag required.Usage
Optional customization:
Open questions (these should be cleared by the maintainers):
Closes #12259.