Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix name of genai input/output tokens tag#6494

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
stephentoub merged 1 commit intodotnet:mainfromstephentoub:fixusagename
Jun 7, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -422,12 +422,12 @@ private static void AddUsageTags(Activity? activity, UsageDetails? usage)
{
if (usage.InputTokenCount is long inputTokens)
{
_ = activity.AddTag(OpenTelemetryConsts.GenAI.Response.InputTokens, (int)inputTokens);
_ = activity.AddTag(OpenTelemetryConsts.GenAI.Usage.InputTokens, (int)inputTokens);
}

if (usage.OutputTokenCount is long outputTokens)
{
_ = activity.AddTag(OpenTelemetryConsts.GenAI.Response.OutputTokens, (int)outputTokens);
_ = activity.AddTag(OpenTelemetryConsts.GenAI.Usage.OutputTokens, (int)outputTokens);
}
}
}
Expand DownExpand Up@@ -795,7 +795,7 @@ FunctionResultContent CreateFunctionResultContent(FunctionInvocationResult resul
_ = Throw.IfNull(context);

using Activity? activity = _activitySource?.StartActivity(
$"execute_tool {context.Function.Name}",
$"{OpenTelemetryConsts.GenAI.ExecuteTool} {context.Function.Name}",
ActivityKind.Internal,
default(ActivityContext),
[
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -400,12 +400,12 @@ private void TraceResponse(

if (response.Usage?.InputTokenCount is long inputTokens)
{
_ = activity.AddTag(OpenTelemetryConsts.GenAI.Response.InputTokens, (int)inputTokens);
_ = activity.AddTag(OpenTelemetryConsts.GenAI.Usage.InputTokens, (int)inputTokens);
}

if (response.Usage?.OutputTokenCount is long outputTokens)
{
_ = activity.AddTag(OpenTelemetryConsts.GenAI.Response.OutputTokens, (int)outputTokens);
_ = activity.AddTag(OpenTelemetryConsts.GenAI.Usage.OutputTokens, (int)outputTokens);
}

if (_system is not null)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -249,7 +249,7 @@ private void TraceResponse(

if (inputTokens.HasValue)
{
_ = activity.AddTag(OpenTelemetryConsts.GenAI.Response.InputTokens, inputTokens);
_ = activity.AddTag(OpenTelemetryConsts.GenAI.Usage.InputTokens, inputTokens);
}

if (responseModelId is not null)
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,6 +31,7 @@ public static class GenAI

public const string Chat = "chat";
public const string Embeddings = "embeddings";
public const string ExecuteTool = "execute_tool";

public static class Assistant
{
Expand DownExpand Up@@ -89,9 +90,7 @@ public static class Response
{
public const string FinishReasons = "gen_ai.response.finish_reasons";
public const string Id = "gen_ai.response.id";
public const string InputTokens = "gen_ai.response.input_tokens";
public const string Model = "gen_ai.response.model";
public const string OutputTokens = "gen_ai.response.output_tokens";

public static string PerProvider(string providerName, string parameterName) => $"gen_ai.{providerName}.response.{parameterName}";
}
Expand All@@ -118,6 +117,12 @@ public static class Call
}
}

public static class Usage
{
public const string InputTokens = "gen_ai.usage.input_tokens";
public const string OutputTokens = "gen_ai.usage.output_tokens";
}

public static class User
{
public const string Message = "gen_ai.user.message";
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -342,8 +342,8 @@ private static void AssertUsageAgainstActivities(ChatResponse response, List<Act
// across all consituent calls, which means our final answer will be double.
if (response.Usage is { } finalUsage)
{
var totalInputTokens = activities.Sum(a => (int?)a.GetTagItem("gen_ai.response.input_tokens")!);
var totalOutputTokens = activities.Sum(a => (int?)a.GetTagItem("gen_ai.response.output_tokens")!);
var totalInputTokens = activities.Sum(a => (int?)a.GetTagItem("gen_ai.usage.input_tokens")!);
var totalOutputTokens = activities.Sum(a => (int?)a.GetTagItem("gen_ai.usage.output_tokens")!);
Assert.Equal(totalInputTokens, finalUsage.InputTokenCount * 2);
Assert.Equal(totalOutputTokens, finalUsage.OutputTokenCount * 2);
}
Expand DownExpand Up@@ -785,8 +785,8 @@ public virtual async Task OpenTelemetry_CanEmitTracesAndMetrics()
Assert.Equal(chatClient.GetService<ChatClientMetadata>()?.ProviderUri?.Port, (int)activity.GetTagItem("server.port")!);
Assert.NotNull(activity.Id);
Assert.NotEmpty(activity.Id);
Assert.NotEqual(0, (int)activity.GetTagItem("gen_ai.response.input_tokens")!);
Assert.NotEqual(0, (int)activity.GetTagItem("gen_ai.response.output_tokens")!);
Assert.NotEqual(0, (int)activity.GetTagItem("gen_ai.usage.input_tokens")!);
Assert.NotEqual(0, (int)activity.GetTagItem("gen_ai.usage.output_tokens")!);

Assert.True(activity.Duration.TotalMilliseconds > 0);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -128,7 +128,7 @@ public virtual async Task OpenTelemetry_CanEmitTracesAndMetrics()
Assert.Equal(embeddingGenerator.GetService<EmbeddingGeneratorMetadata>()?.ProviderUri?.Port, (int)activity.GetTagItem("server.port")!);
Assert.NotNull(activity.Id);
Assert.NotEmpty(activity.Id);
Assert.NotEqual(0, (int)activity.GetTagItem("gen_ai.response.input_tokens")!);
Assert.NotEqual(0, (int)activity.GetTagItem("gen_ai.usage.input_tokens")!);

Assert.True(activity.Duration.TotalMilliseconds > 0);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -171,8 +171,8 @@ async static IAsyncEnumerable<ChatResponseUpdate> CallbackAsync(

Assert.Equal("id123", activity.GetTagItem("gen_ai.response.id"));
Assert.Equal("""["stop"]""", activity.GetTagItem("gen_ai.response.finish_reasons"));
Assert.Equal(10, activity.GetTagItem("gen_ai.response.input_tokens"));
Assert.Equal(20, activity.GetTagItem("gen_ai.response.output_tokens"));
Assert.Equal(10, activity.GetTagItem("gen_ai.usage.input_tokens"));
Assert.Equal(20, activity.GetTagItem("gen_ai.usage.output_tokens"));
Assert.Equal(enableSensitiveData ? "abcdefgh" : null, activity.GetTagItem("gen_ai.testservice.response.system_fingerprint"));
Assert.Equal(enableSensitiveData ? "value2" : null, activity.GetTagItem("gen_ai.testservice.response.and_something_else"));

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,7 +89,7 @@ public async Task ExpectedInformationLogged_Async(string? perRequestModelId, boo
Assert.Equal(enableSensitiveData ? "value1" : null, activity.GetTagItem("gen_ai.testservice.request.service_tier"));
Assert.Equal(enableSensitiveData ? "value2" : null, activity.GetTagItem("gen_ai.testservice.request.something_else"));

Assert.Equal(10, activity.GetTagItem("gen_ai.response.input_tokens"));
Assert.Equal(10, activity.GetTagItem("gen_ai.usage.input_tokens"));
Assert.Equal(enableSensitiveData ? "abcdefgh" : null, activity.GetTagItem("gen_ai.testservice.response.system_fingerprint"));
Assert.Equal(enableSensitiveData ? "value3" : null, activity.GetTagItem("gen_ai.testservice.response.and_something_else"));

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp