Skip to content

GenAiTokenUsageTags

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework.Diagnostics

GenAiTokenUsageTags Struct

Strongly-typed bag of optional tags attached to a RecordTokenUsage(string, long, GenAiTokenUsageTags) measurement. Mirrors the tag schema written by MEAI's Microsoft.Extensions.AI.OpenTelemetryChatClient on the same gen_ai.client.token.usage histogram so the resulting series share a label set and aggregate cleanly under a single OpenTelemetry MetricStreamIdentity.

public readonly record struct GenAiTokenUsageTags : System.IEquatable<NexusLabs.Needlr.AgentFramework.Diagnostics.GenAiTokenUsageTags>

Implements System.IEquatable<GenAiTokenUsageTags>

Remarks

Any property whose value is null is omitted from the recorded measurement. This matches MEAI's behaviour, where MEAI also omits tags whose source data is unavailable.

ServerPort SHOULD be supplied whenever ServerAddress is supplied, matching MEAI's behaviour of always emitting server.port alongside server.address with no scheme-default special-casing.

Constructors

GenAiTokenUsageTags(string, string, string, string, string, Nullable<int>) Constructor

Strongly-typed bag of optional tags attached to a RecordTokenUsage(string, long, GenAiTokenUsageTags) measurement. Mirrors the tag schema written by MEAI's Microsoft.Extensions.AI.OpenTelemetryChatClient on the same gen_ai.client.token.usage histogram so the resulting series share a label set and aggregate cleanly under a single OpenTelemetry MetricStreamIdentity.

public GenAiTokenUsageTags(string? OperationName=null, string? RequestModel=null, string? ResponseModel=null, string? ProviderName=null, string? ServerAddress=null, System.Nullable<int> ServerPort=null);

Parameters

OperationName System.String

Value for the gen_ai.operation.name tag, or null to use the default "chat". Note: new GenAiTokenUsageTags() (parameterless invocation) yields null here even though the primary constructor declares a default — that is the standard C# record-struct behaviour for the implicit parameterless constructor. The implementation substitutes "chat" in either case so callers can use default/new GenAiTokenUsageTags() without surprise.

RequestModel System.String

Value for the gen_ai.request.model tag, or null to omit.

ResponseModel System.String

Value for the gen_ai.response.model tag, or null to omit.

ProviderName System.String

Value for the gen_ai.provider.name tag, or null to omit.

ServerAddress System.String

Value for the server.address tag, or null to omit.

ServerPort System.Nullable<System.Int32>

Value for the server.port tag, or null to omit.

Remarks

Any property whose value is null is omitted from the recorded measurement. This matches MEAI's behaviour, where MEAI also omits tags whose source data is unavailable.

ServerPort SHOULD be supplied whenever ServerAddress is supplied, matching MEAI's behaviour of always emitting server.port alongside server.address with no scheme-default special-casing.

Properties

GenAiTokenUsageTags.OperationName Property

Value for the gen_ai.operation.name tag, or null to use the default "chat". Note: new GenAiTokenUsageTags() (parameterless invocation) yields null here even though the primary constructor declares a default — that is the standard C# record-struct behaviour for the implicit parameterless constructor. The implementation substitutes "chat" in either case so callers can use default/new GenAiTokenUsageTags() without surprise.

public string? OperationName { get; init; }

Property Value

System.String

GenAiTokenUsageTags.ProviderName Property

Value for the gen_ai.provider.name tag, or null to omit.

public string? ProviderName { get; init; }

Property Value

System.String

GenAiTokenUsageTags.RequestModel Property

Value for the gen_ai.request.model tag, or null to omit.

public string? RequestModel { get; init; }

Property Value

System.String

GenAiTokenUsageTags.ResponseModel Property

Value for the gen_ai.response.model tag, or null to omit.

public string? ResponseModel { get; init; }

Property Value

System.String

GenAiTokenUsageTags.ServerAddress Property

Value for the server.address tag, or null to omit.

public string? ServerAddress { get; init; }

Property Value

System.String

GenAiTokenUsageTags.ServerPort Property

Value for the server.port tag, or null to omit.

public System.Nullable<int> ServerPort { get; init; }

Property Value

System.Nullable<System.Int32>