Map package-level error variables to meaningful telemetry codes - #6865
Conversation
Previously, package-level error variables like ErrNoCurrentUser fell through to the default case in MapError, producing unhelpful telemetry codes like 'internal.errors_errorString' (or 'UnknownError' in versions prior to v1.22.4). This made it difficult to diagnose common failures like 'not logged in' from telemetry data. Changes: - Add explicit errors.Is() mappings in MapError for 6 error variables: - auth.ErrNoCurrentUser -> auth.not_logged_in - consent.ErrToolExecutionDenied -> user.tool_denied - git.ErrNotRepository -> internal.not_git_repo - azapi.ErrPreviewNotSupported -> internal.preview_not_supported - provisioning.ErrBindMountOperationDisabled -> internal.bind_mount_disabled - pipeline.ErrRemoteHostIsNotAzDo -> internal.remote_not_azdo - Replace hardcoded 'UnknownError' in EndWithStatus (tracer.go) with the error's type name, matching the pattern already used in MapError. - Add Test_PackageLevelErrorsMapped enforcement test that scans the codebase for 'var Err* = errors.New/fmt.Errorf' definitions and fails CI if any are not mapped in MapError or explicitly excluded. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves telemetry usefulness by ensuring common package-level sentinel errors are mapped to stable, meaningful telemetry codes, and by making span status descriptions more descriptive than a generic "UnknownError".
Changes:
- Added explicit
errors.Ismappings ininternal/cmd/MapErrorfor several package-levelErr*variables to produce meaningful telemetry codes. - Updated
Span.EndWithStatusto set the span status description based on the error type name instead of"UnknownError". - Added an enforcement test intended to detect newly introduced package-level
Err*variables and require they be mapped (or explicitly excluded).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
cli/azd/internal/tracing/tracer.go |
Replaces "UnknownError" span status descriptions with a type-derived error description. |
cli/azd/internal/cmd/errors.go |
Adds errors.Is mappings for several sentinel errors to produce specific telemetry codes. |
cli/azd/internal/cmd/errors_test.go |
Adds test coverage for the new mappings and introduces an enforcement-style scan for unmapped package-level errors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…nforcement test - errorDescription now unwraps errors (Unwrap() error and Unwrap() []error) to find root cause types instead of reporting wrapper types like fmt.wrapError - Enforcement test uses go/parser + go/ast to detect var blocks (var (...)) instead of single-line regex, catching all package-level error variables - Fix gofmt formatting Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
Summary
Package-level error variables (like
ErrNoCurrentUser) fell through to the default case inMapError, producing unhelpful telemetry codes likeinternal.errors_errorStringorUnknownError. This made it hard to diagnose common failures from telemetry.Changes
Explicit error mappings in
MapError(errors.go)auth.ErrNoCurrentUserauth.not_logged_inconsent.ErrToolExecutionDenieduser.tool_deniedgit.ErrNotRepositoryinternal.not_git_repoazapi.ErrPreviewNotSupportedinternal.preview_not_supportedprovisioning.ErrBindMountOperationDisabledinternal.bind_mount_disabledpipeline.ErrRemoteHostIsNotAzDointernal.remote_not_azdoFix
EndWithStatus(tracer.go)Replaced hardcoded
"UnknownError"with error type unwrapping (handles bothUnwrap() errorandUnwrap() []error), matchingMapError's existing pattern. No PII risk — only Go type names are emitted.Enforcement test (
errors_test.go)Test_PackageLevelErrorsMappedusesgo/parser+go/astto scan the codebase forvar Err* = errors.New/fmt.Errorf(includingvar (...)blocks) and fails CI if any are unmapped or unexcluded.Testing
Test_MapErrorcases covering all mappings (including wrapped errors)