Skip to content

fix(analytics): remove amplitude sampling to restore full reporting#2526

Merged
ygrishajev merged 3 commits intomainfrom
fix/analytics
Jan 19, 2026
Merged

fix(analytics): remove amplitude sampling to restore full reporting#2526
ygrishajev merged 3 commits intomainfrom
fix/analytics

Conversation

@ygrishajev
Copy link
Contributor

@ygrishajev ygrishajev commented Jan 17, 2026

refs #2525

Summary by CodeRabbit

  • Chores

    • Removed analytics sampling configuration from deployment and runtime settings so tracking no longer relies on per-user sampling.
  • New Features

    • Analytics now always reports events and user identification (when available), with consistent initialization to improve telemetry reliability.

✏️ Tip: You can customize this high-level summary in your review settings.

@ygrishajev ygrishajev requested a review from a team as a code owner January 17, 2026 10:58
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 17, 2026

📝 Walkthrough

Walkthrough

This PR removes Amplitude sampling configuration and sampling-related logic across API and frontend. Environment variables and schema entries for AMPLITUDE_SAMPLING / NEXT_PUBLIC_AMPLITUDE_SAMPLING were deleted; AnalyticsService implementations were simplified to drop hash-based sampling and related dependencies, with lazy initialization added on the frontend.

Changes

Cohort / File(s) Summary
API env files
apps/api/env/.env.functional.test, apps/api/env/.env.local.sample, apps/api/env/.env.production, apps/api/env/.env.sample, apps/api/env/.env.staging
Removed AMPLITUDE_SAMPLING entries from all API environment files.
API config schema
apps/api/src/core/config/env.config.ts
Removed AMPLITUDE_SAMPLING from env schema (validation/default deleted).
API analytics service
apps/api/src/core/services/analytics/analytics.service.ts, apps/api/src/core/services/analytics/analytics.service.spec.ts
Removed hasher and CoreConfigService injections, deleted samplingRate and sampling helpers, made identify()/track() unconditional, updated tests and Amplitude mock (identify API).
Frontend env files
apps/deploy-web/env/.env.production, apps/deploy-web/env/.env.staging, apps/deploy-web/env/.env.staging-testnet
Removed NEXT_PUBLIC_AMPLITUDE_SAMPLING from frontend env files.
Frontend env schema / types
apps/deploy-web/src/config/env-config.schema.ts, apps/deploy-web/src/config/browser-env.config.ts
Removed NEXT_PUBLIC_AMPLITUDE_SAMPLING from browser env schema and browserEnvConfig (type no longer exposes sampling).
Frontend analytics service
apps/deploy-web/src/services/analytics/analytics.service.ts, apps/deploy-web/src/services/analytics/analytics.service.spec.ts
Removed HashFn export and samplingRate option, removed hash constructor param and per-user sampling logic, added lazy initAmplitude() with amplitudeInitialized guard, simplified tracking/identify flows and updated tests.
Frontend DI
apps/deploy-web/src/services/app-di-container/app-di-container.ts
Removed samplingRate property from amplitude config passed into AnalyticsService.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AnalyticsService
  participant Amplitude
  participant Logger
  participant GA

  Client->>AnalyticsService: identify(userId, properties?)
  AnalyticsService->>AnalyticsService: if not initialized -> initAmplitude()
  AnalyticsService->>Amplitude: identify(userId, properties) rgba(0,128,255,0.5)
  AnalyticsService->>Logger: debug(ANALYTICS_USER_IDENTIFIED, payload) rgba(0,255,128,0.5)
  AnalyticsService->>GA: optional GA identify/event sync rgba(255,128,0,0.5)

  Client->>AnalyticsService: track(userId, eventName, properties?)
  AnalyticsService->>AnalyticsService: ensure amplitude initialized
  AnalyticsService->>Amplitude: track(event with user_id & properties) rgba(0,128,255,0.5)
  AnalyticsService->>Logger: debug(ANALYTICS_EVENT_REPORTED, payload) rgba(0,255,128,0.5)
  AnalyticsService->>GA: GA event emit rgba(255,128,0,0.5)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • baktun14

Poem

🐰 I hopped through envs and trimmed a line,
Amplitude's dice rolled every time,
Now events leap straight, no chance to hide,
Simpler hops on the tracking ride,
Clean code, full carrots, joyful thyme 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: removing amplitude sampling to restore full reporting across both backend and frontend analytics services.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Jan 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.45%. Comparing base (d890137) to head (5c01a15).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

❌ Your project status has failed because the head coverage (79.29%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2526      +/-   ##
==========================================
- Coverage   50.78%   50.45%   -0.33%     
==========================================
  Files        1063     1053      -10     
  Lines       29476    29097     -379     
  Branches     6535     6462      -73     
==========================================
- Hits        14968    14681     -287     
+ Misses      14146    14001     -145     
- Partials      362      415      +53     
Flag Coverage Δ *Carryforward flag
api 79.29% <100.00%> (-0.02%) ⬇️
deploy-web 31.20% <100.00%> (-0.03%) ⬇️
log-collector ?
notifications 87.94% <ø> (ø) Carriedforward from cdb2954
provider-console 81.48% <ø> (ø) Carriedforward from cdb2954
provider-proxy 84.35% <ø> (ø) Carriedforward from cdb2954

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
apps/api/src/core/config/env.config.ts 75.00% <ø> (ø)
...i/src/core/services/analytics/analytics.service.ts 100.00% <100.00%> (+19.44%) ⬆️
apps/deploy-web/src/config/browser-env.config.ts 100.00% <ø> (ø)
apps/deploy-web/src/config/env-config.schema.ts 71.42% <ø> (-1.30%) ⬇️
...oy-web/src/services/analytics/analytics.service.ts 81.25% <100.00%> (+2.20%) ⬆️
.../src/services/app-di-container/app-di-container.ts 74.16% <ø> (-1.87%) ⬇️

... and 61 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@apps/deploy-web/src/services/analytics/analytics.service.ts`:
- Around line 207-221: The call to amplitudeClient.init inside initAmplitude
currently passes the options object as the second argument (so SDK treats it as
userId); change the call in initAmplitude to pass undefined as the second
argument and supply the options object as the third argument (use
this.options.amplitude.apiKey, undefined, and then the options object built from
serverUrl), leaving amplitudeInitialized logic unchanged.
🧹 Nitpick comments (1)
apps/deploy-web/src/services/analytics/analytics.service.spec.ts (1)

115-213: Remove stale “Initialize sampling” comments in track tests.

Sampling is no longer present, so these comments now mislead and add noise.

🧹 Suggested cleanup
-      service.identify({ id: faker.string.uuid() }); // Initialize sampling
+      service.identify({ id: faker.string.uuid() });
...
-      service.identify({ id: faker.string.uuid() }); // Initialize sampling
+      service.identify({ id: faker.string.uuid() });

As per coding guidelines, avoid unnecessary comments.

@ygrishajev ygrishajev merged commit 0cc8def into main Jan 19, 2026
97 of 100 checks passed
@ygrishajev ygrishajev deleted the fix/analytics branch January 19, 2026 10:02
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

Comments