Skip to content

Allow passing in custom tags to telemetry#1723

Merged
derekmisler merged 1 commit intodocker:mainfrom
derekmisler:how-can-we-track-usage
Feb 13, 2026
Merged

Allow passing in custom tags to telemetry#1723
derekmisler merged 1 commit intodocker:mainfrom
derekmisler:how-can-we-track-usage

Conversation

@derekmisler
Copy link
Contributor

@derekmisler derekmisler commented Feb 13, 2026

Closes: https://github.com/docker/gordon/issues/121

Add support for a TELEMETRY_TAGS environment variable that allows callers to attach custom key-value metadata to every telemetry event. This enables tracking where and how the binary is invoked (e.g., GitHub Actions, specific repos, workflows) without hardcoding provider-specific logic into the binary itself.

Changes

  • pkg/telemetry/http.go: Parse TELEMETRY_TAGS env var (comma-separated key=value pairs) in createEvent() and merge them into event properties. System metadata (user_uuid, version, os, os_language) is written after tags to prevent spoofing. Empty keys and malformed entries (missing =) are silently ignored. Whitespace around keys and values is trimmed.
  • pkg/telemetry/telemetry_test.go: Add two test suites:
    • TestCreateEventTelemetryTags — unit tests calling createEvent() directly, covering: single/multiple tags, whitespace trimming, malformed input, empty values, values containing =, system metadata protection, and operator-priority behavior.
    • TestTelemetryTags — integration tests using MockHTTPClient to verify tags appear in the actual HTTP request payload, including security and edge-case scenarios.

Test plan

  • go test ./pkg/telemetry/ -run TestCreateEventTelemetryTags -v — 9 subtests
  • go test ./pkg/telemetry/ -run TestTelemetryTags -v — 5 subtests
  • go test ./pkg/telemetry/ — full suite passes with no regressions

@derekmisler derekmisler self-assigned this Feb 13, 2026
Signed-off-by: Derek Misler <derek.misler@docker.com>
@derekmisler derekmisler force-pushed the how-can-we-track-usage branch from c18c0cb to 0a6fa86 Compare February 13, 2026 17:54
@derekmisler derekmisler marked this pull request as ready for review February 13, 2026 17:54
@derekmisler derekmisler requested a review from a team as a code owner February 13, 2026 17:54
@derekmisler derekmisler marked this pull request as draft February 13, 2026 17:56
@derekmisler derekmisler marked this pull request as ready for review February 13, 2026 17:56
Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

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

Code Review Summary

No issues found in the changed code.

The implementation correctly:

  • Parses comma-separated key=value pairs from TELEMETRY_TAGS environment variable
  • Uses strings.Cut() to split on the first = (correctly allowing = characters in values)
  • Validates that keys are non-empty after trimming whitespace
  • Trims both keys and values of leading/trailing whitespace
  • Handles edge cases: empty values, malformed pairs without =, pairs with extra spaces
  • Protects system metadata (user_uuid, version, os, os_language) by writing them AFTER tags, preventing spoofing

The test coverage is comprehensive and covers all the important edge cases including security concerns, whitespace handling, malformed input, and the critical system metadata protection test.

Great work on this feature!

@derekmisler derekmisler merged commit 4971200 into docker:main Feb 13, 2026
10 of 11 checks passed
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.

2 participants