+
Skip to content

Conversation

steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Oct 10, 2025

Summary by CodeRabbit

  • Chores
    • Reconfigured telemetry/analytics ingestion to use legacy endpoints for clicks, leads, links, sales, webhooks, conversions, and import errors.
    • Aligned background job and API route logging with the updated telemetry configuration.
  • Refactor
    • Consolidated telemetry client setup for consistency across logging modules.

No user-facing changes; functionality and behavior remain the same.

Copy link
Contributor

vercel bot commented Oct 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Oct 10, 2025 10:57pm

Copy link
Contributor

coderabbitai bot commented Oct 10, 2025

Walkthrough

This change reverts Tinybird ingestion usage from the “new” client/key to the “old” client/key across multiple endpoints and helpers. It renames exports to TBOld variants, updates imports, and switches authorization tokens. Control flow and payloads remain the same, with one header change in record-click and one POST in a cron route.

Changes

Cohort / File(s) Summary of edits
Tinybird client config
apps/web/lib/tinybird/client.ts
Replaced exported tbNew with tbOld; token switched from TINYBIRD_API_KEY_NEW to TINYBIRD_API_KEY_OLD.
Endpoint swaps to tbOld (ingest helpers)
apps/web/lib/tinybird/log-conversion-events.ts, apps/web/lib/tinybird/log-import-error.ts, apps/web/lib/tinybird/record-click-zod.ts, apps/web/lib/tinybird/record-lead.ts, apps/web/lib/tinybird/record-link.ts, apps/web/lib/tinybird/record-sale.ts, apps/web/lib/tinybird/record-webhook-event.ts
Changed imports from tbNewtbOld; rebuilt ingest endpoints with tbOld.buildIngestEndpoint; renamed exported constants from ...TBNew to ...TBOld (record-sale keeps names but swaps builder); updated waitUntil calls accordingly.
Audit logs endpoint swap
apps/web/lib/api/audit-logs/record-audit-log.ts
Switched ingest usage to tbOld; waitUntil now targets the TBOld endpoint; export names of main API unchanged.
Record click fallback auth
apps/web/lib/tinybird/record-click.ts
Changed fallback Tinybird Authorization header to use TINYBIRD_API_KEY_OLD; logic and signatures unchanged.
Cron backfill POST auth
apps/web/app/(ee)/api/cron/framer/backfill-leads-batch/route.ts
Second Tinybird POST now uses the old API key; first call unchanged; no control-flow changes.

Sequence Diagram(s)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • devkiran

Poem

In burrows of code where the data streams flow,
I twitch my whiskers—back to the keys we know.
Old burrow, old token, the carrots still sweet,
Events hop along with a familiar beat.
Logs thump softly—all is well, let’s go! 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately summarizes the primary change in the pull request, which is the refactoring of the Tinybird client symbol and related endpoints from tbNew to tbOld across multiple files, without introducing extraneous detail or ambiguity.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch tb-old

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

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

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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/lib/tinybird/record-sale.ts (1)

29-34: Rename export to reflect the tbOld usage.

Similar to recordSaleNewTB, this export name recordSaleWithTimestampNewTB still contains "New" but uses tbOld. Rename it to recordSaleWithTimestampOldTB for consistency.

Apply this diff to rename the export consistently:

-export const recordSaleWithTimestampNewTB = tbOld.buildIngestEndpoint({
+export const recordSaleWithTimestampOldTB = tbOld.buildIngestEndpoint({
   datasource: "dub_sale_events",
   event: saleEventSchemaTB.extend({
     timestamp: z.string(),
   }),
 });

Then update the usage on line 37:

 export const recordSaleWithTimestamp = async (payload: any) => {
-  waitUntil(recordSaleWithTimestampNewTB(payload));
+  waitUntil(recordSaleWithTimestampOldTB(payload));
   return await recordSaleWithTimestampTB(payload);
 };
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5c1bbab and 6de9396.

📒 Files selected for processing (11)
  • apps/web/app/(ee)/api/cron/framer/backfill-leads-batch/route.ts (1 hunks)
  • apps/web/lib/api/audit-logs/record-audit-log.ts (3 hunks)
  • apps/web/lib/tinybird/client.ts (1 hunks)
  • apps/web/lib/tinybird/log-conversion-events.ts (2 hunks)
  • apps/web/lib/tinybird/log-import-error.ts (1 hunks)
  • apps/web/lib/tinybird/record-click-zod.ts (2 hunks)
  • apps/web/lib/tinybird/record-click.ts (1 hunks)
  • apps/web/lib/tinybird/record-lead.ts (2 hunks)
  • apps/web/lib/tinybird/record-link.ts (3 hunks)
  • apps/web/lib/tinybird/record-sale.ts (2 hunks)
  • apps/web/lib/tinybird/record-webhook-event.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-02T22:46:22.739Z
Learnt from: steven-tey
PR: dubinc/dub#2924
File: apps/web/lib/api/conversions/track-lead.ts:7-7
Timestamp: 2025-10-02T22:46:22.739Z
Learning: In apps/web/lib/api/conversions/track-lead.ts, lead events are cached in Redis for 5 minutes (keys: `leadCache:${customer.id}` and `leadCache:${customer.id}:${stringifiedEventName}`) to provide immediate data availability while Tinybird ingestion happens asynchronously. This caching pattern allows for async-only recording without breaking "wait" mode semantics.

Applied to files:

  • apps/web/lib/tinybird/record-lead.ts
🧬 Code graph analysis (8)
apps/web/lib/api/audit-logs/record-audit-log.ts (1)
apps/web/lib/tinybird/client.ts (1)
  • tbOld (9-12)
apps/web/lib/tinybird/log-import-error.ts (2)
apps/web/lib/tinybird/client.ts (2)
  • tb (3-6)
  • tbOld (9-12)
apps/web/lib/zod/schemas/import-error-log.ts (1)
  • importErrorLogSchema (3-23)
apps/web/lib/tinybird/record-lead.ts (2)
apps/web/lib/tinybird/client.ts (2)
  • tb (3-6)
  • tbOld (9-12)
apps/web/lib/zod/schemas/leads.ts (1)
  • leadEventSchemaTB (98-107)
apps/web/lib/tinybird/record-click-zod.ts (1)
apps/web/lib/tinybird/client.ts (1)
  • tbOld (9-12)
apps/web/lib/tinybird/record-webhook-event.ts (2)
apps/web/lib/tinybird/client.ts (2)
  • tb (3-6)
  • tbOld (9-12)
apps/web/lib/zod/schemas/webhooks.ts (1)
  • webhookEventSchemaTB (37-50)
apps/web/lib/tinybird/record-sale.ts (2)
apps/web/lib/tinybird/client.ts (2)
  • tb (3-6)
  • tbOld (9-12)
apps/web/lib/zod/schemas/sales.ts (1)
  • saleEventSchemaTB (120-137)
apps/web/lib/tinybird/log-conversion-events.ts (1)
apps/web/lib/tinybird/client.ts (1)
  • tbOld (9-12)
apps/web/lib/tinybird/record-link.ts (1)
apps/web/lib/tinybird/client.ts (1)
  • tbOld (9-12)
⏰ 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). (1)
  • GitHub Check: build
🔇 Additional comments (14)
apps/web/lib/api/audit-logs/record-audit-log.ts (1)

2-2: LGTM! Consistent migration to tbOld.

The changes correctly update the import and rename the endpoint from recordAuditLogTBNew to recordAuditLogTBOld. The dual ingestion pattern is preserved with tbOld in waitUntil and the primary tb ingest remaining unchanged.

Also applies to: 59-59, 83-87

apps/web/app/(ee)/api/cron/framer/backfill-leads-batch/route.ts (1)

304-314: LGTM! Consistent dual ingestion pattern.

The second fetch now correctly uses TINYBIRD_API_KEY_OLD for authorization, maintaining the dual ingestion pattern during the Tinybird migration. Both requests send identical click data to ensure data consistency across both Tinybird instances.

apps/web/lib/tinybird/client.ts (1)

9-10: LGTM! Core client renamed from tbNew to tbOld.

The export name and token source have been updated consistently. This is a breaking change for any modules importing tbNew, but all affected files in this PR have been updated accordingly.

apps/web/lib/tinybird/record-webhook-event.ts (1)

3-3: LGTM! Consistent endpoint migration.

The import, endpoint definition, and waitUntil call have been updated consistently to use tbOld. The public recordWebhookEvent function maintains its interface while implementing the dual ingestion pattern.

Also applies to: 11-14, 17-17

apps/web/lib/tinybird/record-link.ts (1)

6-6: LGTM! Complete migration for both payload paths.

All changes consistently use tbOld:

  • Import updated (line 6)
  • Endpoint definition renamed (lines 54-58)
  • Both single and array payload paths in recordLink updated (lines 87, 95)

The dual ingestion pattern is correctly implemented for both code paths.

Also applies to: 54-58, 86-96

apps/web/lib/tinybird/record-lead.ts (1)

4-4: LGTM! Both lead recording endpoints migrated.

The migration correctly covers both variants:

  • recordLeadrecordLeadTBOld (lines 12-15, 18)
  • recordLeadWithTimestamprecordLeadWithTimestampTBOld (lines 29-34, 37)

All waitUntil calls updated and public APIs preserved.

Also applies to: 12-15, 18-18, 29-34, 37-37

apps/web/lib/tinybird/log-import-error.ts (1)

3-3: LGTM! Final migration file completed consistently.

The import error logging follows the same migration pattern as all other Tinybird integrations:

  • Import updated (line 3)
  • Endpoint renamed to logImportErrorTBOld (lines 11-14)
  • waitUntil call updated (line 17)

This completes the consistent migration across all Tinybird modules in the PR.

Also applies to: 11-14, 17-17

apps/web/lib/tinybird/record-click-zod.ts (3)

3-3: LGTM! Import updated correctly.

The import now includes tbOld to support the migration from the "new" to "old" Tinybird client.


51-51: LGTM! waitUntil call updated correctly.

The waitUntil call now uses recordClickZodTBOld which is consistent with the export rename.


44-48: No remaining references to the old export. All imports have been updated to recordClickZodTBOld.

apps/web/lib/tinybird/record-sale.ts (1)

4-4: LGTM! Import updated correctly.

The import now uses tbOld instead of tbNew to align with the migration.

apps/web/lib/tinybird/log-conversion-events.ts (3)

3-3: LGTM! Import updated correctly.

The import now includes tbOld to support the migration from the "new" to "old" Tinybird client.


26-26: LGTM! waitUntil call updated correctly.

The waitUntil call now uses logConversionEventTBOld which is consistent with the export rename.


20-23: No remaining imports of the old export. The rename is confined to this file; no further updates required.

method: "POST",
headers: {
Authorization: `Bearer ${process.env.TINYBIRD_API_KEY_NEW}`,
Authorization: `Bearer ${process.env.TINYBIRD_API_KEY_OLD}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Verify that TINYBIRD_API_KEY_OLD is set in the environment.

The authorization header now uses TINYBIRD_API_KEY_OLD. Ensure this environment variable is properly configured in all deployment environments (development, staging, production) to prevent ingestion failures.

Run the following script to check if the environment variable is referenced and documented:


🏁 Script executed:

#!/bin/bash
# Search for TINYBIRD_API_KEY_OLD usage and configuration
rg -n 'TINYBIRD_API_KEY_OLD' -g '!node_modules' -C2

Length of output: 1284


🏁 Script executed:

#!/bin/bash
# Search for TINYBIRD_API_KEY_OLD in environment examples and documentation
rg -n 'TINYBIRD_API_KEY_OLD' -g '.env*' -g '*.md'

Length of output: 0


Add TINYBIRD_API_KEY_OLD to environment documentation
TINYBIRD_API_KEY_OLD is referenced in

  • apps/web/lib/tinybird/record-click.ts (line 216)
  • apps/web/app/(ee)/api/cron/framer/backfill-leads-batch/route.ts (line 309)
  • apps/web/lib/tinybird/client.ts (line 10)
    but isn’t listed in .env.example or any README. Document this variable and ensure it’s configured in all deployment environments.

Comment on lines +12 to 15
export const recordSaleNewTB = tbOld.buildIngestEndpoint({
datasource: "dub_sale_events",
event: saleEventSchemaTB,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Rename export to reflect the tbOld usage.

The export name recordSaleNewTB still contains "New" but now uses tbOld. This is inconsistent with other files in this PR where exports were renamed from *TBNew to *TBOld (e.g., recordClickZodTBNewrecordClickZodTBOld, logConversionEventTBNewlogConversionEventTBOld). The name should reflect that it uses the "old" client.

Apply this diff to rename the export consistently:

-export const recordSaleNewTB = tbOld.buildIngestEndpoint({
+export const recordSaleOldTB = tbOld.buildIngestEndpoint({
   datasource: "dub_sale_events",
   event: saleEventSchemaTB,
 });

Then update the usage on line 18:

 export const recordSale = async (payload: any) => {
-  waitUntil(recordSaleNewTB(payload));
+  waitUntil(recordSaleOldTB(payload));
   return await recordSaleTB(payload);
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const recordSaleNewTB = tbOld.buildIngestEndpoint({
datasource: "dub_sale_events",
event: saleEventSchemaTB,
});
export const recordSaleOldTB = tbOld.buildIngestEndpoint({
datasource: "dub_sale_events",
event: saleEventSchemaTB,
});
export const recordSale = async (payload: any) => {
waitUntil(recordSaleOldTB(payload));
return await recordSaleTB(payload);
};
🤖 Prompt for AI Agents
In apps/web/lib/tinybird/record-sale.ts around lines 12 to 15, the exported name
recordSaleNewTB is inconsistent because this module uses tbOld; rename the
export to recordSaleTBOld and update any references (specifically the usage on
line 18) to the new name to match the TBOld naming convention used elsewhere in
this PR.

@steven-tey steven-tey marked this pull request as draft October 11, 2025 00:06
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.

1 participant

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载