Skip to content

.NET: UseOpenTelemetry() does not emit ActivityEvents as specified in OpenTelemetry GenAI Semantic Conventions #3637

@gijswalraven

Description

@gijswalraven

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.details ActivityEvents

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:

  1. Incomplete spec compliance - Missing a key observability signal defined in GenAI conventions
  2. Limited analysis capabilities - Events enable time-series analysis of LLM operations
  3. 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

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

.NETobservabilityIssues related to observability or telemetryv1.0Features being tracked for the version 1.0 GA

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions