feat(analytics): proxies amplitude requests to avoid failed requests due to blockers#2441
feat(analytics): proxies amplitude requests to avoid failed requests due to blockers#2441ygrishajev merged 1 commit intomainfrom
Conversation
📝 WalkthroughWalkthroughThis change implements an Amplitude analytics events proxy by introducing a configurable proxy URL environment variable, Next.js rewrite rule, and analytics service initialization logic to route events through a custom endpoint. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/deploy-web/next.config.js (1)
26-35: Critical:browserEnvcan be undefined when accessed.When
env-config.schema.jsis not found or validation fails,browserEnvremainsundefined. Line 175 then attempts to accessbrowserEnv.NEXT_PUBLIC_AMPLITUDE_PROXY_URL, which will throw a runtime error and break the build.🔎 Proposed fix
let browserEnv; try { const { browserEnvSchema } = require("./env-config.schema"); browserEnv = browserEnvSchema.parse(process.env); } catch (error) { if (error.message.includes("Cannot find module")) { console.warn("No env-config.schema.js found, skipping env validation"); } + browserEnv = {}; }Or use optional chaining in the rewrites function:
rewrites: async () => - browserEnv.NEXT_PUBLIC_AMPLITUDE_PROXY_URL + browserEnv?.NEXT_PUBLIC_AMPLITUDE_PROXY_URL ? [ { - source: browserEnv.NEXT_PUBLIC_AMPLITUDE_PROXY_URL, + source: browserEnv?.NEXT_PUBLIC_AMPLITUDE_PROXY_URL, destination: "https://api2.amplitude.com/2/httpapi" } ] : []
🧹 Nitpick comments (1)
apps/deploy-web/env/.env (1)
35-35: Remove unnecessary quotes from environment variable value.The value doesn't require quotes in
.envfiles. Remove them for consistency with dotenv conventions.🔎 Suggested fix
-NEXT_PUBLIC_AMPLITUDE_PROXY_URL="/api/collect" +NEXT_PUBLIC_AMPLITUDE_PROXY_URL=/api/collect
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
apps/deploy-web/env/.envapps/deploy-web/next.config.jsapps/deploy-web/src/config/browser-env.config.tsapps/deploy-web/src/config/env-config.schema.tsapps/deploy-web/src/services/analytics/analytics.service.tsapps/deploy-web/src/services/app-di-container/app-di-container.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
**/*.{ts,tsx,js}: Never use typeanyor cast to typeany. Always define the proper TypeScript types.
Never use deprecated methods from libraries.
Don't add unnecessary comments to the code.
Files:
apps/deploy-web/src/services/analytics/analytics.service.tsapps/deploy-web/src/config/env-config.schema.tsapps/deploy-web/src/config/browser-env.config.tsapps/deploy-web/next.config.jsapps/deploy-web/src/services/app-di-container/app-di-container.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: baktun14
Repo: akash-network/console PR: 1725
File: apps/api/src/utils/constants.ts:5-5
Timestamp: 2025-07-24T17:00:52.361Z
Learning: In the Akash Network Console project, when cross-cutting concerns or broader refactoring issues are identified during PR review, the preferred approach is to create a separate GitHub issue to track the work rather than expanding the scope of the current PR. This maintains focus and allows for proper planning of architectural improvements.
📚 Learning: 2025-08-12T13:52:38.708Z
Learnt from: stalniy
Repo: akash-network/console PR: 1800
File: apps/deploy-web/next.config.js:163-165
Timestamp: 2025-08-12T13:52:38.708Z
Learning: In the Akash Console project, akashnetwork/env-loader is used at the top of next.config.js files to automatically load environment variables from env/.env files into process.env. SENTRY_ORG and SENTRY_PROJECT are stored as public configuration values in apps/deploy-web/env/.env and are loaded this way, while only SENTRY_AUTH_TOKEN is handled as a GitHub secret in workflows.
Applied to files:
apps/deploy-web/env/.envapps/deploy-web/src/config/browser-env.config.tsapps/deploy-web/next.config.js
📚 Learning: 2025-08-12T13:52:38.708Z
Learnt from: stalniy
Repo: akash-network/console PR: 1800
File: apps/deploy-web/next.config.js:163-165
Timestamp: 2025-08-12T13:52:38.708Z
Learning: In the Akash Console project, SENTRY_ORG and SENTRY_PROJECT are stored as public configuration values in apps/deploy-web/env/.env file and loaded by akashnetwork/env-loader, not as GitHub secrets. Only SENTRY_AUTH_TOKEN should be handled as a secret.
Applied to files:
apps/deploy-web/env/.env
🧬 Code graph analysis (1)
apps/deploy-web/next.config.js (2)
apps/stats-web/next.config.js (2)
require(2-2)require(5-5)apps/deploy-web/src/config/env-config.schema.ts (1)
browserEnvSchema(6-44)
🪛 dotenv-linter (4.0.0)
apps/deploy-web/env/.env
[warning] 35-35: [QuoteCharacter] The value has quote characters (', ")
(QuoteCharacter)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: validate / validate-app
- GitHub Check: test-build
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
apps/deploy-web/next.config.js (1)
174-182: The endpointhttps://api2.amplitude.com/2/httpapiis correct for the standard (global) Amplitude HTTP API v2 event tracking. No changes needed.apps/deploy-web/src/services/analytics/analytics.service.ts (1)
216-224: Amplitude SDKserverUrlconfiguration is correctly implemented.The code properly uses the
serverUrloption in theinitmethod, which is supported in @amplitude/analytics-browser v2.11.11. The pattern of conditionally passing{ serverUrl }to init is correct, andhttps://api2.amplitude.com/2/httpapiis the documented standard endpoint for event tracking.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2441 +/- ##
==========================================
- Coverage 51.23% 50.93% -0.30%
==========================================
Files 1072 1062 -10
Lines 29375 29034 -341
Branches 6428 6413 -15
==========================================
- Hits 15050 14789 -261
+ Misses 13920 13839 -81
- Partials 405 406 +1
*This pull request uses carry forward flags. Click here to find out more.
🚀 New features to boost your workflow:
|
Summary by CodeRabbit
New Features
Chores
✏️ Tip: You can customize this high-level summary in your review settings.