Skip to content

fix: add ms-fabric-cli user agent to cicd when running deploy cmd#269

Open
aviatco wants to merge 1 commit into
microsoft:mainfrom
aviatco:dev/aviatcohen/fix-deploy-cmd-telemetry
Open

fix: add ms-fabric-cli user agent to cicd when running deploy cmd#269
aviatco wants to merge 1 commit into
microsoft:mainfrom
aviatco:dev/aviatcohen/fix-deploy-cmd-telemetry

Conversation

@aviatco

@aviatco aviatco commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

📥 Pull Request

✨ Description of new changes

This pull request refactors how the Fabric CLI sets and manages the User-Agent string for deployment commands, making it easier to attribute deployments and improving telemetry for the Fabric CICD service. The logic for building and resolving User-Agent strings is now centralized in a new utility module, and the deployment command ensures that the correct User-Agent is always set, regardless of user input. Comprehensive tests have been added and updated to verify this behavior.

User-Agent construction and attribution:

  • Introduced a new utility module fab_user_agent.py that centralizes logic for building the User-Agent string (build_user_agent) and resolving library versions for attribution (resolve_library_user_agent). This ensures consistent and maintainable User-Agent formatting across the CLI.
  • Updated the deployment command in fab_fs_deploy_config_file.py to always set a CLI-controlled User-Agent, combining both the CICD library version and the CLI's own User-Agent. This prevents users from spoofing the User-Agent via parameters and enables accurate attribution for telemetry and analytics. [1] [2]

Refactoring and code cleanup:

  • Removed the old User-Agent construction logic from fab_api_client.py and replaced it with calls to the new utility functions, simplifying the client code and removing redundant code. [1] [2] [3] [4]

Testing improvements:

  • Added a new test module test_fab_user_agent.py to thoroughly test User-Agent construction, environment variable handling, and library version resolution.
  • Updated deployment tests to verify that the correct User-Agent is passed and cannot be overridden by user-supplied parameters.
  • Moved and consolidated tests for host app suffix logic from test_fab_api_client.py to test_fab_user_agent.py for better organization. [1] [2]

Documentation and changelog:

  • Added a changelog entry describing the fix and the benefits of the new User-Agent attribution for deployments.

@aviatco
aviatco requested a review from a team as a code owner July 26, 2026 14:50
Copilot AI review requested due to automatic review settings July 26, 2026 14:50

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.

Pull request overview

This PR centralizes Fabric CLI User-Agent construction into a dedicated utility module and ensures the deploy command always sets a CLI-controlled User-Agent (optionally prefixed with the fabric-cicd library version) to improve attribution/telemetry for CICD-triggered deployments.

Changes:

  • Added fab_user_agent.py utility with shared build_user_agent(...) and resolve_library_user_agent(...) helpers (including host-app suffix handling).
  • Updated API request handling and deploy_with_config_file to use the centralized User-Agent logic and enforce a CLI-controlled deploy User-Agent.
  • Added/updated tests to validate User-Agent behavior and moved host-app suffix tests into the new utility test module; added a changelog entry.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/fabric_cli/utils/fab_user_agent.py New shared utility for building CLI User-Agent strings and resolving host library versions.
src/fabric_cli/client/fab_api_client.py Replaces inline User-Agent construction with the new shared utility.
src/fabric_cli/commands/fs/deploy/fab_fs_deploy_config_file.py Forces CLI-controlled User-Agent for deploy runs (with optional CICD prefix).
tests/test_utils/test_fab_user_agent.py New unit tests for the new User-Agent utility functions.
tests/test_core/test_fab_api_client.py Removes host-app suffix tests that moved to the new utility test module.
tests/test_commands/test_deploy.py Adds deploy-specific tests to assert CICD-prefixed User-Agent behavior and prevent spoofing via params.
.changes/unreleased/fixed-20260726-120000.yaml Changelog entry documenting the deployment User-Agent attribution fix.

from fabric_cli.core.fab_exceptions import FabricCLIError
from fabric_cli.core.fab_msal_bridge import create_fabric_token_credential
from fabric_cli.utils import fab_ui
from fabric_cli.utils.fab_user_agent import build_user_agent, resolve_library_user_agent
Comment on lines +69 to +72
with patch(
"fabric_cli.utils.fab_user_agent.importlib.metadata.version",
side_effect=importlib.metadata.PackageNotFoundError,
):
@@ -0,0 +1,6 @@
kind: fixed
body: Set User Agent suffix for Fabric CLI deploy command. This allows the Fabric CICD service to identify the host application that is invoking the deployment, which can be useful for logging, analytics, and debugging purposes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why all these changes? only need to tell cicd on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants