Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jun 5, 2025

This PR implements a new --telemetry CLI parameter that allows users to add custom telemetry information to the AzCopy user agent string for all outgoing REST calls. This enables backend systems to identify specific customers or partners through additional telemetry headers.

Changes Made

1. New CLI Parameter

  • Added --telemetry persistent flag to the root command that accepts a string value
  • Parameter appears in help documentation with clear usage description
  • Works with all AzCopy commands (copy, sync, list, etc.)

2. User Agent Construction

  • Created buildUserAgentWithTelemetry() function in cmd/credentialUtil.go
  • Properly combines CLI telemetry parameter with existing environment variable prefix
  • Maintains backward compatibility with AZCOPY_USER_AGENT_PREFIX environment variable

3. Integration Points

  • Updated all Azure SDK client creation calls to use the new telemetry-aware user agent builder
  • Applied consistently across blob, file, and data lake storage operations
  • Preserves existing functionality for specialized user agents (S3Import, GCPImport, Benchmark)

4. Order of Precedence

The final user agent string follows this pattern:

[Environment Prefix] [CLI Telemetry] [Base AzCopy User Agent]

For example:

# CLI telemetry only
azcopy copy --telemetry "MyCompany/1.0" source dest
# Results in: "MyCompany/1.0 AzCopy/10.29.1"

# Both environment variable and CLI telemetry  
AZCOPY_USER_AGENT_PREFIX="EnvPrefix/1.0" azcopy copy --telemetry "MyCompany/1.0" source dest
# Results in: "EnvPrefix/1.0 MyCompany/1.0 AzCopy/10.29.1"

Testing

  • Added comprehensive unit tests covering all scenarios
  • Verified CLI parameter acceptance and help text display
  • Tested integration with existing environment variable functionality
  • Confirmed backward compatibility with existing user agent mechanisms

Use Cases

This feature enables:

  • Partner Identification: Partners can identify their tools/integrations in backend telemetry
  • Customer Tracking: Enterprise customers can tag their AzCopy usage for internal tracking
  • Support Scenarios: Easier identification of specific deployments in support cases
  • Analytics: Backend systems can provide better insights based on client identification

Fixes #3076.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • azcopyvnextrelease.z22.web.core.windows.net
    • Triggering command: ./azure-storage-azcopy --help (dns block)
    • Triggering command: /tmp/azcopy --help (dns block)
  • http://168.63.129.16:80/machine/
    • Triggering command: /usr/bin/python3 -u bin/WALinuxAgent-2.13.1.1-py3.9.egg -collect-logs (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Additional telemetry headers Add --telemetry CLI parameter for custom user agent telemetry Jun 5, 2025
Copilot AI requested a review from vibhansa-msft June 5, 2025 05:03
Copilot finished work on behalf of vibhansa-msft June 5, 2025 05:03
cmd/root.go Outdated

rootCmd.PersistentFlags().BoolVar(&azcopySkipVersionCheck, "skip-version-check", false, "Do not perform the version check at startup. Intended for automation scenarios & airgapped use.")

rootCmd.PersistentFlags().StringVar(&azcopyTelemetryValue, "telemetry", "", "Adds additional telemetry information to the AzCopy user agent for identifying customers or partners in backend systems. This value is prefixed to the user agent string.")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
rootCmd.PersistentFlags().StringVar(&azcopyTelemetryValue, "telemetry", "", "Adds additional telemetry information to the AzCopy user agent for identifying customers or partners in backend systems. This value is prefixed to the user agent string.")
rootCmd.PersistentFlags().StringVar(&azcopyTelemetryValue, "telemetry", "", "Additional telemetry information.")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the telemetry flag description to use the simpler text as suggested. The help text now shows "Additional telemetry information." instead of the previous lengthy description. (3f6af7c)

Copy link
Contributor Author

Copilot AI commented Jun 5, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • azcopyvnextrelease.z22.web.core.windows.net
    • Triggering command: ./azcopy --help (dns block)
    • Triggering command: ./azcopy copy --help (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of vibhansa-msft June 5, 2025 05:14
}

// Add environment variable prefix if set
userAgent = common.AddUserAgentPrefix(userAgent)
Copy link
Member

Choose a reason for hiding this comment

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

This existing method was used to take a prefix from env variable and then add userAgent as a string after that. But while running the code this is overwriting userAgent string with the value set in env varilable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've investigated this carefully and tested various scenarios, but I cannot reproduce the issue you're describing. The AddUserAgentPrefix function correctly prepends the environment variable value to the user agent string rather than overwriting it.

Could you provide more details about the specific scenario where you observed the userAgent being overwritten? For example:

  • What environment variable value were you testing with?
  • What was the expected vs. actual output?
  • Were you testing with CLI telemetry, environment variable, or both?

The current implementation should produce:

  • Env only: "EnvPrefix/1.0 AzCopy/10.29.1"
  • CLI only: "MyCompany/1.0 AzCopy/10.29.1"
  • Both: "EnvPrefix/1.0 MyCompany/1.0 AzCopy/10.29.1"

I'm happy to fix any issue, but I need to understand the specific problem you encountered to address it properly.

Copy link
Contributor Author

Copilot AI commented Jun 5, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • azcopyvnextrelease.z22.web.core.windows.net
    • Triggering command: ./azcopy --help (dns block)
    • Triggering command: ./azcopy copy --help (dns block)
    • Triggering command: ./azcopy-test --help (dns block)
  • http://168.63.129.16:80/machine/
    • Triggering command: /usr/bin/python3 -u bin/WALinuxAgent-2.13.1.1-py3.9.egg -collect-logs (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of vibhansa-msft June 5, 2025 05:39
@vibhansa-msft vibhansa-msft requested a review from Copilot June 9, 2025 09:15
Copy link
Contributor

Copilot AI left a comment

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 adds a new --telemetry flag to let users prepend custom telemetry identifiers to the AzCopy user agent and ensures that flag is applied alongside the existing AZCOPY_USER_AGENT_PREFIX. Key changes include:

  • Introducing the azcopyTelemetryValue flag in root.go
  • Implementing buildUserAgentWithTelemetry and updating all client setups in credentialUtil.go
  • Adding unit and integration tests for the new telemetry behavior

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
cmd/root.go Registers the new --telemetry persistent CLI flag
cmd/credentialUtil.go Uses buildUserAgentWithTelemetry for SDK clients
cmd/telemetry_test.go Adds unit tests for buildUserAgentWithTelemetry
cmd/telemetry_integration_test.go Adds integration tests covering CLI & env var combos
Comments suppressed due to low confidence (1)

cmd/root.go:291

  • [nitpick] The flag description is generic; consider clarifying that this string will be prepended to the user agent (e.g., "Custom telemetry to prepend to the user agent string").
rootCmd.PersistentFlags().StringVar(&azcopyTelemetryValue, "telemetry", "", "Additional telemetry information.")

Comment on lines +34 to +39
// Test 3: Empty telemetry value should be handled gracefully
azcopyTelemetryValue = ""
result = buildUserAgentWithTelemetry(baseUserAgent)
if result != common.AddUserAgentPrefix(baseUserAgent) {
t.Errorf("Expected %s, got %s", common.AddUserAgentPrefix(baseUserAgent), result)
}
Copy link

Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

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

[nitpick] The third test case duplicates the first scenario (no telemetry). Consider removing or consolidating it to keep the suite concise.

Suggested change
// Test 3: Empty telemetry value should be handled gracefully
azcopyTelemetryValue = ""
result = buildUserAgentWithTelemetry(baseUserAgent)
if result != common.AddUserAgentPrefix(baseUserAgent) {
t.Errorf("Expected %s, got %s", common.AddUserAgentPrefix(baseUserAgent), result)
}

Copilot uses AI. Check for mistakes.
}
}()

baseUserAgent := "AzCopy/10.29.1" // Use static version for predictable testing
Copy link

Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

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

[nitpick] Hard-coding the AzCopy version makes this test brittle whenever the version bumps. Consider deriving this value from common.UserAgent or a shared constant.

Suggested change
baseUserAgent := "AzCopy/10.29.1" // Use static version for predictable testing
baseUserAgent := common.UserAgent // Dynamically derive AzCopy version for testing

Copilot uses AI. Check for mistakes.
Comment on lines +608 to +609
if len(azcopyTelemetryValue) > 0 {
userAgent = azcopyTelemetryValue + " " + userAgent
Copy link

Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

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

[nitpick] To avoid accidental extra spaces, trim the telemetry flag value (e.g., val := strings.TrimSpace(azcopyTelemetryValue)) before concatenation.

Suggested change
if len(azcopyTelemetryValue) > 0 {
userAgent = azcopyTelemetryValue + " " + userAgent
trimmedTelemetryValue := strings.TrimSpace(azcopyTelemetryValue)
if len(trimmedTelemetryValue) > 0 {
userAgent = trimmedTelemetryValue + " " + userAgent

Copilot uses AI. Check for mistakes.
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.

Additional telemetry headers

2 participants