From 012a012c3581b1d6e0eb713e6050a9404fcae4a1 Mon Sep 17 00:00:00 2001 From: Mohamed Asaker Date: Wed, 15 Jan 2025 01:11:20 -0800 Subject: [PATCH] update LlmProcessor for AOT --- .../Implementation/AWSLlmModelProcessor.cs | 8 +------- .../Implementation/AWSTracingPipelineHandler.cs | 5 +++-- .../OpenTelemetry.Instrumentation.AWS.csproj | 1 + 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSLlmModelProcessor.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSLlmModelProcessor.cs index a8f932f919..302951fda6 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSLlmModelProcessor.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSLlmModelProcessor.cs @@ -18,7 +18,7 @@ internal class AWSLlmModelProcessor "Specify StringComparison for clarity", "CA1307", Justification = "Adding StringComparison only works for NET Core but not the framework.")] - internal static void ProcessGenAiAttributes<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]T>(Activity activity, T message, string modelName, bool isRequest, AWSSemanticConventions awsSemanticConventions) + internal static void ProcessGenAiAttributes<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(Activity activity, T message, string modelName, bool isRequest, AWSSemanticConventions awsSemanticConventions) #else internal static void ProcessGenAiAttributes(Activity activity, T message, string modelName, bool isRequest, AWSSemanticConventions awsSemanticConventions) #endif @@ -31,12 +31,6 @@ internal static void ProcessGenAiAttributes(Activity activity, T message, str // the response body. For the Claude, Command, and Mistral models, the input and output tokens are not provided // in the response body, so we approximate their values by dividing the input and output lengths by 6, based on // the Bedrock documentation here: https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html - - if (message is null) - { - return; - } - var messageBodyProperty = typeof(T).GetProperty("Body"); if (messageBodyProperty != null) { diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs index 6cbb1330c0..a7c471f774 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 using System.Diagnostics; +using Amazon.BedrockRuntime.Model; using Amazon.Runtime; using Amazon.Runtime.Internal; using Amazon.Runtime.Telemetry; @@ -138,7 +139,7 @@ private void AddResponseSpecificInformation(Activity activity, IExecutionContext var modelString = model.ToString(); if (modelString != null) { - AWSLlmModelProcessor.ProcessGenAiAttributes(activity, responseContext.Response, modelString, false, this.awsSemanticConventions); + AWSLlmModelProcessor.ProcessGenAiAttributes(activity, (InvokeModelResponse)responseContext.Response, modelString, false, this.awsSemanticConventions); } } } @@ -183,7 +184,7 @@ private void AddRequestSpecificInformation(Activity activity, IRequestContext re var modelString = model.ToString(); if (modelString != null) { - AWSLlmModelProcessor.ProcessGenAiAttributes(activity, request, modelString, true, this.awsSemanticConventions); + AWSLlmModelProcessor.ProcessGenAiAttributes(activity, (InvokeModelRequest)request, modelString, true, this.awsSemanticConventions); } } } diff --git a/src/OpenTelemetry.Instrumentation.AWS/OpenTelemetry.Instrumentation.AWS.csproj b/src/OpenTelemetry.Instrumentation.AWS/OpenTelemetry.Instrumentation.AWS.csproj index 0af00cbdc4..768b1fdcc9 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/OpenTelemetry.Instrumentation.AWS.csproj +++ b/src/OpenTelemetry.Instrumentation.AWS/OpenTelemetry.Instrumentation.AWS.csproj @@ -23,6 +23,7 @@ +