.NET: expose OpenTelemetryAgent.DefaultSourceName - #7815
.NET: expose OpenTelemetryAgent.DefaultSourceName#7815Yashvant Mahadev Hange (YashvantHange) wants to merge 7 commits into
Conversation
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.
There was a problem hiding this comment.
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.
| File | Description |
|---|---|
dotnet/src/Microsoft.Agents.AI/OpenTelemetryAgent.cs |
Exposes the default telemetry source name. |
dotnet/tests/Microsoft.Agents.AI.UnitTests/OpenTelemetryAgentTests.cs |
Verifies the exposed value. |
docs/decisions/0003-agent-opentelemetry-instrumentation.md |
Uses the public API in the example. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
@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.
Roger Barreto (rogerbarreto)
left a comment
There was a problem hiding this comment.
Thanks for the contribution, please also consider updating the wording in the ADR + XmlDocs as suggested, LGTM
The tracing pipeline only receives agent spans when the name registered with TracerProviderBuilder.AddSource matches the source name the agent emits under; a mismatch fails silently. Spell that pairing out in the sourceName XML docs on UseOpenTelemetry and the OpenTelemetryAgent constructors, and in the ADR usage example, which now also shows the custom-source case and uses the AsBuilder().UseOpenTelemetry() API that actually exists.
…default-source-name
DefaultSourceName is a new public API, so gate it behind MAAI001 and graduate it later if it proves useful. The ADR usage section notes that the diagnostic has to be suppressed to use the property.
|
Roger Barreto (@rogerbarreto) please re-review |
…default-source-name
The public API analyzers added in microsoft#7935 require every public member of a released package to be listed in that package's PublicAPI baseline for each target framework. DefaultSourceName was added before those analyzers landed, so this branch built clean on its own but failed RS0016 once merged with main. Add the entry to all five Microsoft.Agents.AI baselines. Unshipped rather than Shipped, since the member has not been released yet; the promotion workflow moves it across after a release.
|
Roger Barreto (@rogerbarreto) this got dequeued from the merge queue on 1 Sep rather than merged, and it needed a change from me to go back in — pushed as The queue build failed Nothing was wrong with the change itself. #7935 added the public API analyzers on 31 Aug, after this branch's last CI run, so the branch built clean in isolation and only failed once the queue merged it with main. Any .NET PR whose last CI run predates that commit and adds public surface will hit the same thing. Fixed by declaring the member in the Could you re-approve and put it back in the queue when you get a chance? |
Motivation & Context
ADR 0003 documents how to subscribe to agent telemetry:
That snippet does not compile against the shipped package.
AgentOpenTelemetryConstswas renamed toOpenTelemetryConstsin #356, and the type isinternal, soDefaultSourceNameis unreachable from outside the assembly. Consumers who want to receiveinvoke_agentspans 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?
OpenTelemetryAgentgains apublic const string DefaultSourceNamethat forwards to the existing internalOpenTelemetryConsts.DefaultSourceName. The constant is placed on the type that emits the spans, soOpenTelemetryConstsand thegen_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.AIsucceed 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
OpenTelemetryAgentis 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 thegen_ai.*attribute keys public is deliberately left out of this change, since it is a larger API commitment.Related Issue
Fixes #6452
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.