Skip to content

.NET: expose OpenTelemetryAgent.DefaultSourceName - #7815

Open
Yashvant Mahadev Hange (YashvantHange) wants to merge 2 commits into
microsoft:mainfrom
YashvantHange:dotnet-expose-otel-default-source-name
Open

.NET: expose OpenTelemetryAgent.DefaultSourceName#7815
Yashvant Mahadev Hange (YashvantHange) wants to merge 2 commits into
microsoft:mainfrom
YashvantHange:dotnet-expose-otel-default-source-name

Conversation

@YashvantHange

Copy link
Copy Markdown

Motivation & Context

ADR 0003 documents how to subscribe to agent telemetry:

usingvartracerProvider=Sdk.CreateTracerProviderBuilder().AddSource(AgentOpenTelemetryConsts.DefaultSourceName).AddConsoleExporter().Build();

That snippet does not compile against the shipped package. AgentOpenTelemetryConsts was renamed to OpenTelemetryConsts in #356, and the type is internal, so DefaultSourceName is unreachable from outside the assembly. Consumers who want to receive invoke_agent spans under the default source have to hardcode the literal "Experimental.Microsoft.Agents.AI", which fails silently if that name ever changes. The repository's own tests hardcode the same literal.

Description & Review Guide

  • What are the major changes?

    OpenTelemetryAgent gains a public const string DefaultSourceName that forwards to the existing internal OpenTelemetryConsts.DefaultSourceName. The constant is placed on the type that emits the spans, so OpenTelemetryConsts and the gen_ai.* attribute keys remain internal, preserving the Microsoft.Extensions.AI symmetry that ADR 0003 lists as a design goal. The ADR usage snippet is corrected to reference the constant that now exists. A unit test pins the constant to the literal source name so a rename cannot silently break subscribers.

  • What is the impact of these changes?

    Purely additive. Release builds of Microsoft.Agents.AI succeed across all five target frameworks with no warnings, and Package Validation reports no compatibility diagnostics against the published baseline. No existing behavior changes.

  • What do you want reviewers to focus on?

    Whether OpenTelemetryAgent is the placement you want for the constant. Moving it is a one-line change if you would prefer it elsewhere. The narrower question of whether to also make the gen_ai.* attribute keys public is deliberately left out of this change, since it is a larger API commitment.

Related Issue

Fixes#6452

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

The default ActivitySource name lives on the internal OpenTelemetryConsts
class, so consumers cannot reference it when configuring a TracerProvider
and must hardcode the literal "Experimental.Microsoft.Agents.AI" instead.
ADR 0003 documents AgentOpenTelemetryConsts.DefaultSourceName for this,
a type that no longer exists after the rename in microsoft#356.
Expose the source name as a public const on OpenTelemetryAgent, the type
that emits the spans, rather than making the whole constants class public.
That keeps the gen_ai.* attribute keys internal, matching the
Microsoft.Extensions.AI precedent, while making the documented AddSource
call compile. Update the ADR snippet to the constant that now exists.
CopilotAI balanced review requested due to automatic review settings August 22, 2026 07:33
@agent-framework-automationagent-framework-automationBot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net labels Aug 22, 2026

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Exposes the default OpenTelemetry activity source name for external subscribers and updates guidance and tests accordingly.

Changes:

  • Adds OpenTelemetryAgent.DefaultSourceName.
  • Updates the ADR usage example.
  • Tests the exposed source name.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

FileDescription
dotnet/src/Microsoft.Agents.AI/OpenTelemetryAgent.csExposes the default telemetry source name.
dotnet/tests/Microsoft.Agents.AI.UnitTests/OpenTelemetryAgentTests.csVerifies the exposed value.
docs/decisions/0003-agent-opentelemetry-instrumentation.mdUses the public API in the example.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment threaddotnet/src/Microsoft.Agents.AI/OpenTelemetryAgent.cs Outdated
@YashvantHange

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

A public const is baked into each consumer assembly at compile time, so a
consumer built against one package version would keep subscribing to the
old literal after upgrading to a version that changed the source name, and
would silently stop receiving spans. That is the exact failure this API is
meant to remove, so expose the value as a static property that is read at
run time.
Rename the test to describe what it actually asserts and point at the
test that verifies emitted activities use the same source name.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentationUsage: [Issues, PRs], Target: documentation in the code base and learn docs.NETUsage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: Microsoft.Agents.AI.OpenTelemetryConsts is internal

2 participants

@YashvantHange