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
2 changes: 2 additions & 0 deletions src/Observability/Runtime/DTOs/Builders/BaseDataBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public abstract class BaseDataBuilder<T> where T : BaseData
OpenTelemetryConstants.GenAiCallerAgentAUIDKey,
OpenTelemetryConstants.GenAiCallerAgentUPNKey,
OpenTelemetryConstants.GenAiCallerAgentTenantKey,
OpenTelemetryConstants.GenAiCallerClientIpKey,
OpenTelemetryConstants.GenAiConversationIdKey,
OpenTelemetryConstants.SessionIdKey,
OpenTelemetryConstants.GenAiToolNameKey,
Expand Down Expand Up @@ -145,6 +146,7 @@ protected static void AddCallerDetails(IDictionary<string, object?> attributes,
AddIfNotNull(attributes, OpenTelemetryConstants.GenAiCallerIdKey, callerDetails.CallerId);
AddIfNotNull(attributes, OpenTelemetryConstants.GenAiCallerUpnKey, callerDetails.CallerUpn);
AddIfNotNull(attributes, OpenTelemetryConstants.GenAiCallerNameKey, callerDetails.CallerName);
AddIfNotNull(attributes, OpenTelemetryConstants.GenAiCallerClientIpKey, callerDetails.CallerClientIP?.ToString());
AddIfNotNull(attributes, OpenTelemetryConstants.GenAiCallerTenantIdKey, callerDetails.TenantId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class ExecuteInferenceDataBuilder : BaseDataBuilder<ExecuteInferenceData>
/// <param name="sourceMetadata">Optional source metadata for the inference call.</param>
/// <param name="thoughtProcess">Optional agent thought process for the inference.</param>
/// <param name="hiringManagerId">Optional hiring manager ID.</param>
/// <param name="callerDetails">Optional details about the non-agentic caller.</param>
/// <param name="extraAttributes">Optional dictionary of extra attributes.</param>
/// <returns>An ExecuteInferenceData object containing all telemetry data.</returns>
public static ExecuteInferenceData Build(
Expand All @@ -45,6 +46,7 @@ public static ExecuteInferenceData Build(
SourceMetadata? sourceMetadata = null,
string? thoughtProcess = null,
string? hiringManagerId = null,
CallerDetails? callerDetails = null,
IDictionary<string, object?>? extraAttributes = null)
{
var attributes = BuildAttributes(
Expand All @@ -57,6 +59,7 @@ public static ExecuteInferenceData Build(
sourceMetadata,
thoughtProcess,
hiringManagerId,
callerDetails,
extraAttributes);

return new ExecuteInferenceData(attributes, startTime, endTime, spanId, parentSpanId);
Expand All @@ -72,6 +75,7 @@ public static ExecuteInferenceData Build(
SourceMetadata? sourceMetadata,
string? thoughtProcess,
string? hiringManagerId,
CallerDetails? callerDetails,
IDictionary<string, object?>? extraAttributes = null)
{
var attributes = new Dictionary<string, object?>();
Expand Down Expand Up @@ -99,6 +103,9 @@ public static ExecuteInferenceData Build(
// Add hiring manager ID
AddIfNotNull(attributes, HiringManagerIdKey, hiringManagerId);

// Add caller details
AddCallerDetails(attributes, callerDetails);

// Add any extra attributes
AddExtraAttributes(attributes, extraAttributes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class ExecuteToolDataBuilder : BaseDataBuilder<ExecuteToolData>
/// <param name="parentSpanId">Optional parent span ID for distributed tracing.</param>
/// <param name="sourceMetadata">Optional source metadata for the operation.</param>
/// <param name="hiringManagerId">Optional hiring manager ID.</param>
/// <param name="callerDetails">Optional details about the non-agentic caller.</param>
/// <param name="extraAttributes">Optional dictionary of extra attributes.</param>
/// <returns>An ExecuteToolData object containing all telemetry data.</returns>
public static ExecuteToolData Build(
Expand All @@ -44,9 +45,10 @@ public static ExecuteToolData Build(
string? parentSpanId = null,
SourceMetadata? sourceMetadata = null,
string? hiringManagerId = null,
CallerDetails? callerDetails = null,
IDictionary<string, object?>? extraAttributes = null)
{
var attributes = BuildAttributes(toolCallDetails, agentDetails, tenantDetails, conversationId, responseContent, sourceMetadata, hiringManagerId, extraAttributes);
var attributes = BuildAttributes(toolCallDetails, agentDetails, tenantDetails, conversationId, responseContent, sourceMetadata, hiringManagerId, callerDetails, extraAttributes);

return new ExecuteToolData(attributes, startTime, endTime, spanId, parentSpanId);
}
Expand All @@ -59,6 +61,7 @@ public static ExecuteToolData Build(
string? responseContent,
SourceMetadata? sourceMetadata,
string? hiringManagerId,
CallerDetails? callerDetails,
IDictionary<string, object?>? extraAttributes = null)
{
var attributes = new Dictionary<string, object?>();
Expand All @@ -85,6 +88,9 @@ public static ExecuteToolData Build(
// Add hiring manager ID
AddIfNotNull(attributes, OpenTelemetryConstants.HiringManagerIdKey, hiringManagerId);

// Add caller details
AddCallerDetails(attributes, callerDetails);

// Add any extra attributes
AddExtraAttributes(attributes, extraAttributes);

Expand Down
12 changes: 8 additions & 4 deletions src/Observability/Runtime/Etw/A365EtwLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public void LogInferenceCall(
DateTimeOffset? endTime,
string? spanId,
string? parentSpanId,
SourceMetadata? sourceMetadata)
SourceMetadata? sourceMetadata,
CallerDetails? callerDetails)
{
var data = ExecuteInferenceDataBuilder.Build(
inferenceCallDetails,
Expand All @@ -58,7 +59,8 @@ public void LogInferenceCall(
endTime,
spanId,
parentSpanId,
sourceMetadata);
sourceMetadata,
callerDetails: callerDetails);

logger.Log(
LogLevel.Information,
Expand Down Expand Up @@ -118,7 +120,8 @@ public void LogToolCall(
DateTimeOffset? endTime,
string? spanId,
string? parentSpanId,
SourceMetadata? sourceMetadata)
SourceMetadata? sourceMetadata,
CallerDetails? callerDetails)
{
var data = ExecuteToolDataBuilder.Build(
toolCallDetails,
Expand All @@ -130,7 +133,8 @@ public void LogToolCall(
endTime,
spanId,
parentSpanId,
sourceMetadata);
sourceMetadata,
callerDetails: callerDetails);

logger.Log(
LogLevel.Information,
Expand Down
8 changes: 6 additions & 2 deletions src/Observability/Runtime/Etw/IA365EtwLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void LogInvokeAgent(
/// <param name="spanId">Optional span ID for tracing.</param>
/// <param name="parentSpanId">Optional parent span ID for tracing.</param>
/// <param name="sourceMetadata">Optional source metadata for the inference call.</param>
/// <param name="callerDetails">Optional details of the non-agentic caller.</param>
public void LogInferenceCall(
InferenceCallDetails inferenceCallDetails,
AgentDetails agentDetails,
Expand All @@ -62,7 +63,8 @@ public void LogInferenceCall(
DateTimeOffset? endTime = null,
string? spanId = null,
string? parentSpanId = null,
SourceMetadata? sourceMetadata = null);
SourceMetadata? sourceMetadata = null,
CallerDetails? callerDetails = null);

/// <summary>
/// Logs an execute_tool event.
Expand All @@ -77,6 +79,7 @@ public void LogInferenceCall(
/// <param name="spanId">Optional span ID for tracing.</param>
/// <param name="parentSpanId">Optional parent span ID for tracing.</param>
/// <param name="sourceMetadata">Optional source metadata for the tool call.</param>
/// <param name="callerDetails">Optional details of the non-agentic caller.</param>
public void LogToolCall(
ToolCallDetails toolCallDetails,
AgentDetails agentDetails,
Expand All @@ -87,7 +90,8 @@ public void LogToolCall(
DateTimeOffset? endTime = null,
string? spanId = null,
string? parentSpanId = null,
SourceMetadata? sourceMetadata = null);
SourceMetadata? sourceMetadata = null,
CallerDetails? callerDetails = null);

/// <summary>
/// Logs an output_messages event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public sealed class ExecuteToolScope : OpenTelemetryScope
/// <param name="conversationId">Optional conversation or session correlation ID for the tool execution.</param>
/// <param name="sourceMetadata">Optional metadata describing the source of the call (e.g., component, file, line) for observability.</param>
/// <param name="threatDiagnosticsSummary">Optional threat diagnostics summary containing security-related information about blocked actions.</param>
/// <param name="callerDetails">Optional details about the non-agentic caller.</param>
/// <returns>A new ExecuteToolScope instance.</returns>
/// <remarks>
/// <para>
Expand All @@ -43,9 +44,9 @@ public sealed class ExecuteToolScope : OpenTelemetryScope
/// <see href="https://go.microsoft.com/fwlink/?linkid=2344479">Learn more about certification requirements</see>
/// </para>
/// </remarks>
public static ExecuteToolScope Start(ToolCallDetails details, AgentDetails agentDetails, TenantDetails tenantDetails, string? parentId = null, string? conversationId = null, SourceMetadata? sourceMetadata = null, ThreatDiagnosticsSummary? threatDiagnosticsSummary = null) => new ExecuteToolScope(details, agentDetails, tenantDetails, parentId, conversationId, sourceMetadata, threatDiagnosticsSummary);
public static ExecuteToolScope Start(ToolCallDetails details, AgentDetails agentDetails, TenantDetails tenantDetails, string? parentId = null, string? conversationId = null, SourceMetadata? sourceMetadata = null, ThreatDiagnosticsSummary? threatDiagnosticsSummary = null, CallerDetails? callerDetails = null) => new ExecuteToolScope(details, agentDetails, tenantDetails, parentId, conversationId, sourceMetadata, threatDiagnosticsSummary, callerDetails);

private ExecuteToolScope(ToolCallDetails details, AgentDetails agentDetails, TenantDetails tenantDetails, string? parentId = null, string? conversationId = null, SourceMetadata? sourceMetadata = null, ThreatDiagnosticsSummary? threatDiagnosticsSummary = null)
private ExecuteToolScope(ToolCallDetails details, AgentDetails agentDetails, TenantDetails tenantDetails, string? parentId = null, string? conversationId = null, SourceMetadata? sourceMetadata = null, ThreatDiagnosticsSummary? threatDiagnosticsSummary = null, CallerDetails? callerDetails = null)
: base(
kind: ActivityKind.Internal,
agentDetails: agentDetails,
Expand All @@ -54,7 +55,8 @@ private ExecuteToolScope(ToolCallDetails details, AgentDetails agentDetails, Ten
activityName: $"{OperationName} {details.ToolName}",
parentId: parentId,
conversationId: conversationId,
sourceMetadata: sourceMetadata)
sourceMetadata: sourceMetadata,
callerDetails: callerDetails)
{
var (toolName, arguments, toolCallId, description, toolType, endpoint, toolServerName) = details;
SetTagMaybe(OpenTelemetryConstants.GenAiToolNameKey, toolName);
Expand Down
8 changes: 5 additions & 3 deletions src/Observability/Runtime/Tracing/Scopes/InferenceScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public sealed class InferenceScope : OpenTelemetryScope
/// <param name="parentId">Optional parent Activity ID used to link this span to an upstream operation.</param>
/// <param name="conversationId">Optional conversation or session correlation ID for the inference.</param>
/// <param name="sourceMetadata">Optional metadata describing the source of the call (e.g., component, file, line) for observability.</param>
/// <param name="callerDetails">Optional details about the non-agentic caller.</param>
/// <returns>A new InferenceScope instance.</returns>
/// <remarks>
/// <para>
Expand All @@ -38,9 +39,9 @@ public sealed class InferenceScope : OpenTelemetryScope
/// <see href="https://go.microsoft.com/fwlink/?linkid=2344479">Learn more about certification requirements</see>
/// </para>
/// </remarks>
public static InferenceScope Start(InferenceCallDetails details, AgentDetails agentDetails, TenantDetails tenantDetails, string? parentId = null, string? conversationId = null, SourceMetadata? sourceMetadata = null) => new InferenceScope(details, agentDetails, tenantDetails, parentId, conversationId, sourceMetadata);
public static InferenceScope Start(InferenceCallDetails details, AgentDetails agentDetails, TenantDetails tenantDetails, string? parentId = null, string? conversationId = null, SourceMetadata? sourceMetadata = null, CallerDetails? callerDetails = null) => new InferenceScope(details, agentDetails, tenantDetails, parentId, conversationId, sourceMetadata, callerDetails);

private InferenceScope(InferenceCallDetails details, AgentDetails agentDetails, TenantDetails tenantDetails, string? parentId = null, string? conversationId = null, SourceMetadata? sourceMetadata = null)
private InferenceScope(InferenceCallDetails details, AgentDetails agentDetails, TenantDetails tenantDetails, string? parentId = null, string? conversationId = null, SourceMetadata? sourceMetadata = null, CallerDetails? callerDetails = null)
: base(
kind: ActivityKind.Client,
agentDetails: agentDetails,
Expand All @@ -49,7 +50,8 @@ private InferenceScope(InferenceCallDetails details, AgentDetails agentDetails,
activityName: $"{details.OperationName} {details.Model}",
parentId: parentId,
conversationId: conversationId,
sourceMetadata: sourceMetadata)
sourceMetadata: sourceMetadata,
callerDetails: callerDetails)
{
SetTagMaybe(GenAiOperationNameKey, details.OperationName.ToString());
SetTagMaybe(GenAiRequestModelKey, details.Model);
Expand Down
13 changes: 2 additions & 11 deletions src/Observability/Runtime/Tracing/Scopes/InvokeAgentScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ private InvokeAgentScope(InvokeAgentDetails invokeAgentDetails, TenantDetails te
? OperationName
: $"invoke_agent {invokeAgentDetails.Details.AgentName}",
conversationId: conversationId,
sourceMetadata: request?.SourceMetadata)
sourceMetadata: request?.SourceMetadata,
callerDetails: callerDetails)
{
var (endpoint, _, sessionId) = invokeAgentDetails;

Expand All @@ -77,16 +78,6 @@ private InvokeAgentScope(InvokeAgentDetails invokeAgentDetails, TenantDetails te
SetTagMaybe(OpenTelemetryConstants.ServerPortKey, endpoint?.Port);
}

// Set caller details tags
if (callerDetails != null)
{
SetTagMaybe(OpenTelemetryConstants.GenAiCallerIdKey, callerDetails.CallerId);
SetTagMaybe(OpenTelemetryConstants.GenAiCallerUpnKey, callerDetails.CallerUpn);
SetTagMaybe(OpenTelemetryConstants.GenAiCallerNameKey, callerDetails.CallerName);
SetTagMaybe(OpenTelemetryConstants.GenAiCallerClientIpKey, callerDetails.CallerClientIP?.ToString());
SetTagMaybe(OpenTelemetryConstants.GenAiCallerTenantIdKey, callerDetails.TenantId);
}

// Set caller agent details tags
if (callerAgentDetails != null)
{
Expand Down
12 changes: 11 additions & 1 deletion src/Observability/Runtime/Tracing/Scopes/OpenTelemetryScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public abstract class OpenTelemetryScope : IDisposable
/// <param name="parentId">Optional parent ID for the activity.</param>
/// <param name="conversationId">Optional conversation id.</param>
/// <param name="sourceMetadata">Optional source metadata.</param>
protected OpenTelemetryScope(ActivityKind kind, AgentDetails agentDetails, TenantDetails tenantDetails, string operationName, string activityName, DateTimeOffset? startTime = null, string? parentId = null, string? conversationId = null, SourceMetadata? sourceMetadata = null)
/// <param name="callerDetails">Optional details about the non-agentic caller.</param>
protected OpenTelemetryScope(ActivityKind kind, AgentDetails agentDetails, TenantDetails tenantDetails, string operationName, string activityName, DateTimeOffset? startTime = null, string? parentId = null, string? conversationId = null, SourceMetadata? sourceMetadata = null, CallerDetails? callerDetails = null)
{
customStartTime = startTime;
activity = ActivitySource.CreateActivity(activityName, kind, default(ActivityContext));
Expand Down Expand Up @@ -104,6 +105,15 @@ protected OpenTelemetryScope(ActivityKind kind, AgentDetails agentDetails, Tenan
SetTagMaybe(OpenTelemetryConstants.GenAiChannelLinkKey, sourceMetadata.Description);
}

if (callerDetails != null)
{
SetTagMaybe(OpenTelemetryConstants.GenAiCallerIdKey, callerDetails.CallerId);
SetTagMaybe(OpenTelemetryConstants.GenAiCallerUpnKey, callerDetails.CallerUpn);
SetTagMaybe(OpenTelemetryConstants.GenAiCallerNameKey, callerDetails.CallerName);
SetTagMaybe(OpenTelemetryConstants.GenAiCallerClientIpKey, callerDetails.CallerClientIP?.ToString());
SetTagMaybe(OpenTelemetryConstants.GenAiCallerTenantIdKey, callerDetails.TenantId);
}

activity?.Start();
}

Expand Down
Loading