atmos icon indicating copy to clipboard operation
atmos copied to clipboard

Added initial implementation of telemetry

Open goruha opened this issue 5 months ago โ€ข 6 comments

what

  • Make Atmos send anonymous statistics about usage and failures to posthog

why

  • The statistical information helps us improve support and development planning decisions

Summary by CodeRabbit

  • New Features

    • Introduced anonymous telemetry collection to help improve the product, with clear opt-out options via configuration or environment variable.
    • Added support for detecting CI and Docker environments to enrich telemetry data.
    • Telemetry now includes workspace ID for Pro users to enhance support and troubleshooting.
  • Documentation

    • Updated documentation to describe telemetry behavior, opt-out methods, and provided a link to detailed telemetry documentation.
  • Bug Fixes

    • Configuration outputs and documentation now consistently reflect the new telemetry settings.
  • Tests

    • Added comprehensive tests for telemetry features, including event capture, configuration, CI/Docker detection, and opt-out functionality.

goruha avatar Jun 16 '25 22:06 goruha

๐Ÿ’ฅ This pull request now has conflicts. Could you fix it @goruha? ๐Ÿ™

mergify[bot] avatar Jun 16 '25 22:06 mergify[bot]

[!IMPORTANT]

Cloud Posse Engineering Team Review Required

This pull request modifies files that require Cloud Posse's review. Please be patient, and a core maintainer will review your changes.

To expedite this process, reach out to us on Slack in the #pr-reviews channel.

mergify[bot] avatar Jun 16 '25 22:06 mergify[bot]

Codecov Report

Attention: Patch coverage is 69.91404% with 105 lines in your changes missing coverage. Please review.

Project coverage is 53.47%. Comparing base (9cbd6a3) to head (ee796f0). Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/telemetry/mock/mock_posthog_client.go 23.91% 70 Missing :warning:
pkg/telemetry/utils.go 80.39% 16 Missing and 4 partials :warning:
cmd/root.go 33.33% 4 Missing :warning:
pkg/telemetry/ci.go 93.75% 3 Missing and 1 partial :warning:
pkg/telemetry/docker.go 84.21% 2 Missing and 1 partial :warning:
cmd/cmd_utils.go 0.00% 2 Missing :warning:
pkg/config/cache.go 50.00% 2 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1308      +/-   ##
==========================================
+ Coverage   53.10%   53.47%   +0.36%     
==========================================
  Files         245      251       +6     
  Lines       26337    26685     +348     
==========================================
+ Hits        13987    14269     +282     
- Misses      10675    10725      +50     
- Partials     1675     1691      +16     
Flag Coverage ฮ”
unittests 53.47% <69.91%> (+0.36%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Jun 18 '25 10:06 codecov[bot]

[!WARNING]

This PR exceeds the recommended limit of 1,000 lines.

Large PRs are difficult to review and may be rejected due to their size.

Please verify that this PR does not address multiple issues. Consider refactoring it into smaller, more focused PRs to facilitate a smoother review process.

mergify[bot] avatar Jun 19 '25 00:06 mergify[bot]

๐Ÿ’ฅ This pull request now has conflicts. Could you fix it @goruha? ๐Ÿ™

mergify[bot] avatar Jun 27 '25 11:06 mergify[bot]

๐Ÿ“ Walkthrough

Walkthrough

Telemetry support was added to the project. This includes new code for detecting CI and Docker environments, capturing command execution events, and sending anonymized data to a configurable PostHog endpoint. Configuration, documentation, and tests were updated to support enabling/disabling telemetry, setting endpoints, and capturing relevant environment and execution details.

Changes

Files/Groups Change Summary
README.md, README.yaml Added "Telemetry" section describing anonymous data collection, opt-out methods, and documentation link.
codecov.yml Excluded Go files in any mock subdirectory from coverage.
go.mod Added posthog-go dependency, updated AWS SDK dependencies, and added golang-lru/v2 as indirect.
pkg/config/atmos.yaml, tests/snapshots/TestCLICommands_*.golden Added settings.telemetry section with enabled, endpoint, and token fields.
pkg/config/cache.go Added InstallationId to cache config and save logic.
pkg/config/load.go Bound telemetry settings to environment variables.
pkg/schema/schema.go Added TelemetrySettings struct and field to AtmosSettings.
pkg/telemetry/ci.go, pkg/telemetry/ci_test.go Added CI environment/provider detection logic and tests.
pkg/telemetry/docker.go, pkg/telemetry/docker_test.go Added Docker environment detection logic and tests.
pkg/telemetry/telemetry.go, pkg/telemetry/telemetry_test.go Added telemetry client abstraction, event capture logic, and comprehensive tests.
pkg/telemetry/utils.go, pkg/telemetry/utils_test.go Added utilities to capture command telemetry, manage installation ID, and unit tests.
pkg/telemetry/mock/mock_posthog_client.go, pkg/telemetry/mock/mock_telemetry_provider.go, Added GoMock-generated mocks for PostHog client and telemetry provider interfaces.
pkg/telemetry/mock/telemetry_client_provider_interface.go Added interface for mocking telemetry client provider.
cmd/root.go, cmd/cmd_utils.go, internal/exec/version.go Integrated telemetry capture and disclosure message printing into CLI root, utils, and version commands.
tests/cli_test.go Added cache file removal and CI env var preservation/restoration in CLI tests.
website/docs/cli/telemetry.mdx Added new Telemetry documentation page describing data collection, opt-out, and configuration.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant Telemetry
    participant PostHog

    User->>CLI: Executes command
    CLI->>Telemetry: CaptureCmdString/CaptureCmd
    Telemetry->>Telemetry: Check config & enabled
    Telemetry->>Telemetry: Generate/load installation ID
    Telemetry->>Telemetry: Detect env (OS, arch, CI, Docker, workspace ID)
    Telemetry->>PostHog: Send event (if enabled)
    PostHog-->>Telemetry: Ack/response
    Telemetry-->>CLI: Success/failure (bool)

Assessment against linked issues

Objective (Issue) Addressed Explanation
Capture Atmos version, commands, errors, Pro workspace ID, OS, architecture, CI (GH Actions, GitLab, Jenkins, BitBucket, ADO, Docker) (DEV-2965) โœ…
Allow opt-out via config and environment variable (DEV-2965) โœ…
Configurable endpoint and token for PostHog (DEV-2965) โœ…
Store anonymous UUID in cache (DEV-2965) โœ…
No logging of command arguments (DEV-2965) โœ…

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

  • #1335: Adds the same "Telemetry" section to README.yaml describing anonymous telemetry data collection and opt-out methods, closely related documentation update.

Suggested reviewers

  • osterman
  • aknysh
  • milldr
โœจ Finishing Touches
  • [ ] ๐Ÿ“ Generate Docstrings
๐Ÿงช Generate Unit Tests
  • [ ] Create PR with Unit Tests
  • [ ] Post Copyable Unit Tests in a Comment
  • [ ] Commit Unit Tests in branch DEV-2965/implement-atmos-telemetry

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

โค๏ธ Share
๐Ÿชง Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Jun 27 '25 11:06 coderabbitai[bot]