Skip to content
Draft
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 @@ -25,7 +25,7 @@ public static BaggageBuilder FromTurnContext(this BaggageBuilder baggageBuilder,
.SetCallerBaggage(turnContext)
.SetTargetAgentBaggage(turnContext)
.SetTenantIdBaggage(turnContext)
.SetSourceMetadataBaggage(turnContext)
.SetChannelBaggage(turnContext)
.SetConversationIdBaggage(turnContext);

return baggageBuilder;
Expand Down Expand Up @@ -68,14 +68,14 @@ public static BaggageBuilder SetTenantIdBaggage(this BaggageBuilder baggageBuild
}

/// <summary>
/// Sets the source metadata baggage values from the TurnContext.
/// Sets the channel baggage values from the TurnContext.
/// </summary>
/// <param name="baggageBuilder">The BaggageBuilder instance.</param>
/// <param name="turnContext">The turn context containing activity information.</param>
/// <returns>The updated BaggageBuilder instance.</returns>
public static BaggageBuilder SetSourceMetadataBaggage(this BaggageBuilder baggageBuilder, ITurnContext turnContext)
public static BaggageBuilder SetChannelBaggage(this BaggageBuilder baggageBuilder, ITurnContext turnContext)
{
baggageBuilder.SetRange(turnContext.GetSourceMetadataBaggagePairs());
baggageBuilder.SetRange(turnContext.GetChannelBaggagePairs());
return baggageBuilder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static InvokeAgentScope FromTurnContext(this InvokeAgentScope invokeAgent
.SetCallerTags(turnContext)
.SetTargetAgentTags(turnContext)
.SetTenantIdTags(turnContext)
.SetSourceMetadataTags(turnContext)
.SetChannelTags(turnContext)
.SetConversationIdTags(turnContext);

return invokeAgentScope;
Expand Down Expand Up @@ -63,11 +63,11 @@ public static InvokeAgentScope SetTenantIdTags(this InvokeAgentScope invokeAgent
}

/// <summary>
/// Sets the source metadata tags from the TurnContext.
/// Sets the channel tags from the TurnContext.
/// </summary>
public static InvokeAgentScope SetSourceMetadataTags(this InvokeAgentScope invokeAgentScope, ITurnContext turnContext)
public static InvokeAgentScope SetChannelTags(this InvokeAgentScope invokeAgentScope, ITurnContext turnContext)
{
invokeAgentScope.RecordAttributes(turnContext.GetSourceMetadataBaggagePairs());
invokeAgentScope.RecordAttributes(turnContext.GetChannelBaggagePairs());
return invokeAgentScope;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public static class TurnContextExtensions
/// </summary>
public static IEnumerable<KeyValuePair<string, object?>> GetCallerBaggagePairs(this ITurnContext turnContext)
{
yield return new KeyValuePair<string, object?>(OpenTelemetryConstants.CallerIdKey, turnContext.Activity?.From?.Id);
yield return new KeyValuePair<string, object?>(OpenTelemetryConstants.CallerNameKey, turnContext.Activity?.From?.Name);
yield return new KeyValuePair<string, object?>(OpenTelemetryConstants.UserIdKey, turnContext.Activity?.From?.Id);
yield return new KeyValuePair<string, object?>(OpenTelemetryConstants.UserNameKey, turnContext.Activity?.From?.Name);
}

/// <summary>
Expand Down Expand Up @@ -65,9 +65,9 @@ public static class TurnContextExtensions
}

/// <summary>
/// Extracts source metadata baggage key-value pairs from the provided turn context.
/// Extracts channel baggage key-value pairs from the provided turn context.
/// </summary>
public static IEnumerable<KeyValuePair<string, object?>> GetSourceMetadataBaggagePairs(this ITurnContext turnContext)
public static IEnumerable<KeyValuePair<string, object?>> GetChannelBaggagePairs(this ITurnContext turnContext)
{
yield return new KeyValuePair<string, object?>(OpenTelemetryConstants.ChannelNameKey, turnContext.Activity?.ChannelId?.Channel);
yield return new KeyValuePair<string, object?>(OpenTelemetryConstants.ChannelLinkKey, turnContext.Activity?.ChannelId?.SubChannel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ public async Task OnTurnAsync(ITurnContext turnContext, NextDelegate next, Cance

var callerDetails = DeriveCallerDetails(turnContext);
var conversationId = turnContext.Activity?.Conversation?.Id;
var sourceMetadata = DeriveSourceMetadata(turnContext);
var channel = DeriveChannel(turnContext);

turnContext.OnSendActivities(CreateSendHandler(
turnContext,
agentDetails,
tenantDetails,
callerDetails,
conversationId,
sourceMetadata));
channel));

await next(cancellationToken).ConfigureAwait(false);
}
Expand Down Expand Up @@ -116,17 +116,17 @@ public async Task OnTurnAsync(ITurnContext turnContext, NextDelegate next, Cance
tenantId: from.TenantId);
}

private static SourceMetadata? DeriveSourceMetadata(ITurnContext turnContext)
private static Channel? DeriveChannel(ITurnContext turnContext)
{
var channelId = turnContext.Activity?.ChannelId;
if (channelId == null)
{
return null;
}

return new SourceMetadata(
return new Channel(
name: channelId.Channel,
description: channelId.SubChannel);
link: channelId.SubChannel);
}

private static SendActivitiesHandler CreateSendHandler(
Expand All @@ -135,7 +135,7 @@ private static SendActivitiesHandler CreateSendHandler(
TenantDetails tenantDetails,
CallerDetails? callerDetails,
string? conversationId,
SourceMetadata? sourceMetadata)
Channel? channel)
{
return async (ctx, activities, nextSend) =>
{
Expand Down Expand Up @@ -171,7 +171,7 @@ private static SendActivitiesHandler CreateSendHandler(
tenantDetails: tenantDetails,
response: new Response(messages),
conversationId: conversationId,
sourceMetadata: sourceMetadata,
channel: channel,
callerDetails: callerDetails,
parentContext: parentContext);

Expand Down
8 changes: 4 additions & 4 deletions src/Observability/Runtime/Common/BaggageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public BaggageBuilder AgentAuid(string? v)
/// </remarks>
public BaggageBuilder AgentUpn(string? v)
{
Set(OpenTelemetryConstants.AgentUPNKey, v);
Set(OpenTelemetryConstants.AgentEmailKey, v);
return this;
}

Expand Down Expand Up @@ -160,7 +160,7 @@ public BaggageBuilder AgentPlatformId(string? v)
/// </remarks>
public BaggageBuilder CallerId(string? v)
{
Set(OpenTelemetryConstants.CallerIdKey, v);
Set(OpenTelemetryConstants.UserIdKey, v);
return this;
}

Expand All @@ -172,7 +172,7 @@ public BaggageBuilder CallerId(string? v)
/// </remarks>
public BaggageBuilder CallerUpn(string? v)
{
Set(OpenTelemetryConstants.CallerUpnKey, v);
Set(OpenTelemetryConstants.UserEmailKey, v);
return this;
}

Expand All @@ -184,7 +184,7 @@ public BaggageBuilder CallerUpn(string? v)
/// </remarks>
public BaggageBuilder CallerName(string? v)
{
Set(OpenTelemetryConstants.CallerNameKey, v);
Set(OpenTelemetryConstants.UserNameKey, v);
return this;
}

Expand Down
32 changes: 16 additions & 16 deletions src/Observability/Runtime/DTOs/Builders/BaseDataBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ public abstract class BaseDataBuilder<T> where T : BaseData
OpenTelemetryConstants.GenAiAgentNameKey,
OpenTelemetryConstants.GenAiAgentDescriptionKey,
OpenTelemetryConstants.AgentAUIDKey,
OpenTelemetryConstants.AgentUPNKey,
OpenTelemetryConstants.AgentEmailKey,
OpenTelemetryConstants.AgentBlueprintIdKey,
OpenTelemetryConstants.AgentPlatformIdKey,
OpenTelemetryConstants.TenantIdKey,
OpenTelemetryConstants.ServerAddressKey,
OpenTelemetryConstants.ServerPortKey,
OpenTelemetryConstants.ChannelNameKey,
OpenTelemetryConstants.ChannelLinkKey,
OpenTelemetryConstants.CallerIdKey,
OpenTelemetryConstants.CallerUpnKey,
OpenTelemetryConstants.CallerNameKey,
OpenTelemetryConstants.UserIdKey,
OpenTelemetryConstants.UserEmailKey,
OpenTelemetryConstants.UserNameKey,
OpenTelemetryConstants.CallerAgentNameKey,
OpenTelemetryConstants.CallerAgentIdKey,
OpenTelemetryConstants.CallerAgentBlueprintIdKey,
OpenTelemetryConstants.CallerAgentAUIDKey,
OpenTelemetryConstants.CallerAgentUPNKey,
OpenTelemetryConstants.CallerAgentEmailKey,
OpenTelemetryConstants.CallerClientIpKey,
OpenTelemetryConstants.GenAiConversationIdKey,
OpenTelemetryConstants.SessionIdKey,
Expand Down Expand Up @@ -88,7 +88,7 @@ protected static void AddAgentDetails(IDictionary<string, object?> attributes, A
AddIfNotNull(attributes, OpenTelemetryConstants.GenAiAgentNameKey, agentDetails.AgentName);
AddIfNotNull(attributes, OpenTelemetryConstants.GenAiAgentDescriptionKey, agentDetails.AgentDescription);
AddIfNotNull(attributes, OpenTelemetryConstants.AgentAUIDKey, agentDetails.AgentAUID);
AddIfNotNull(attributes, OpenTelemetryConstants.AgentUPNKey, agentDetails.AgentUPN);
AddIfNotNull(attributes, OpenTelemetryConstants.AgentEmailKey, agentDetails.AgentUPN);
AddIfNotNull(attributes, OpenTelemetryConstants.AgentBlueprintIdKey, agentDetails.AgentBlueprintId);
AddIfNotNull(attributes, OpenTelemetryConstants.AgentPlatformIdKey, agentDetails.AgentPlatformId);
}
Expand Down Expand Up @@ -126,7 +126,7 @@ protected static void AddRequestDetails(IDictionary<string, object?> attributes,
{
if (request == null) return;

AddSourceMetadataAttributes(attributes, request.SourceMetadata);
AddChannelAttributes(attributes, request.Channel);
}

/// <summary>
Expand All @@ -136,9 +136,9 @@ protected static void AddCallerDetails(IDictionary<string, object?> attributes,
{
if (callerDetails == null) return;

AddIfNotNull(attributes, OpenTelemetryConstants.CallerIdKey, callerDetails.CallerId);
AddIfNotNull(attributes, OpenTelemetryConstants.CallerUpnKey, callerDetails.CallerUpn);
AddIfNotNull(attributes, OpenTelemetryConstants.CallerNameKey, callerDetails.CallerName);
AddIfNotNull(attributes, OpenTelemetryConstants.UserIdKey, callerDetails.CallerId);
AddIfNotNull(attributes, OpenTelemetryConstants.UserEmailKey, callerDetails.CallerUpn);
AddIfNotNull(attributes, OpenTelemetryConstants.UserNameKey, callerDetails.CallerName);
AddIfNotNull(attributes, OpenTelemetryConstants.CallerClientIpKey, callerDetails.CallerClientIP?.ToString());
}

Expand All @@ -153,19 +153,19 @@ protected static void AddCallerAgentDetails(IDictionary<string, object?> attribu
AddIfNotNull(attributes, OpenTelemetryConstants.CallerAgentIdKey, callerAgentDetails.AgentId);
AddIfNotNull(attributes, OpenTelemetryConstants.CallerAgentBlueprintIdKey, callerAgentDetails.AgentBlueprintId);
AddIfNotNull(attributes, OpenTelemetryConstants.CallerAgentAUIDKey, callerAgentDetails.AgentAUID);
AddIfNotNull(attributes, OpenTelemetryConstants.CallerAgentUPNKey, callerAgentDetails.AgentUPN);
AddIfNotNull(attributes, OpenTelemetryConstants.CallerAgentEmailKey, callerAgentDetails.AgentUPN);
AddIfNotNull(attributes, OpenTelemetryConstants.CallerAgentPlatformIdKey, callerAgentDetails.AgentPlatformId);
}

/// <summary>
/// Adds source metadata attributes to the attributes dictionary.
/// Adds channel attributes to the attributes dictionary.
/// </summary>
protected static void AddSourceMetadataAttributes(IDictionary<string, object?> attributes, SourceMetadata? sourceMetadata)
protected static void AddChannelAttributes(IDictionary<string, object?> attributes, Channel? channel)
{
if (sourceMetadata == null) return;
if (channel == null) return;

AddIfNotNull(attributes, OpenTelemetryConstants.ChannelNameKey, sourceMetadata.Name);
AddIfNotNull(attributes, OpenTelemetryConstants.ChannelLinkKey, sourceMetadata.Description);
AddIfNotNull(attributes, OpenTelemetryConstants.ChannelNameKey, channel.Name);
AddIfNotNull(attributes, OpenTelemetryConstants.ChannelLinkKey, channel.Link);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ExecuteInferenceDataBuilder : BaseDataBuilder<ExecuteInferenceData>
/// <param name="endTime">Optional custom end time for the operation.</param>
/// <param name="spanId">Optional span ID for the operation.</param>
/// <param name="parentSpanId">Optional parent span ID for distributed tracing.</param>
/// <param name="sourceMetadata">Optional source metadata for the inference call.</param>
/// <param name="channel">Optional channel information for the inference call.</param>
/// <param name="thoughtProcess">Optional agent thought process for the inference.</param>
/// <param name="callerDetails">Optional details about the non-agentic caller.</param>
/// <param name="extraAttributes">Optional dictionary of extra attributes.</param>
Expand All @@ -43,7 +43,7 @@ public static ExecuteInferenceData Build(
DateTimeOffset? endTime = null,
string? spanId = null,
string? parentSpanId = null,
SourceMetadata? sourceMetadata = null,
Channel? channel = null,
string? thoughtProcess = null,
CallerDetails? callerDetails = null,
IDictionary<string, object?>? extraAttributes = null,
Expand All @@ -56,7 +56,7 @@ public static ExecuteInferenceData Build(
conversationId,
inputMessages,
outputMessages,
sourceMetadata,
channel,
thoughtProcess,
callerDetails,
extraAttributes);
Expand All @@ -71,7 +71,7 @@ public static ExecuteInferenceData Build(
string conversationId,
string[]? inputMessages,
string[]? outputMessages,
SourceMetadata? sourceMetadata,
Channel? channel,
string? thoughtProcess,
CallerDetails? callerDetails,
IDictionary<string, object?>? extraAttributes = null)
Expand All @@ -95,8 +95,8 @@ public static ExecuteInferenceData Build(
// Thought process
AddIfNotNull(attributes, GenAiAgentThoughtProcessKey, thoughtProcess);

// Source metadata
AddSourceMetadataAttributes(attributes, sourceMetadata);
// Channel
AddChannelAttributes(attributes, channel);

// Add caller details
AddCallerDetails(attributes, callerDetails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ExecuteToolDataBuilder : BaseDataBuilder<ExecuteToolData>
/// <param name="endTime">Optional custom end time for the operation.</param>
/// <param name="spanId">Optional span ID for the operation.</param>
/// <param name="parentSpanId">Optional parent span ID for distributed tracing.</param>
/// <param name="sourceMetadata">Optional source metadata for the operation.</param>
/// <param name="channel">Optional channel information for the operation.</param>
/// <param name="callerDetails">Optional details about the non-agentic caller.</param>
/// <param name="extraAttributes">Optional dictionary of extra attributes.</param>
/// <param name="spanKind">Optional span kind override. Use <see cref="SpanKindConstants.Internal"/> or <see cref="SpanKindConstants.Client"/> as appropriate.</param>
Expand All @@ -44,13 +44,13 @@ public static ExecuteToolData Build(
DateTimeOffset? endTime = null,
string? spanId = null,
string? parentSpanId = null,
SourceMetadata? sourceMetadata = null,
Channel? channel = null,
CallerDetails? callerDetails = null,
IDictionary<string, object?>? extraAttributes = null,
string? spanKind = null,
string? traceId = null)
{
var attributes = BuildAttributes(toolCallDetails, agentDetails, tenantDetails, conversationId, responseContent, sourceMetadata, callerDetails, extraAttributes);
var attributes = BuildAttributes(toolCallDetails, agentDetails, tenantDetails, conversationId, responseContent, channel, callerDetails, extraAttributes);

return new ExecuteToolData(attributes, startTime, endTime, spanId, parentSpanId, spanKind, traceId);
}
Expand All @@ -61,7 +61,7 @@ public static ExecuteToolData Build(
TenantDetails tenantDetails,
string conversationId,
string? responseContent,
SourceMetadata? sourceMetadata,
Channel? channel,
CallerDetails? callerDetails,
IDictionary<string, object?>? extraAttributes = null)
{
Expand All @@ -83,8 +83,8 @@ public static ExecuteToolData Build(
// Response content if supplied
AddIfNotNull(attributes, OpenTelemetryConstants.GenAiToolCallResultKey, responseContent);

// Source metadata
AddSourceMetadataAttributes(attributes, sourceMetadata);
// Channel
AddChannelAttributes(attributes, channel);

// Add caller details
AddCallerDetails(attributes, callerDetails);
Expand Down
Loading