feat(shared): Add opt-out support for SDK telemetry#2099
feat(shared): Add opt-out support for SDK telemetry#2099brkalow merged 7 commits intobrk.feat/telemetry-spikefrom
Conversation
…ialization to Clerk.load, implement opt-out for Next
|
| if (this.#options.sdkMetadata) { | ||
| Clerk.sdkMetadata = this.#options.sdkMetadata; | ||
| } | ||
|
|
||
| this.#telemetry = new TelemetryCollector({ | ||
| clerkVersion: Clerk.version, | ||
| verbose: true, | ||
| samplingRate: 1, | ||
| // @ts-expect-error -- in v5 this will always be defined | ||
| publishableKey: this.publishableKey, | ||
| ...this.#options.telemetry, | ||
| }); |
There was a problem hiding this comment.
Moved the TelemetryCollector instantiation into Clerk.load() instead of the constructor. It's much easier to pass options this way.
| domain: this.domain, | ||
| } as any); | ||
|
|
||
| c.sdkMetadata = this.options.sdkMetadata ?? SDK_METADATA; |
There was a problem hiding this comment.
Cleaning up this metadata thing by handling it in Clerk.load().
| }, | ||
| }) | ||
| .catch(err => console.error(err)) | ||
| .catch(() => void 0) |
There was a problem hiding this comment.
Swallowing errors here to ensure we don't create noise as a result of our telemetry.
|
|
||
| jest.useFakeTimers(); | ||
|
|
||
| describe('TelemetryCollector', () => { |
There was a problem hiding this comment.
Added some high-level tests for the collector. Most importantly, validating that events aren't sent when disabled or debug are true.
* feat(clerk-js): Spike out telemetry collection * feat(clerk-js): Add sampling rate and verbose option * feat(shared): Move TelemtryCollector into shared, make it isomorphic * feat(nextjs): Add telemtry collection for authMiddleware * feat(shared): Support passing multiple events to the telemetry endpoint * feat(shared): Abstract fetch into sendEvent * feat(shared): Refactor SDK metadata handling to get accurate value * feat(shared): Update endpoint, don't use no-cors * fix(nextjs): Fix merge conflict * feat(shared): Add batching to the telemetry collector * feat(shared): Add opt-out support for SDK telemetry (#2099) * feat(clerk-js): Add TelemetryCollector instance to backend client (#2134) * chore(repo): Add changeset * fix(shared): Fix tests that rely on fetch * feat(shared): Set production endpoint * feat(clerk-js): Make telemtry public, expose via isomorphicClerk * feat(shared): Add doc on the TelemetryCollector * feat(clerk-js): Support telemetry: false as a way to disable telemetry * chore(shared): Tweak comment * chore(shared): Tweak comment * fix(clerk-sdk-node): Add PACKAGE_ constants for tests * fix(fastify): Define PACKAGE_ constants in test environment * feat(shared): Refactor telemetry instrumentation to rely on helpers * feat(shared): Add telemetry notice * feat(shared): Add postinstall script * chore(shared): Add word * chore(shared): Swallow errors in postinstall * chore(repo): Allow scripts directory in subpaths-workaround * feat(shared): Adjust types to enforce the event structure from event factory methods * chore(shared): Simplify telemetry.record() API
* feat(clerk-js): Spike out telemetry collection * feat(clerk-js): Add sampling rate and verbose option * feat(shared): Move TelemtryCollector into shared, make it isomorphic * feat(nextjs): Add telemtry collection for authMiddleware * feat(shared): Support passing multiple events to the telemetry endpoint * feat(shared): Abstract fetch into sendEvent * feat(shared): Refactor SDK metadata handling to get accurate value * feat(shared): Update endpoint, don't use no-cors * fix(nextjs): Fix merge conflict * feat(shared): Add batching to the telemetry collector * feat(shared): Add opt-out support for SDK telemetry (#2099) * feat(clerk-js): Add TelemetryCollector instance to backend client (#2134) * chore(repo): Add changeset * fix(shared): Fix tests that rely on fetch * feat(shared): Set production endpoint * feat(clerk-js): Make telemtry public, expose via isomorphicClerk * feat(shared): Add doc on the TelemetryCollector * feat(clerk-js): Support telemetry: false as a way to disable telemetry * chore(shared): Tweak comment * chore(shared): Tweak comment * fix(clerk-sdk-node): Add PACKAGE_ constants for tests * fix(fastify): Define PACKAGE_ constants in test environment * feat(shared): Refactor telemetry instrumentation to rely on helpers * feat(shared): Add telemetry notice * feat(shared): Add postinstall script * chore(shared): Add word * chore(shared): Swallow errors in postinstall * chore(repo): Allow scripts directory in subpaths-workaround * feat(shared): Adjust types to enforce the event structure from event factory methods * chore(shared): Simplify telemetry.record() API
Description
Adds opt-out support to the TelemetryCollector by way of the
disabledoption. We also moved the initialization ofTelemetryCollectortoClerk.loadinstead of its constructor to make it easier to pass options.fixes SDK-915
Checklist
npm testruns as expected.npm run buildruns as expected.Type of change
Packages affected
@clerk/backend@clerk/chrome-extension@clerk/clerk-js@clerk/clerk-expo@clerk/fastifygatsby-plugin-clerk@clerk/localizations@clerk/nextjs@clerk/clerk-react@clerk/remix@clerk/clerk-sdk-node@clerk/shared@clerk/themes@clerk/typesbuild/tooling/chore