diff --git a/src/Libraries/Microsoft.Extensions.AI/ChatCompletion/OpenTelemetryChatClient.cs b/src/Libraries/Microsoft.Extensions.AI/ChatCompletion/OpenTelemetryChatClient.cs index b3e4f8b86bf..d9bdb479a44 100644 --- a/src/Libraries/Microsoft.Extensions.AI/ChatCompletion/OpenTelemetryChatClient.cs +++ b/src/Libraries/Microsoft.Extensions.AI/ChatCompletion/OpenTelemetryChatClient.cs @@ -23,7 +23,7 @@ namespace Microsoft.Extensions.AI; /// Represents a delegating chat client that implements the OpenTelemetry Semantic Conventions for Generative AI systems. /// -/// This class provides an implementation of the Semantic Conventions for Generative AI systems v1.30, defined at . +/// This class provides an implementation of the Semantic Conventions for Generative AI systems v1.31, defined at . /// The specification is still experimental and subject to change; as such, the telemetry output by this client is also subject to change. /// public sealed partial class OpenTelemetryChatClient : DelegatingChatClient @@ -279,20 +279,21 @@ public override async IAsyncEnumerable GetStreamingResponseA _ = activity.AddTag(OpenTelemetryConsts.GenAI.Request.TopP, top_p); } - if (_system is not null) + if (options.ResponseFormat is not null) { - if (options.ResponseFormat is not null) + switch (options.ResponseFormat) { - string responseFormat = options.ResponseFormat switch - { - ChatResponseFormatText => "text", - ChatResponseFormatJson { Schema: null } => "json_schema", - ChatResponseFormatJson => "json_object", - _ => "_OTHER", - }; - _ = activity.AddTag(OpenTelemetryConsts.GenAI.Request.PerProvider(_system, "response_format"), responseFormat); + case ChatResponseFormatText: + _ = activity.AddTag(OpenTelemetryConsts.GenAI.Output.Type, "text"); + break; + case ChatResponseFormatJson: + _ = activity.AddTag(OpenTelemetryConsts.GenAI.Output.Type, "json"); + break; } + } + if (_system is not null) + { if (options.AdditionalProperties is { } props) { // Log all additional request options as per-provider tags. This is non-normative, but it covers cases where diff --git a/src/Libraries/Microsoft.Extensions.AI/Embeddings/OpenTelemetryEmbeddingGenerator.cs b/src/Libraries/Microsoft.Extensions.AI/Embeddings/OpenTelemetryEmbeddingGenerator.cs index 26ead720a1c..cfcd032bbd2 100644 --- a/src/Libraries/Microsoft.Extensions.AI/Embeddings/OpenTelemetryEmbeddingGenerator.cs +++ b/src/Libraries/Microsoft.Extensions.AI/Embeddings/OpenTelemetryEmbeddingGenerator.cs @@ -16,7 +16,7 @@ namespace Microsoft.Extensions.AI; /// Represents a delegating embedding generator that implements the OpenTelemetry Semantic Conventions for Generative AI systems. /// -/// This class provides an implementation of the Semantic Conventions for Generative AI systems v1.30, defined at . +/// This class provides an implementation of the Semantic Conventions for Generative AI systems v1.31, defined at . /// The specification is still experimental and subject to change; as such, the telemetry output by this client is also subject to change. /// /// The type of input used to produce embeddings. diff --git a/src/Libraries/Microsoft.Extensions.AI/OpenTelemetryConsts.cs b/src/Libraries/Microsoft.Extensions.AI/OpenTelemetryConsts.cs index 031d88a140f..b585ebf3086 100644 --- a/src/Libraries/Microsoft.Extensions.AI/OpenTelemetryConsts.cs +++ b/src/Libraries/Microsoft.Extensions.AI/OpenTelemetryConsts.cs @@ -59,6 +59,11 @@ public static class Operation public const string Name = "gen_ai.operation.name"; } + public static class Output + { + public const string Type = "gen_ai.output.type"; + } + public static class Request { public const string EmbeddingDimensions = "gen_ai.request.embedding.dimensions";