-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Summary
Microsoft Agent Framework's UseOpenTelemetry() (via Microsoft.Extensions.AI) implements span attributes from the OpenTelemetry GenAI Semantic Conventions, but does not emit the required ActivityEvents defined in the specification.
Current Behavior
When using MAF with OpenTelemetry:
var chatClient = azureClient
.GetChatClient(deploymentName)
.AsIChatClient()
.AsBuilder()
.UseOpenTelemetry(sourceName: "MyAgent", configure: c => c.EnableSensitiveData = true)
.Build();What's emitted:
- ✅ Activity spans with
gen_ai.*attributes - ✅ Histogram metrics (
gen_ai.client.token.usage,gen_ai.client.operation.duration) - ❌ Missing:
gen_ai.client.inference.operation.detailsActivityEvents
Expected Behavior
According to the OpenTelemetry GenAI Events specification, implementations should emit structured ActivityEvent objects with event name gen_ai.client.inference.operation.details.
Example of expected event structure:
var tags = new ActivityTagsCollection
{
{ "gen_ai.operation.name", "chat" },
{ "gen_ai.request.model", modelId },
{ "gen_ai.response.model", response.ModelId },
{ "gen_ai.usage.input_tokens", inputTokens },
{ "gen_ai.usage.output_tokens", outputTokens },
{ "gen_ai.output.messages", responseText } // Optional
};
var activityEvent = new ActivityEvent("gen_ai.client.inference.operation.details", tags: tags);
Activity.Current?.AddEvent(activityEvent);Distinction: Events vs Span Attributes
- Span Attributes: Key-value pairs attached to spans for the entire operation duration
- ActivityEvents: Timestamped, structured occurrences within a span representing discrete points in time
Both are defined in the OpenTelemetry GenAI spec and serve different purposes in observability.
Impact
Without ActivityEvents:
- Incomplete spec compliance - Missing a key observability signal defined in GenAI conventions
- Limited analysis capabilities - Events enable time-series analysis of LLM operations
- Reduced interoperability - Tools expecting full GenAI spec compliance won't receive event data
Proposal
Extend UseOpenTelemetry() (or add UseOpenTelemetryEvents()) to emit ActivityEvents as specified in the GenAI semantic conventions. This would provide:
- Full compliance with OpenTelemetry GenAI spec
- Unified observability without custom extensions
- Better time-series analysis of LLM operations
- Improved interoperability with GenAI observability tools
References
- OpenTelemetry GenAI Events Spec
- OpenTelemetry GenAI Semantic Conventions
- OpenTelemetryChatClient Source - Current implementation
Environment
- Microsoft Agent Framework: v1.0.0-preview.260128.1
- Microsoft.Extensions.AI: (bundled with MAF)
- Target Framework: .NET 8.0
Metadata
Metadata
Assignees
Labels
Type
Projects
Status