Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Microsoft.Extensions.AI;

/// <summary>Represents a delegating chat client that implements the OpenTelemetry Semantic Conventions for Generative AI systems.</summary>
/// <remarks>
/// 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/" />.
/// 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/" />.
/// The specification is still experimental and subject to change; as such, the telemetry output by this client is also subject to change.
/// </remarks>
public sealed partial class OpenTelemetryChatClient : DelegatingChatClient
Expand Down Expand Up @@ -279,20 +279,21 @@ public override async IAsyncEnumerable<ChatResponseUpdate> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.Extensions.AI;

/// <summary>Represents a delegating embedding generator that implements the OpenTelemetry Semantic Conventions for Generative AI systems.</summary>
/// <remarks>
/// 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/" />.
/// 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/" />.
/// The specification is still experimental and subject to change; as such, the telemetry output by this client is also subject to change.
/// </remarks>
/// <typeparam name="TInput">The type of input used to produce embeddings.</typeparam>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Loading