-
Couldn't load subscription status.
- Fork 1k
Add support for ConverseStream to bedrock instrumentation #13410
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 2 commits
b02d108
24e9b30
be043a3
cf7b818
cbd0649
6c57d34
73fdb57
5648989
e849d2f
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,41 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.awssdk.v2_2; | ||
|
|
||
| import static net.bytebuddy.matcher.ElementMatchers.named; | ||
|
|
||
| import io.opentelemetry.instrumentation.awssdk.v2_2.autoconfigure.AwsSdkSingletons; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
| import net.bytebuddy.asm.Advice; | ||
| import net.bytebuddy.description.type.TypeDescription; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
| import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeAsyncClient; | ||
|
|
||
| public class DefaultBedrockRuntimeAsyncClientBuilderInstrumentation implements TypeInstrumentation { | ||
|
|
||
| @Override | ||
| public ElementMatcher<TypeDescription> typeMatcher() { | ||
| return named( | ||
| "software.amazon.awssdk.services.bedrockruntime.DefaultBedrockRuntimeAsyncClientBuilder"); | ||
| } | ||
|
|
||
| @Override | ||
| public void transform(TypeTransformer transformer) { | ||
| transformer.applyAdviceToMethod( | ||
| named("buildClient"), this.getClass().getName() + "$BuildClientAdvice"); | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class BuildClientAdvice { | ||
|
|
||
| @Advice.OnMethodExit(suppress = Throwable.class) | ||
| public static void methodExit( | ||
| @Advice.Return(readOnly = false) BedrockRuntimeAsyncClient client) { | ||
| client = AwsSdkSingletons.telemetry().wrapBedrockRuntimeClient(client); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,6 @@ | |
| import static io.opentelemetry.instrumentation.awssdk.v2_2.internal.TracingExecutionInterceptor.SDK_REQUEST_ATTRIBUTE; | ||
|
|
||
| import io.opentelemetry.instrumentation.api.incubator.semconv.genai.GenAiAttributesGetter; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import javax.annotation.Nullable; | ||
| import software.amazon.awssdk.core.interceptor.ExecutionAttributes; | ||
|
|
@@ -37,6 +36,8 @@ public String getOperationName(ExecutionAttributes executionAttributes) { | |
| if (operation != null) { | ||
| switch (operation) { | ||
| case "Converse": | ||
| // fallthrough | ||
| case "ConverseStream": | ||
| return GenAiOperationNameIncubatingValues.CHAT; | ||
| default: | ||
| return null; | ||
|
|
@@ -117,11 +118,11 @@ public Double getRequestTopP(ExecutionAttributes executionAttributes) { | |
| @Override | ||
| public List<String> getResponseFinishReasons( | ||
| ExecutionAttributes executionAttributes, Response response) { | ||
| String stopReason = BedrockRuntimeAccess.getStopReason(response.getSdkResponse()); | ||
| if (stopReason == null) { | ||
| List<String> stopReasons = BedrockRuntimeAccess.getStopReasons(response); | ||
| if (stopReasons == null) { | ||
| return null; | ||
|
||
| } | ||
| return Arrays.asList(stopReason); | ||
| return stopReasons; | ||
| } | ||
|
|
||
| @Nullable | ||
|
|
@@ -139,12 +140,12 @@ public String getResponseModel(ExecutionAttributes executionAttributes, Response | |
| @Nullable | ||
| @Override | ||
| public Long getUsageInputTokens(ExecutionAttributes executionAttributes, Response response) { | ||
| return BedrockRuntimeAccess.getUsageInputTokens(response.getSdkResponse()); | ||
| return BedrockRuntimeAccess.getUsageInputTokens(response); | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Long getUsageOutputTokens(ExecutionAttributes executionAttributes, Response response) { | ||
| return BedrockRuntimeAccess.getUsageOutputTokens(response.getSdkResponse()); | ||
| return BedrockRuntimeAccess.getUsageOutputTokens(response); | ||
| } | ||
| } | ||
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 couldn't use
wrapas was probably intended because all argument classes for overloads have to be on the compile classpath, which isn't the case. If the library instrumentation hasn't been marked stable yet, in a separate PR I could deprecatewrapand addwrapSqsClientif it makes sense