Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pretty-rings-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/shared": patch
---

Increase sampling for high-signal auth components on mount.
20 changes: 18 additions & 2 deletions packages/shared/src/telemetry/events/component-mounted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ const EVENT_COMPONENT_MOUNTED = 'COMPONENT_MOUNTED';
const EVENT_COMPONENT_OPENED = 'COMPONENT_OPENED';
const EVENT_SAMPLING_RATE = 0.1;

/** Increase sampling for high-signal auth components on mount. */
const AUTH_COMPONENTS = new Set<string>(['SignIn', 'SignUp']);

/**
* Returns the per-event sampling rate for component-mounted telemetry events.
* Uses a higher rate for SignIn/SignUp to improve signal quality.
*
* @internal
*/
function getComponentMountedSamplingRate(component: string): number {
return AUTH_COMPONENTS.has(component) ? 1 : EVENT_SAMPLING_RATE;
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to go from 10% to 100%? Not objecting to it, just want to call out that we can probably get a representative sample at a lower sampling rate.

Copy link
Contributor Author

@heatlikeheatwave heatlikeheatwave Sep 26, 2025

Choose a reason for hiding this comment

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

I think if this was telemetry event data we used in isolation we could lower the sampling rate, but we're trying to compare the telemetry event for this between keyless (which has 100% sampling for this event) and all SDKs. I might have that wrong though, and we could lower it. What do you think?

}

type ComponentMountedBase = {
component: string;
};
Expand All @@ -18,6 +31,8 @@ type EventPrebuiltComponent = ComponentMountedBase & {
type EventComponentMounted = ComponentMountedBase & TelemetryEventRaw['payload'];

/**
* Factory for prebuilt component telemetry events.
*
* @internal
*/
function createPrebuiltComponentEvent(event: typeof EVENT_COMPONENT_MOUNTED | typeof EVENT_COMPONENT_OPENED) {
Expand All @@ -28,7 +43,8 @@ function createPrebuiltComponentEvent(event: typeof EVENT_COMPONENT_MOUNTED | ty
): TelemetryEventRaw<EventPrebuiltComponent> {
return {
event,
eventSamplingRate: EVENT_SAMPLING_RATE,
eventSamplingRate:
event === EVENT_COMPONENT_MOUNTED ? getComponentMountedSamplingRate(component) : EVENT_SAMPLING_RATE,
payload: {
component,
appearanceProp: Boolean(props?.appearance),
Expand Down Expand Up @@ -91,7 +107,7 @@ export function eventComponentMounted(
): TelemetryEventRaw<EventComponentMounted> {
return {
event: EVENT_COMPONENT_MOUNTED,
eventSamplingRate: EVENT_SAMPLING_RATE,
eventSamplingRate: getComponentMountedSamplingRate(component),
payload: {
component,
...props,
Expand Down