Repository navigation
[Monitor] az monitor trace-association, az monitor account trace-container: Add preview command groups for distributed traces - #34263
Conversation
…ontainer`: Add preview command groups for distributed traces Route distributed traces from an Application Insights component, resource group or subscription to an Azure Monitor workspace with one command, `az monitor trace-association create --resource-uri`. It creates the workspace's trace container first if it has none and never changes an existing one. Replacing the workspace of a resource group or subscription, and deleting its association, ask for confirmation. The commands use Microsoft.Monitor 2026-09-03-preview through AAZ models from Azure/aaz#1131. The per-scope association commands are generated as unregistered helpers that the --resource-uri commands dispatch to. `trace-container create` keeps the current value of settings it is not given. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3fea4286-bba0-4628-84dc-866644c2595b
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
…and when settings conflict When explicit --trace-retention-days or --trace-metrics differ from the workspace's existing trace container, the error now says what the shared container keeps and recommends the exact `az monitor account trace-container update` command, or running without the flags. The container is still never changed by onboarding. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3fea4286-bba0-4628-84dc-866644c2595b
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
…ces needs write access on the workspace Access denied while reading or creating the trace container, and the LinkedAuthorizationFailed error that ARM returns when the caller cannot write the workspace, now explain that write access on the workspace is needed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3fea4286-bba0-4628-84dc-866644c2595b
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
There was a problem hiding this comment.
🟡 Changes recommended
Updating metrics or the duration window on a legacy container without traceRetentionInDays fails before the PUT, requiring default-handling logic and a regression test.
1 open issue
What changed in this PR
Adds preview distributed-tracing commands to Azure CLI’s Monitor module using the 2026-09-03-preview API.
Changes:
- Adds scope-based trace associations with inheritance reporting and confirmation for resource-group and subscription changes.
- Adds trace-container management, automatic creation, settings preservation, and validation.
- Adds command help, unit tests, scenario tests, and a trace-container recording.
Paths below are relative to src/azure-cli/azure/cli/command_modules/monitor/.
| File | Description |
|---|---|
tests/latest/test_monitor_unittest.py |
Tests scope parsing, settings, conflicts, and access errors. |
tests/latest/test_monitor_trace_scenario.py |
Exercises container and association workflows. |
tests/latest/recordings/test_monitor_trace_container.yaml |
Records trace-container scenario requests and responses. |
operations/trace_container.py |
Validates workspaces and manages container prerequisites. |
operations/trace_association.py |
Dispatches scope operations and reports trace destinations. |
operations/latest/monitor/account/trace_container/_create.py |
Preserves existing settings and supplies creation defaults. |
operations/latest/monitor/account/trace_container/__init__.py |
Initializes the container customization package. |
operations/latest/monitor/account/__init__.py |
Initializes the account customization package. |
commands.py |
Registers preview trace-association commands. |
aaz/latest/monitor/trace_association/subscription/_show.py |
Adds the subscription association read helper. |
aaz/latest/monitor/trace_association/subscription/_list.py |
Adds the subscription association list helper. |
aaz/latest/monitor/trace_association/subscription/_delete.py |
Adds the subscription association delete helper. |
aaz/latest/monitor/trace_association/subscription/_create.py |
Adds the subscription association write helper. |
aaz/latest/monitor/trace_association/subscription/__init__.py |
Initializes subscription helpers without eager imports. |
aaz/latest/monitor/trace_association/subscription/__cmd_group.py |
Defines unregistered subscription group metadata. |
aaz/latest/monitor/trace_association/resource/_show.py |
Adds the component association read helper. |
aaz/latest/monitor/trace_association/resource/_list.py |
Adds the component association list helper. |
aaz/latest/monitor/trace_association/resource/_delete.py |
Adds the component association delete helper. |
aaz/latest/monitor/trace_association/resource/_create.py |
Adds the component association write helper. |
aaz/latest/monitor/trace_association/resource/__init__.py |
Initializes component helpers without eager imports. |
aaz/latest/monitor/trace_association/resource/__cmd_group.py |
Defines unregistered component group metadata. |
aaz/latest/monitor/trace_association/resource_group/_show.py |
Adds the resource-group association read helper. |
aaz/latest/monitor/trace_association/resource_group/_list.py |
Adds the resource-group association list helper. |
aaz/latest/monitor/trace_association/resource_group/_delete.py |
Adds the resource-group association delete helper. |
aaz/latest/monitor/trace_association/resource_group/_create.py |
Adds the resource-group association write helper. |
aaz/latest/monitor/trace_association/resource_group/__init__.py |
Initializes resource-group helpers without eager imports. |
aaz/latest/monitor/trace_association/resource_group/__cmd_group.py |
Defines unregistered resource-group metadata. |
aaz/latest/monitor/trace_association/__init__.py |
Initializes the generated association package. |
aaz/latest/monitor/trace_association/__cmd_group.py |
Defines unregistered association group metadata. |
aaz/latest/monitor/account/trace_container/_wait.py |
Adds container condition polling. |
aaz/latest/monitor/account/trace_container/_update.py |
Adds container settings updates. |
aaz/latest/monitor/account/trace_container/_show.py |
Adds container retrieval. |
aaz/latest/monitor/account/trace_container/_create.py |
Adds container creation and operation polling. |
aaz/latest/monitor/account/trace_container/__init__.py |
Initializes container commands without eager imports. |
aaz/latest/monitor/account/trace_container/__cmd_group.py |
Registers the preview container command group. |
_params.py |
Defines association arguments and settings options. |
_help.py |
Documents association behavior and examples. |
Review effort: Balanced
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5f924a07-a586-442e-97de-0529c398c64d
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
Please fix CI issues |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5f924a07-a586-442e-97de-0529c398c64d
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
The ci test failures look like timeouts in the build pipeline and unrelated to my change? Yong Zhang (@yonzhan) Unit Test for Core Python314: Unit Test for Telemetry Python312: Unit Test for Telemetry Python314: |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
bragi92 Resolve the legacy-update and generated-source findings before merge. Scenario coverage is unverified. To addressTick each item as you address it.
Review detailsUpstream CI52 successful completed checks; no CI failures in the handoff. Test validation
Author evidence under Risk assessment55/100 · High The High rating is driven by public CLI behavior, failure-handling behavior, generated output.
Ask the Agent Tick a box to queue an action. Requires write access to this repository.
|
mansoor sarfraz (msarfraz)
left a comment
There was a problem hiding this comment.
LGTM. Please make sure Azure/aaz#1131 is merged before (or together with) this PR so the generated command models and the CLI stay in sync.

🤖 PR Validation —⚠️ Review suggested
This PR adds warning or check suppressions. Fix the underlying warning where possible and justify each remaining suppression in a code comment or the PR description.
1 added suppression
src/azure-cli/azure/cli/command_modules/monitor/operations/trace_association.pyclass _Scope: # pylint: disable=too-few-public-methodsRelated command
az monitor trace-association create/show/list/deleteaz monitor account trace-container create/show/update/waitDescription
Adds preview commands for distributed traces in Azure Monitor, on
Microsoft.Monitor2026-09-03-preview.az monitor trace-association create --resource-uri <scope> --azure-monitor-workspace <workspace id>routes the traces of an Application Insights component, a resource group or a subscription to an Azure Monitor workspace. One command covers every scope;--resource-uripicks the API path.Enabledunless--trace-retention-daysor--trace-metricssay otherwise. An existing container is never changed, and explicit settings that differ from it fail.--yesskips it), because everything under that scope stops sending traces to the old workspace unless another association routes them there.showreturns the association at exactly the scope,listadds the inherited ones, anddeleteremoves only the scope's own association. Deleting at a resource group or subscription asks for confirmation; deleting where nothing is configured is a no-op.az monitor account trace-container create/show/update/waitmanage the workspace's trace container.createkeeps the current value of any setting it is not given, and uses the defaults above for a new container.Implementation notes:
--resource-uricommands dispatch to them.az monitor slionboarding: generated packages keep empty__init__.pyfiles for args-guided loading. Thetrace-container createoverride lives in theoperations/latesttree.Testing Guide
test_monitor_trace_scenario.py: two scenario tests, recorded live ineastus2euap. Trace containers and Application Insights trace associations are only created in regions with traces enabled, and canary regions get them first.test_monitor_unittest.py: unit tests for--resource-uriparsing, workspace ID validation and container settings.azdev linter monitorpasses. flake8 and pylint are clean on the changed files.History Notes
[Monitor]
az monitor trace-association: Add preview command group to route distributed traces from an Application Insights component, resource group or subscription to an Azure Monitor workspace[Monitor]
az monitor account trace-container: Add preview command group to manage the trace container of an Azure Monitor workspaceThis checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.