Skip to content

Stop dotnet CLI from exporting its own OTLP telemetry for project resources - #21454

Merged
Karol Zadora-Przylecki (karolz-ms) merged 1 commit into
mainfrom
aspireagent/fix-20885-dotnet-cli-otel
Oct 30, 2026
Merged

Karol Zadora-Przylecki (karolz-ms) merged 1 commit into
mainfrom
aspireagent/fix-20885-dotnet-cli-otel

Conversation

@davidfowl

@davidfowl David Fowler (davidfowl) commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Fixes #20885

On the .NET 11 SDK, every dotnet run/dotnet watch process that Aspire launches for a project resource exports its own OTLP telemetry to the dashboard. Each one appears as an unattributed dotnet-cli-<id> resource with dotnet-cli: telemetry-setup and long-running dotnet-cli: dotnet run spans.

Root cause

The .NET 11 CLI turns on its OTLP exporter (hard-coded service name dotnet-cli) whenever standard OTEL_EXPORTER_OTLP_* variables are set (SDK telemetry docs). Aspire sets those variables on project resources so the app can export to the dashboard. The launching dotnet process inherits the same environment, so it exports too.

DOTNET_CLI_TELEMETRY_DISABLE_TRACE_EXPORT only disables the Azure Monitor exporter, not OTLP. Of the CLI's settings, only DOTNET_CLI_TELEMETRY_OPTOUT disables the CLI's telemetry providers without changing the app's own OTEL_* configuration. Setting OTEL_SDK_DISABLED would also turn off the app's telemetry.

Fix

WithProjectDefaults (used by AddProject, AddCSharpApp and AddDotnetProject) now sets DOTNET_CLI_TELEMETRY_OPTOUT=true in run mode. Publish output is unchanged.

Before / after evidence

I reproduced this with the repo's .NET SDK 11.0.100-rc.2.26504.105, running dotnet run against a local OTLP/HTTP capture listener. The environment matched what Aspire gives a project (OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_PROTOCOL, OTEL_SERVICE_NAME=apiservice):

OTLP payloads captured dotnet-cli resource dotnet run / telemetry-setup spans
Before (current env) 6 (/v1/traces + /v1/metrics) yes yes
After (DOTNET_CLI_TELEMETRY_OPTOUT=1) 0 no no

The app itself still ran normally in both cases.

Validation

  • Regression test: ProjectResourceTests.AddProjectAddsEnvironmentVariablesAndServiceMetadata asserts the exact run-mode environment. It fails on main for both cases (Expected: "DOTNET_CLI_TELEMETRY_OPTOUT") and passes with the fix.
  • ProjectResourceTests, KestrelConfigTests, ManifestGenerationTests, WithOtlpExporterTests and ExecutableLaunchRecipeTests pass (95/95).
  • Aspire.Hosting.Dotnet.Tests passes (201/201).
  • Full Aspire.Hosting.Tests locally: the only failures are environmental (no IPv6, no dev certificate, Docker build, timing under disk pressure). Each either fails the same way on main or passes on rerun with the fix.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No

🤖 Posted by AspireAgent (AI Agent)

Starting with .NET 11, the dotnet CLI exports its own traces and metrics
(service name "dotnet-cli") over OTLP whenever standard OTEL_EXPORTER_OTLP_*
variables are present. Project resources are launched via `dotnet run` /
`dotnet watch` with the app's environment, so the CLI showed up in the
dashboard as unattributed dotnet-cli-<id> resources with long-running
"dotnet run" spans. Set DOTNET_CLI_TELEMETRY_OPTOUT for project resources in
run mode; DOTNET_CLI_TELEMETRY_DISABLE_TRACE_EXPORT only affects the Azure
Monitor exporter.

Fixes #20885

Co-authored-by: Copilot <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21454

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21454"

@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

52 / 100 PR test projects · 4 PR jobs, from 2 changed files.

Selected PR test projects (52 / 100)

Aspire.Cli.EndToEnd.Tests, Aspire.Hosting.Analyzers.Tests, Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Kubernetes.Tests, Aspire.Hosting.Azure.Kusto.Tests, Aspire.Hosting.Azure.Provisioning.Tests, Aspire.Hosting.Azure.Tests, Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Browsers.Tests, Aspire.Hosting.CodeGeneration.Go.Tests, Aspire.Hosting.CodeGeneration.Java.Tests, Aspire.Hosting.CodeGeneration.Python.Tests, Aspire.Hosting.CodeGeneration.Rust.Tests, Aspire.Hosting.CodeGeneration.TypeScript.Tests, Aspire.Hosting.Containers.Tests, Aspire.Hosting.DevTunnels.Tests, Aspire.Hosting.Docker.Tests, Aspire.Hosting.Dotnet.Tests, Aspire.Hosting.DotnetTool.Tests, Aspire.Hosting.EntityFrameworkCore.Tests, Aspire.Hosting.Foundry.Tests, Aspire.Hosting.Garnet.Tests, Aspire.Hosting.Go.Tests, Aspire.Hosting.Java.Tests, Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Kafka.Tests, Aspire.Hosting.Keycloak.Tests, Aspire.Hosting.Kubernetes.Tests, Aspire.Hosting.Maui.Tests, Aspire.Hosting.Milvus.Tests, Aspire.Hosting.MongoDB.Tests, Aspire.Hosting.MySql.Tests, Aspire.Hosting.Nats.Tests, Aspire.Hosting.OpenAI.Tests, Aspire.Hosting.Oracle.Tests, Aspire.Hosting.Orleans.Tests, Aspire.Hosting.PostgreSQL.Tests, Aspire.Hosting.Python.Tests, Aspire.Hosting.Qdrant.Tests, Aspire.Hosting.RabbitMQ.Tests, Aspire.Hosting.Radius.Tests, Aspire.Hosting.Redis.Tests, Aspire.Hosting.RemoteHost.Tests, Aspire.Hosting.Rust.Tests, Aspire.Hosting.Seq.Tests, Aspire.Hosting.SqlServer.Tests, Aspire.Hosting.Testing.Tests, Aspire.Hosting.Tests, Aspire.Hosting.Valkey.Tests, Aspire.Hosting.Yarp.Tests, Aspire.Playground.Tests, Aspire.Templates.Tests

Selected PR jobs (4)

cli-starter-validation, extension-e2e, polyglot, typescript-api-compat


How these were chosen — grouped by what changed

⚠️ 46 of the 52 selected test projects come from a single change — src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs.

🔧 src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs (changed source)
→ 46 via the project graph

show 46

Aspire.Hosting.Analyzers.Tests (2 hops), Aspire.Hosting.Azure.EntraId.Tests (2 hops), Aspire.Hosting.Azure.Kubernetes.Tests (2 hops), Aspire.Hosting.Azure.Kusto.Tests (2 hops), Aspire.Hosting.Azure.Provisioning.Tests (3 hops), Aspire.Hosting.Azure.Tests, Aspire.Hosting.Browsers.Tests (2 hops), Aspire.Hosting.CodeGeneration.Go.Tests, Aspire.Hosting.CodeGeneration.Java.Tests, Aspire.Hosting.CodeGeneration.Python.Tests, Aspire.Hosting.CodeGeneration.Rust.Tests, Aspire.Hosting.CodeGeneration.TypeScript.Tests, Aspire.Hosting.Containers.Tests (2 hops), Aspire.Hosting.DevTunnels.Tests (2 hops), Aspire.Hosting.Docker.Tests (2 hops), Aspire.Hosting.DotnetTool.Tests (2 hops), Aspire.Hosting.EntityFrameworkCore.Tests (2 hops), Aspire.Hosting.Foundry.Tests (2 hops), Aspire.Hosting.Garnet.Tests (2 hops), Aspire.Hosting.Go.Tests (2 hops), Aspire.Hosting.Java.Tests (2 hops), Aspire.Hosting.JavaScript.Tests (2 hops), Aspire.Hosting.Kafka.Tests (2 hops), Aspire.Hosting.Keycloak.Tests (2 hops), Aspire.Hosting.Kubernetes.Tests (2 hops), Aspire.Hosting.Maui.Tests, Aspire.Hosting.Milvus.Tests (2 hops), Aspire.Hosting.MongoDB.Tests (2 hops), Aspire.Hosting.MySql.Tests (2 hops), Aspire.Hosting.Nats.Tests (2 hops), Aspire.Hosting.OpenAI.Tests (2 hops), Aspire.Hosting.Oracle.Tests (2 hops), Aspire.Hosting.Orleans.Tests (2 hops), Aspire.Hosting.PostgreSQL.Tests (2 hops), Aspire.Hosting.Python.Tests (2 hops), Aspire.Hosting.Qdrant.Tests (2 hops), Aspire.Hosting.RabbitMQ.Tests (2 hops), Aspire.Hosting.Redis.Tests (2 hops), Aspire.Hosting.RemoteHost.Tests, Aspire.Hosting.Rust.Tests (2 hops), Aspire.Hosting.Seq.Tests (2 hops), Aspire.Hosting.SqlServer.Tests (2 hops), Aspire.Hosting.Testing.Tests (2 hops), Aspire.Hosting.Valkey.Tests (2 hops), Aspire.Hosting.Yarp.Tests (2 hops), Aspire.Playground.Tests

🧪 tests/Aspire.Hosting.Tests/ProjectResourceTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests
→ 3 via the project graph: Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Dotnet.Tests, Aspire.Hosting.Radius.Tests

📦 affected project Aspire.Hosting.Dotnet
→ 2 tests: Aspire.Cli.EndToEnd.Tests, Aspire.Templates.Tests

📦 affected project Aspire.Hosting
→ 1 test: Aspire.Cli.EndToEnd.Tests

Job reasons

Job Triggered by
cli-starter-validation affected project Aspire.Hosting.AppHost
extension-e2e • src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs
• affected project Aspire.Hosting
polyglot • affected project Aspire.Hosting
• affected project Aspire.Hosting.Azure.Provisioning.KeyVault
typescript-api-compat affected project Aspire.Hosting

Selection computed for commit ff22e14.

Copilot AI 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.

🟢 Approval recommended

No active review issues remain for the change that disables .NET CLI telemetry for project resources in run mode.

No open issues 🎉

What changed in this PR

Fixes #20885 by preventing .NET CLI processes launched for project resources from sending unrelated telemetry to the Aspire dashboard, while preserving application telemetry.

Changes:

  • Sets DOTNET_CLI_TELEMETRY_OPTOUT=true in WithProjectDefaults only in run mode, leaving publish output unchanged.
  • Updates the project-resource regression test to assert the new environment setting.
File Description
tests/​Aspire.Hosting.Tests/​ProjectResourceTests.cs Asserts the CLI telemetry opt-out setting in the expected environment.
src/​Aspire.Hosting/​ProjectResourceBuilderExtensions.cs Disables CLI telemetry for project resources in run mode and documents why.

Review effort: Balanced

@karolz-ms
Karol Zadora-Przylecki (karolz-ms) merged commit ec4cc67 into main Oct 30, 2026
691 of 695 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.0 milestone Oct 30, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

Pull request created: #2000

Generated by PR Documentation Check · copilot · auto · 26.9 AIC · ⌖ 1.14 AIC · ⊞ 7.1K

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

📝 Documentation has been drafted in microsoft/aspire.dev#2000 targeting release/17.0.

No gating signals fired (docs_optional), but the PR changes user-visible behavior: project resources now get DOTNET_CLI_TELEMETRY_OPTOUT=true in run mode. Added a note to fundamentals/telemetry.mdx.

Note

This draft PR needs human review before merging.

Karol Zadora-Przylecki (karolz-ms) added a commit to microsoft/aspire.dev that referenced this pull request Nov 14, 2026
)

Documents changes from microsoft/aspire#21454

Author: ``@karolz-ms-independent-of-author-see-sou``rce-pr

Targeting `release/17.0` based on the source PR milestone `17.0`
(`target_resolution`: `exact_match`).

## Why
No deterministic signals fired, but the source PR changes user-visible
behavior: `WithProjectDefaults` now sets
`DOTNET_CLI_TELEMETRY_OPTOUT=true` in run mode, so the .NET 11 `dotnet
run`/`dotnet watch` processes no longer export their own OTLP telemetry
(the unattributed `dotnet-cli-<id>` resource in the dashboard). The
telemetry docs describe the environment variables Aspire sets, so they
needed this addition.

## Changes
- Updated (existing page):
`src/frontend/src/content/docs/fundamentals/telemetry.mdx` — added a
note in "OpenTelemetry environment variables".

> Generated by [PR Documentation
Check](https://github.com/microsoft/aspire/actions/runs/41084390203) for
#21454 · copilot · auto · 26.9 AIC · ⌖ 1.14 AIC · ⊞ 7.1K ·
[◷](https://github.com/search?q=repo%3Amicrosoft%2Faspire.dev+%22gh-aw-workflow-id%3A+pr-docs-check%22&type=pullrequests)

<!-- gh-aw-agentic-workflow: PR Documentation Check, engine: copilot,
model: auto, id: 41084390203, workflow_id: pr-docs-check, run:
https://github.com/microsoft/aspire/actions/runs/41084390203 -->

<!-- gh-aw-workflow-id: pr-docs-check -->
<!-- gh-aw-workflow-call-id: microsoft/aspire/pr-docs-check -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.Net 11 adds unattributed dotnet-cli otel resources / spans

3 participants