Repository navigation
Stop dotnet CLI from exporting its own OTLP telemetry for project resources - #21454
Karol Zadora-Przylecki (karolz-ms) merged 1 commit into
Conversation
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]>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21454Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21454" |
Tests selector52 / 100 PR test projects · 4 PR jobs, from 2 changed files. Selected PR test projects (52 / 100)
Selected PR jobs (4)
How these were chosen — grouped by what changed
🔧 show 46
🧪 📦 affected project 📦 affected project Job reasons
Selection computed for commit |
There was a problem hiding this comment.
🟢 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=trueinWithProjectDefaultsonly 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
ec4cc67
into
main
|
Pull request created: #2000
|
|
📝 Documentation has been drafted in microsoft/aspire.dev#2000 targeting No gating signals fired (docs_optional), but the PR changes user-visible behavior: project resources now get Note This draft PR needs human review before merging. |
) 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 -->
Description
Fixes #20885
On the .NET 11 SDK, every
dotnet run/dotnet watchprocess that Aspire launches for a project resource exports its own OTLP telemetry to the dashboard. Each one appears as an unattributeddotnet-cli-<id>resource withdotnet-cli: telemetry-setupand long-runningdotnet-cli: dotnet runspans.Root cause
The .NET 11 CLI turns on its OTLP exporter (hard-coded service name
dotnet-cli) whenever standardOTEL_EXPORTER_OTLP_*variables are set (SDK telemetry docs). Aspire sets those variables on project resources so the app can export to the dashboard. The launchingdotnetprocess inherits the same environment, so it exports too.DOTNET_CLI_TELEMETRY_DISABLE_TRACE_EXPORTonly disables the Azure Monitor exporter, not OTLP. Of the CLI's settings, onlyDOTNET_CLI_TELEMETRY_OPTOUTdisables the CLI's telemetry providers without changing the app's ownOTEL_*configuration. SettingOTEL_SDK_DISABLEDwould also turn off the app's telemetry.Fix
WithProjectDefaults(used byAddProject,AddCSharpAppandAddDotnetProject) now setsDOTNET_CLI_TELEMETRY_OPTOUT=truein 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, runningdotnet runagainst 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):dotnet-cliresourcedotnet run/telemetry-setupspans/v1/traces+/v1/metrics)DOTNET_CLI_TELEMETRY_OPTOUT=1)The app itself still ran normally in both cases.
Validation
ProjectResourceTests.AddProjectAddsEnvironmentVariablesAndServiceMetadataasserts the exact run-mode environment. It fails onmainfor both cases (Expected: "DOTNET_CLI_TELEMETRY_OPTOUT") and passes with the fix.ProjectResourceTests,KestrelConfigTests,ManifestGenerationTests,WithOtlpExporterTestsandExecutableLaunchRecipeTestspass (95/95).Aspire.Hosting.Dotnet.Testspasses (201/201).Aspire.Hosting.Testslocally: the only failures are environmental (no IPv6, no dev certificate, Docker build, timing under disk pressure). Each either fails the same way onmainor passes on rerun with the fix.Checklist
🤖 Posted by AspireAgent (AI Agent)