diff --git a/.changeset/four-countries-share.md b/.changeset/four-countries-share.md new file mode 100644 index 00000000000..ce084d83ddd --- /dev/null +++ b/.changeset/four-countries-share.md @@ -0,0 +1,5 @@ +--- +"@clerk/shared": patch +--- + +Fixes an issue accessing the `CLERK_TELEMETRY_DEBUG` environment variable during telemetry collection diff --git a/packages/shared/src/telemetry/collector.ts b/packages/shared/src/telemetry/collector.ts index db7e8595af0..a9af381f151 100644 --- a/packages/shared/src/telemetry/collector.ts +++ b/packages/shared/src/telemetry/collector.ts @@ -98,7 +98,10 @@ export class TelemetryCollector implements TelemetryCollectorInterface { // In browser or client environments, we most likely pass the disabled option to the collector, but in environments // where environment variables are available we also check for `CLERK_TELEMETRY_DISABLED`. - if (this.#config.disabled || (typeof process !== 'undefined' && isTruthy(process.env.CLERK_TELEMETRY_DISABLED))) { + if ( + this.#config.disabled || + (typeof process !== 'undefined' && process.env && isTruthy(process.env.CLERK_TELEMETRY_DISABLED)) + ) { return false; } @@ -113,7 +116,10 @@ export class TelemetryCollector implements TelemetryCollectorInterface { } get isDebug(): boolean { - return this.#config.debug || (typeof process !== 'undefined' && isTruthy(process.env.CLERK_TELEMETRY_DEBUG)); + return ( + this.#config.debug || + (typeof process !== 'undefined' && process.env && isTruthy(process.env.CLERK_TELEMETRY_DEBUG)) + ); } record(event: TelemetryEventRaw): void {