Skip to content

[.Net][ADR] OTel auto-instrumentation proposal#5971

Open
rogerbarreto wants to merge 2 commits into
microsoft:mainfrom
rogerbarreto:adr/agent-otel-auto-instrumentation
Open

[.Net][ADR] OTel auto-instrumentation proposal#5971
rogerbarreto wants to merge 2 commits into
microsoft:mainfrom
rogerbarreto:adr/agent-otel-auto-instrumentation

Conversation

@rogerbarreto
Copy link
Copy Markdown
Member

What

ADR 0026 propose convention-aligned OTel auto-instrumentation for Agent Framework. No code change. Only doc.

Why

Today: per-agent UseOpenTelemetry() wrap. Diverge from .NET OTel ecosystem (AddXxxInstrumentation() on provider). No kill switch. AsAIAgent() factories unreachable by DI wrap.

What ADR propose

  • AddAgentFrameworkInstrumentation() on TracerProviderBuilder + MeterProviderBuilder
  • AddAgentFrameworkWorkflowsInstrumentation() for workflows source
  • Dep: OpenTelemetry.Api.ProviderBuilderExtensions, 2 net-new transitive
  • AgentFrameworkInstrumentationOptions = full parity with UseOpenTelemetry() (SourceName + ConfigureAgent)
  • AsAIAgent() factories gain optional IServiceProvider? services param. Auto-wrap when options registered. Idempotent.
  • Workflow.AsAIAgent() join same pattern (agents marker)
  • Env-var kill switch OTEL_DOTNET_AGENTFRAMEWORK_INSTRUMENTATION_ENABLED
  • Multi-call: last-wins
  • UseOpenTelemetry() + OpenTelemetryAgent unchanged. ADR-0003 not superseded.

Open question for reviewer

Existing OpenTelemetryAgent, UseOpenTelemetry(), OpenTelemetryConsts:

  • Stay in core (recommended, non-breaking), OR
  • Move to new Microsoft.Agents.AI.OpenTelemetry + Microsoft.Agents.AI.Workflows.OpenTelemetry packages (breaking)

Out of scope (deferred)

  • Source-name rename / consolidation (separate "source-naming" ADR)
  • Experimental. prefix removal (gated on upstream gen-AI semconv stable)
  • Profiler-based auto-instrumentation
  • BCL listener-driven emission refactor

Refs

Big OTel rock. Tribe pattern say AddXxxInstrumentation() on provider, kill switch env var. Agent Framework miss.

ADR 0026 land options + decision. Recommended: embed extensions in core assemblies. AddAgentFrameworkInstrumentation() on TracerProviderBuilder + MeterProviderBuilder. Dep small: OpenTelemetry.Api.ProviderBuilderExtensions only, 2 net-new transitive packages.

AsAIAgent() factories auto-wrap via IServiceProvider param when AgentFrameworkInstrumentationOptions registered. Workflow.AsAIAgent() join same. Workflow internal spans still opt-in via WorkflowBuilder.WithOpenTelemetry().

Kill switch: OTEL_DOTNET_AGENTFRAMEWORK_INSTRUMENTATION_ENABLED. Multi-call: last-wins.

ADR-0003 not superseded. Source-naming questions deferred to follow-on ADR.

Refs microsoft#5852
Copilot AI review requested due to automatic review settings May 20, 2026 10:24
@moonbox3 moonbox3 added the documentation Improvements or additions to documentation label May 20, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds ADR 0026 proposing convention-aligned OpenTelemetry “auto-instrumentation” activation for the .NET Agent Framework (provider-builder AddXxxInstrumentation() entrypoints + DI-aware AsAIAgent() wrapping + env-var kill switch). This is documentation-only and is intended to set direction before implementation work begins.

Changes:

  • Introduces a new ADR describing provider-builder activation APIs for agent + workflow telemetry.
  • Proposes DI-driven auto-wrapping behavior for AsAIAgent() factories and an env-var kill switch.
  • Outlines validation/testing expectations and open packaging questions (keep OTel primitives in-core vs move to dedicated packages).
Comments suppressed due to low confidence (1)

docs/decisions/0026-agent-otel-auto-instrumentation.md:139

  • In Consequences, “Adds optional IServiceProvider? services = null to every AsAIAgent() overload” reads as if this parameter is universally new. In practice, several providers already have a services parameter today, while a few (e.g., A2A / Copilot) do not. Suggest clarifying the impact as “adds services to the remaining AsAIAgent overloads that lack it” and optionally call out representative examples, so the scope/cost is accurately represented.
- **Bad:** Adds optional `IServiceProvider? services = null` to every
  `AsAIAgent()` overload across ~10–15 provider packages.
  Source-compatible + binary-compatible. Coordinated release needed.

Comment thread docs/decisions/0026-agent-otel-auto-instrumentation.md
@rogerbarreto rogerbarreto self-assigned this May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants