Skip to content

Commit a7bbcd8

Browse files
authored
Update OpenTelemetryChatClient/EmbeddingGenerator to v1.31 of genai standard convention (#6073)
1 parent 8216ce1 commit a7bbcd8

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/Libraries/Microsoft.Extensions.AI/ChatCompletion/OpenTelemetryChatClient.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Microsoft.Extensions.AI;
2323

2424
/// <summary>Represents a delegating chat client that implements the OpenTelemetry Semantic Conventions for Generative AI systems.</summary>
2525
/// <remarks>
26-
/// This class provides an implementation of the Semantic Conventions for Generative AI systems v1.30, defined at <see href="https://opentelemetry.io/docs/specs/semconv/gen-ai/" />.
26+
/// This class provides an implementation of the Semantic Conventions for Generative AI systems v1.31, defined at <see href="https://opentelemetry.io/docs/specs/semconv/gen-ai/" />.
2727
/// The specification is still experimental and subject to change; as such, the telemetry output by this client is also subject to change.
2828
/// </remarks>
2929
public sealed partial class OpenTelemetryChatClient : DelegatingChatClient
@@ -279,20 +279,21 @@ public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseA
279279
_ = activity.AddTag(OpenTelemetryConsts.GenAI.Request.TopP, top_p);
280280
}
281281

282-
if (_system is not null)
282+
if (options.ResponseFormat is not null)
283283
{
284-
if (options.ResponseFormat is not null)
284+
switch (options.ResponseFormat)
285285
{
286-
string responseFormat = options.ResponseFormat switch
287-
{
288-
ChatResponseFormatText => "text",
289-
ChatResponseFormatJson { Schema: null } => "json_schema",
290-
ChatResponseFormatJson => "json_object",
291-
_ => "_OTHER",
292-
};
293-
_ = activity.AddTag(OpenTelemetryConsts.GenAI.Request.PerProvider(_system, "response_format"), responseFormat);
286+
case ChatResponseFormatText:
287+
_ = activity.AddTag(OpenTelemetryConsts.GenAI.Output.Type, "text");
288+
break;
289+
case ChatResponseFormatJson:
290+
_ = activity.AddTag(OpenTelemetryConsts.GenAI.Output.Type, "json");
291+
break;
294292
}
293+
}
295294

295+
if (_system is not null)
296+
{
296297
if (options.AdditionalProperties is { } props)
297298
{
298299
// Log all additional request options as per-provider tags. This is non-normative, but it covers cases where

src/Libraries/Microsoft.Extensions.AI/Embeddings/OpenTelemetryEmbeddingGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Microsoft.Extensions.AI;
1616

1717
/// <summary>Represents a delegating embedding generator that implements the OpenTelemetry Semantic Conventions for Generative AI systems.</summary>
1818
/// <remarks>
19-
/// This class provides an implementation of the Semantic Conventions for Generative AI systems v1.30, defined at <see href="https://opentelemetry.io/docs/specs/semconv/gen-ai/" />.
19+
/// This class provides an implementation of the Semantic Conventions for Generative AI systems v1.31, defined at <see href="https://opentelemetry.io/docs/specs/semconv/gen-ai/" />.
2020
/// The specification is still experimental and subject to change; as such, the telemetry output by this client is also subject to change.
2121
/// </remarks>
2222
/// <typeparam name="TInput">The type of input used to produce embeddings.</typeparam>

src/Libraries/Microsoft.Extensions.AI/OpenTelemetryConsts.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public static class Operation
5959
public const string Name = "gen_ai.operation.name";
6060
}
6161

62+
public static class Output
63+
{
64+
public const string Type = "gen_ai.output.type";
65+
}
66+
6267
public static class Request
6368
{
6469
public const string EmbeddingDimensions = "gen_ai.request.embedding.dimensions";

0 commit comments

Comments
 (0)