Skip to content

Conversation

Mercy811
Copy link
Contributor

@Mercy811 Mercy811 commented Oct 1, 2025

Summary

  • Diagnostics client
    • Implement sample rate logic
      • Rename isSessionInSample() to isTimestampInSample() and move it from SR to core package
    • Save current timestamp as last flush timestamp for first time users. Otherwise events are not sent when a first time user comes back next time because it still thinks this user is first time user.
  • Add diagnostics client to browser client
  • Add a backdoor to set diagnostics sample rate. Call it before amplitude.init().
  • Use diagnostics client to
    • track analytics sdk library + version
    • track autocapture getHierachy block time
  • Use remote config in autocapture plugin
  • Gitignore playground amplitude.js script

Ideally, both remote config client and diagnostics client should be in AmplitudeContext but it requires significant change so this PR adds them to internal browser config.

image Screenshot 2025-10-01 at 12 44 55 PM image

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?:

Note

Introduces a diagnostics client with sampling, integrates it into the browser/unified clients, tracks autocapture getHierarchy timing, and switches autocapture to use a provided remote-config client.

  • Core:
    • Add DiagnosticsClient (tags/counters/histograms/events, flush/save timers) with deterministic sampling (generateHashCode, isTimestampInSample).
    • Export diagnostics and sampling utilities; update types (AmplitudeContext -> interfaces) and configs to carry diagnosticsClient/remoteConfigClient.
  • Browser/Unified Clients:
    • Initialize and attach DiagnosticsClient; set library tag; expose _setDiagnosticsSampleRate backdoor; plumb through config (enableDiagnostics, diagnosticsSampleRate).
    • Pass remoteConfigClient through; factories wrap new method.
  • Autocapture Plugin:
    • Track getHierarchy duration via diagnostics histogram.
    • Replace internal RC fetch with provided remoteConfigClient.subscribe.
  • Session Replay:
    • Reuse core isTimestampInSample (remove local sampler).
  • Housekeeping/Tests:
    • Add tests for diagnostics, sampling, and new APIs; ignore playground amplitude.js in .gitignore.

Written by Cursor Bugbot for commit 4aba738. This will update automatically on new commits. Configure here.

@Mercy811 Mercy811 force-pushed the AMP-140345-add-diagnositcs-client-to-browser-sdk branch from cf60aa3 to 42a882b Compare October 2, 2025 18:20
@Mercy811
Copy link
Contributor Author

Mercy811 commented Oct 2, 2025

bugbot run

cursor[bot]

This comment was marked as outdated.

@Mercy811 Mercy811 marked this pull request as ready for review October 2, 2025 19:59
@daniel-graham-amplitude
Copy link
Collaborator

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no bugs!


Comment @cursor review or bugbot run to trigger another review on this PR

Copy link
Collaborator

@daniel-graham-amplitude daniel-graham-amplitude left a comment

Choose a reason for hiding this comment

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

Lgtm. Some minor comments.

I'll definitely want SR and Autocapture reviewers to approve this first though.

Copy link
Collaborator

@lewgordon-amplitude lewgordon-amplitude left a comment

Choose a reason for hiding this comment

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

SR changes (sampling changes) LGTM!

@Mercy811 Mercy811 merged commit a919e22 into main Oct 3, 2025
7 checks passed
@Mercy811 Mercy811 deleted the AMP-140345-add-diagnositcs-client-to-browser-sdk branch October 3, 2025 20:04
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.

4 participants