Skip to content

Conversation

@panteliselef
Copy link
Contributor

@panteliselef panteliselef commented Aug 11, 2025

Description

Switch to throttling instead of sampling for telemetry on keyless applications to help us better troubleshoot keyless issues.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • New Features

    • UI telemetry for keyless apps now uses throttling instead of sampling to reduce event volume.
    • Telemetry Collector gains a per-event sampling option for finer control; applied consistently across many prebuilt UI components.
  • Tests

    • Added tests verifying interaction between per-event sampling and global sampling behavior.
  • Chores

    • Added changesets documenting the patch and minor updates; adjusted bundle size threshold and cleaned telemetry docs.

@changeset-bot
Copy link

changeset-bot bot commented Aug 11, 2025

🦋 Changeset detected

Latest commit: 19c3bf5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 19 packages
Name Type
@clerk/clerk-js Patch
@clerk/shared Minor
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/elements Patch
@clerk/expo-passkeys Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/clerk-react Patch
@clerk/remix Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Aug 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ⬜️ Skipped (Inspect) Aug 11, 2025 5:14pm

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 11, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@6514

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@6514

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@6514

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@6514

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@6514

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@6514

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@6514

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@6514

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@6514

@clerk/express

npm i https://pkg.pr.new/@clerk/express@6514

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@6514

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@6514

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@6514

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@6514

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@6514

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@6514

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@6514

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@6514

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@6514

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@6514

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@6514

@clerk/types

npm i https://pkg.pr.new/@clerk/types@6514

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@6514

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@6514

commit: 19c3bf5

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 11, 2025

📝 Walkthrough

Walkthrough

Adds two changesets (patch for @clerk/clerk-js, minor for @clerk/shared). Introduces a new TelemetryCollector option perEventSampling and wires it through types and collector initialization (default true). Server-side telemetry sampling logic now respects perEventSampling, and tests were added for sampling interactions. In clerk-js many prebuilt-component flows were standardized to use a local component identifier for preloadHint, mount name, and telemetry event names; telemetry initialization for keyless apps conditionally sets perEventSampling to false (throttling vs per-event sampling). bundlewatch headless size threshold increased from 57KB to 57.1KB. Minor JSDoc and guard/optional-chaining cleanups included.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~35 minutes


🪧 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.
  • 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.

Support

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

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 sequence diagram to generate a sequence diagram of the changes in 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 to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

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

🧹 Nitpick comments (3)
.changeset/bitter-waves-burn.md (1)

5-5: Clarify terminology: sampling vs throttling

The code implements a per-event sampling rate override (eventSamplingRate), setting it to 1 for keyless. The note says “Use throttling instead of sampling,” which can confuse readers. Suggest clarifying that for keyless, samplingRate is set to 1 (i.e., 100% of events are sent).

Suggested wording:

-Use throttling instead of sampling for telemetry events of UI components on keyless apps.
+For keyless apps, send 100% of UI component telemetry by overriding the event sampling rate to 1.
.changeset/slow-shoes-give.md (1)

5-5: Mention expected range for the new parameter

Call out that samplingRate is expected to be between 0 and 1 (inclusive) to guide consumers.

-Update `eventPrebuiltComponentMounted` and `eventPrebuiltComponentOpened` to accept a samplingRate.
+Update `eventPrebuiltComponentMounted` and `eventPrebuiltComponentOpened` to accept an optional `samplingRate` (0..1).
packages/shared/src/telemetry/events/component-mounted.ts (1)

51-62: Document expected range and default behavior for samplingRate

JSDoc mentions the param but not its valid range or default. Add brief guidance.

- * @param samplingRate - The sampling rate for the event.
+ * @param samplingRate - Optional sampling rate for the event (0..1). Defaults to a library constant.

Also applies to: 70-81

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1269b61 and 52307bc.

📒 Files selected for processing (4)
  • .changeset/bitter-waves-burn.md (1 hunks)
  • .changeset/slow-shoes-give.md (1 hunks)
  • packages/clerk-js/src/core/clerk.ts (22 hunks)
  • packages/shared/src/telemetry/events/component-mounted.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
.changeset/**

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/slow-shoes-give.md
  • .changeset/bitter-waves-burn.md
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/clerk-js/src/core/clerk.ts
  • packages/shared/src/telemetry/events/component-mounted.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/clerk-js/src/core/clerk.ts
  • packages/shared/src/telemetry/events/component-mounted.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/clerk.ts
  • packages/shared/src/telemetry/events/component-mounted.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/clerk-js/src/core/clerk.ts
  • packages/shared/src/telemetry/events/component-mounted.ts
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/clerk-js/src/core/clerk.ts
  • packages/shared/src/telemetry/events/component-mounted.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/clerk-js/src/core/clerk.ts
  • packages/shared/src/telemetry/events/component-mounted.ts
**/*

⚙️ CodeRabbit Configuration File

If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

Files:

  • packages/clerk-js/src/core/clerk.ts
  • packages/shared/src/telemetry/events/component-mounted.ts
🧬 Code Graph Analysis (2)
packages/clerk-js/src/core/clerk.ts (1)
packages/shared/src/telemetry/events/component-mounted.ts (2)
  • eventPrebuiltComponentOpened (74-81)
  • eventPrebuiltComponentMounted (55-62)
packages/shared/src/telemetry/events/component-mounted.ts (1)
packages/types/src/telemetry.ts (1)
  • TelemetryEventRaw (40-44)
⏰ 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). (5)
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: semgrep/ci
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
packages/shared/src/telemetry/events/component-mounted.ts (1)

55-61: LGTM: API changes are minimal and backward-compatible

Optional param is added at the end, return types remain explicit, and event payload remains stable.

Also applies to: 74-81

packages/clerk-js/src/core/clerk.ts (1)

350-353: LGTM: Centralized sampling rate logic for keyless

Private getter cleanly encapsulates the keyless override (1 or undefined). Call sites remain simple.

Copy link
Member

@brkalow brkalow left a comment

Choose a reason for hiding this comment

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

Can we disable sampling at the collector level instead of per-event? Something like disableSampling: true as an option to the collector.

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

♻️ Duplicate comments (2)
packages/clerk-js/src/core/clerk.ts (2)

660-662: Remove unnecessary template literal

This uses a backtick template literal without interpolation, which violates ESLint's no-useless-template-literals rule:

this.telemetry?.record(
-  eventPrebuiltComponentOpened(`UserVerification`, props, undefined, this.telemetrySamplingRate),
+  eventPrebuiltComponentOpened('UserVerification', props, undefined, this.telemetrySamplingRate),
);

730-730: Fix operator precedence in length checks

The expressions on these lines have operator precedence issues that can lead to incorrect evaluation:

Line 730 & 880:

-const additionalData = (props?.customPages?.length || 0) > 0 ? { customPages: true } : undefined;
+const additionalData = ((props?.customPages?.length || 0) > 0) ? { customPages: true } : undefined;

Line 1061:

-...(props?.customMenuItems?.length || 0 > 0 ? { customItems: true } : undefined),
+...((props?.customMenuItems?.length || 0) > 0 ? { customItems: true } : undefined),

Without proper parentheses, the expression evaluates as length || (0 > 0) instead of (length || 0) > 0.

Also applies to: 880-880, 1061-1061

🧹 Nitpick comments (1)
packages/clerk-js/src/core/clerk.ts (1)

350-352: Consider improving clarity and terminology consistency

The PR description mentions switching from "sampling" to "throttling" for keyless applications, but the variable name still uses "samplingRate". Consider either:

  1. Renaming to reflect throttling semantics (e.g., telemetryThrottleRate)
  2. Adding a comment explaining that 1 means no sampling (100% of events sent)

Also, the conditional could be more explicit:

private get telemetrySamplingRate(): number | undefined {
-  return this.#options.__internal_keyless_claimKeylessApplicationUrl ? 1 : undefined;
+  // Return 1 (100% sampling/no throttling) for keyless apps, undefined (use default) for others
+  return this.#options.__internal_keyless_claimKeylessApplicationUrl ? 1 : undefined;
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 52307bc and 9927e85.

📒 Files selected for processing (2)
  • packages/clerk-js/src/core/clerk.ts (22 hunks)
  • packages/shared/src/telemetry/events/component-mounted.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/shared/src/telemetry/events/component-mounted.ts
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/clerk-js/src/core/clerk.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/clerk-js/src/core/clerk.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/clerk.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/clerk-js/src/core/clerk.ts
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/clerk-js/src/core/clerk.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/clerk-js/src/core/clerk.ts
**/*

⚙️ CodeRabbit Configuration File

If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

Files:

  • packages/clerk-js/src/core/clerk.ts
🧬 Code Graph Analysis (1)
packages/clerk-js/src/core/clerk.ts (1)
packages/shared/src/telemetry/events/component-mounted.ts (2)
  • eventPrebuiltComponentOpened (79-86)
  • eventPrebuiltComponentMounted (60-67)
⏰ 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). (4)
  • GitHub Check: Build Packages
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
packages/clerk-js/src/core/clerk.ts (1)

550-551: Consistent propagation of samplingRate to telemetry events

All telemetry event calls have been correctly updated to pass this.telemetrySamplingRate as the 4th parameter, which aligns with the changes in the shared package. This ensures keyless applications will have their telemetry throttled appropriately.

Also applies to: 574-575, 626-627, 708-709, 731-733, 763-765, 787-789, 803-804, 824-825, 848-849, 881-882, 921-923, 954-956, 987-997, 1031-1041, 1065-1067, 1086-1087, 1113-1114, 1182-1183, 1220-1222

Comment on lines 350 to 352
private get telemetrySamplingRate(): number | undefined {
return this.#options.__internal_keyless_claimKeylessApplicationUrl ? 1 : undefined;
}
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

Add tests for telemetry sampling rate logic

Consider adding tests to verify:

  1. The telemetrySamplingRate getter returns 1 for keyless apps and undefined for regular apps
  2. The sampling rate is correctly passed to all telemetry event methods
  3. The telemetry behavior differs appropriately between keyless and non-keyless applications

Example test structure:

describe('telemetry sampling', () => {
  it('should use full sampling rate for keyless apps', () => {
    const clerk = new Clerk(key, {
      __internal_keyless_claimKeylessApplicationUrl: 'https://example.com'
    });
    // Verify telemetry calls receive samplingRate = 1
  });
  
  it('should use default sampling for regular apps', () => {
    const clerk = new Clerk(key);
    // Verify telemetry calls receive samplingRate = undefined
  });
});
🤖 Prompt for AI Agents
In packages/clerk-js/src/core/clerk.ts around lines 350 to 352, add unit tests
that verify the telemetrySamplingRate getter and its propagation: create a Clerk
instance with __internal_keyless_claimKeylessApplicationUrl set (keyless) and
assert telemetrySamplingRate === 1 and that all telemetry event calls receive
samplingRate = 1 (use spies/mocks on telemetry methods); create a Clerk instance
without that option and assert telemetrySamplingRate === undefined and telemetry
event calls receive samplingRate = undefined; ensure tests cover multiple
telemetry methods and both behaviors so keyless and non-keyless flows are
exercised.

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

🧹 Nitpick comments (2)
packages/clerk-js/bundlewatch.config.json (2)

6-6: Tiny budget bump: confirm necessity and keep budgets tight

57KB → 57.1KB is modest. Please confirm the measured compressed size for the headless bundle post-change and that this increase is strictly tied to the new telemetry parameter wiring. If we expect more incremental growth soon, consider either a slightly larger buffer or a follow-up cleanup to offset this growth.


1-35: Tests recommendation for telemetry changes

This PR appears to alter telemetry event APIs/usage (samplingRate propagation). If no tests were added, consider adding focused unit/integration tests to cover:

  • eventPrebuiltComponentMounted/Open with explicit samplingRate
  • defaulting/normalization behavior when samplingRate is undefined/invalid
  • keyless flows where throttling vs sampling behavior differs
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9927e85 and 81720d0.

📒 Files selected for processing (1)
  • packages/clerk-js/bundlewatch.config.json (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/clerk-js/bundlewatch.config.json
**/*

⚙️ CodeRabbit Configuration File

If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

Files:

  • packages/clerk-js/bundlewatch.config.json
⏰ 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). (4)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (generic, chrome)

@panteliselef panteliselef force-pushed the elef/user-3116-increase-telemetry-sampling-for-aios-while-on-keyless branch from 0ca6c52 to 0bbf54e Compare August 11, 2025 15:22
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: 0

🔭 Outside diff range comments (2)
packages/clerk-js/src/core/clerk.ts (2)

657-658: Avoid useless template literals and align with component variable pattern

Use plain strings and/or a local component variable, like other flows.

Apply:

-    this.telemetry?.record(eventPrebuiltComponentOpened(`UserVerification`, props));
+    const component = 'UserVerification';
+    this.telemetry?.record(eventPrebuiltComponentOpened(component, props));

1-2897: Replace backtick-quoted component names in telemetry calls

We found one leftover usage of backticks around the component name in a telemetry call. Please update it to use a plain string literal:

• packages/clerk-js/src/core/clerk.ts:657

- this.telemetry?.record(eventPrebuiltComponentOpened(`UserVerification`, props));
+ this.telemetry?.record(eventPrebuiltComponentOpened('UserVerification', props));
🧹 Nitpick comments (1)
packages/clerk-js/src/core/clerk.ts (1)

438-446: Wire perEventSampling for keyless initialization

Setting perEventSampling to false when __internal_keyless_claimKeylessApplicationUrl is present implements the “throttling instead of per-event sampling” goal. Consider adding a small unit/integration test under clerk-js to verify the wiring for keyless vs non-keyless.

If helpful, I can scaffold a test that asserts TelemetryCollector receives perEventSampling=false for keyless and undefined for non-keyless.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 81720d0 and 5d18bb0.

📒 Files selected for processing (6)
  • .changeset/slow-shoes-give.md (1 hunks)
  • packages/clerk-js/src/core/clerk.ts (8 hunks)
  • packages/shared/src/__tests__/telemetry.test.ts (1 hunks)
  • packages/shared/src/telemetry/collector.ts (3 hunks)
  • packages/shared/src/telemetry/events/component-mounted.ts (1 hunks)
  • packages/shared/src/telemetry/types.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/shared/src/telemetry/events/component-mounted.ts
  • .changeset/slow-shoes-give.md
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/shared/src/telemetry/types.ts
  • packages/shared/src/__tests__/telemetry.test.ts
  • packages/shared/src/telemetry/collector.ts
  • packages/clerk-js/src/core/clerk.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/shared/src/telemetry/types.ts
  • packages/shared/src/__tests__/telemetry.test.ts
  • packages/shared/src/telemetry/collector.ts
  • packages/clerk-js/src/core/clerk.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/shared/src/telemetry/types.ts
  • packages/shared/src/__tests__/telemetry.test.ts
  • packages/shared/src/telemetry/collector.ts
  • packages/clerk-js/src/core/clerk.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/shared/src/telemetry/types.ts
  • packages/shared/src/__tests__/telemetry.test.ts
  • packages/shared/src/telemetry/collector.ts
  • packages/clerk-js/src/core/clerk.ts
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/shared/src/telemetry/types.ts
  • packages/shared/src/__tests__/telemetry.test.ts
  • packages/shared/src/telemetry/collector.ts
  • packages/clerk-js/src/core/clerk.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/shared/src/telemetry/types.ts
  • packages/shared/src/__tests__/telemetry.test.ts
  • packages/shared/src/telemetry/collector.ts
  • packages/clerk-js/src/core/clerk.ts
**/*

⚙️ CodeRabbit Configuration File

If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

Files:

  • packages/shared/src/telemetry/types.ts
  • packages/shared/src/__tests__/telemetry.test.ts
  • packages/shared/src/telemetry/collector.ts
  • packages/clerk-js/src/core/clerk.ts
packages/**/*.{test,spec}.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Unit tests should use Jest or Vitest as the test runner.

Files:

  • packages/shared/src/__tests__/telemetry.test.ts
**/__tests__/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/typescript.mdc)

**/__tests__/**/*.{ts,tsx}: Create type-safe test builders/factories
Use branded types for test isolation
Implement proper mock types that match interfaces

Files:

  • packages/shared/src/__tests__/telemetry.test.ts
🧬 Code Graph Analysis (2)
packages/shared/src/__tests__/telemetry.test.ts (1)
packages/shared/src/telemetry/collector.ts (1)
  • TelemetryCollector (72-310)
packages/clerk-js/src/core/clerk.ts (1)
packages/shared/src/telemetry/events/component-mounted.ts (2)
  • eventPrebuiltComponentOpened (70-76)
  • eventPrebuiltComponentMounted (53-59)
⏰ 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). (23)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (tanstack-react-router, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: Static analysis
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (14)
packages/shared/src/telemetry/types.ts (2)

11-13: JSDoc punctuation fix looks good

Minor doc polish; no functional impact.


15-19: New public option perEventSampling?: boolean — API shape LGTM

Clear semantics and default noted. This pairs well with collector defaulting to true and conditional overrides.

packages/shared/src/telemetry/collector.ts (3)

47-52: Expose perEventSampling in TelemetryCollectorConfig

Type update correctly surfaces the flag for initialization.


80-87: Default perEventSampling to true in constructor

Matches the public JSDoc default. Good defensive defaulting.


169-174: Sampling gate correctly short-circuits per-event rates when perEventSampling is false

Order of checks is correct: global sampling, then per-event if enabled, then throttling. Tests cover both paths.

packages/shared/src/__tests__/telemetry.test.ts (2)

204-224: Test: perEventSampling=false bypasses per-event rate

Good coverage. Server-path forcing via window undefined and random seed mocking is appropriate.


226-245: Test: perEventSampling=true enforces per-event rate

Complements the previous test; ensures default behavior is preserved.

packages/clerk-js/src/core/clerk.ts (7)

541-548: Standardize component identifier for GoogleOneTap

Consistent use of a local component variable for preloadHint and telemetry. Good.


565-572: SignIn open flow: consistent component naming and additionalData

Local component name improves consistency; additionalData correctly captures withSignUp state.


618-624: PlanDetails open flow: component variable + telemetry

Looks consistent with the new pattern.


725-726: Operator precedence fix for customPages length

The explicit comparison avoids precedence pitfalls. Good catch.


802-814: SignIn mount flow: component variable across preloadHint, name, and telemetry

Consistent and clear.


827-838: SignUp mount flow normalization

Good standardization.


859-871: UserProfile mount: component variable + explicit customPages check

Matches the new conventions and fixes the earlier precedence issue.

@panteliselef panteliselef enabled auto-merge (squash) August 11, 2025 17:14
@panteliselef panteliselef merged commit 0ff648a into main Aug 11, 2025
35 checks passed
@panteliselef panteliselef deleted the elef/user-3116-increase-telemetry-sampling-for-aios-while-on-keyless branch August 11, 2025 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants