Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(shared): Add opt-out support for SDK telemetry #2099

Merged
merged 7 commits into from
Nov 13, 2023

Conversation

brkalow
Copy link
Member

@brkalow brkalow commented Nov 9, 2023

Description

Adds opt-out support to the TelemetryCollector by way of the disabled option. We also moved the initialization of TelemetryCollector to Clerk.load instead of its constructor to make it easier to pass options.

fixes SDK-915

Checklist

  • npm test runs as expected.
  • npm run 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:

Packages affected

  • @clerk/backend
  • @clerk/chrome-extension
  • @clerk/clerk-js
  • @clerk/clerk-expo
  • @clerk/fastify
  • gatsby-plugin-clerk
  • @clerk/localizations
  • @clerk/nextjs
  • @clerk/clerk-react
  • @clerk/remix
  • @clerk/clerk-sdk-node
  • @clerk/shared
  • @clerk/themes
  • @clerk/types
  • build/tooling/chore

…ialization to Clerk.load, implement opt-out for Next
Copy link

changeset-bot bot commented Nov 9, 2023

⚠️ No Changeset found

Latest commit: 2f72334

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Comment on lines +328 to +339
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,
});
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved the TelemetryCollector instantiation into Clerk.load() instead of the constructor. It's much easier to pass options this way.

@@ -168,7 +173,6 @@ export default class IsomorphicClerk {
domain: this.domain,
} as any);

c.sdkMetadata = this.options.sdkMetadata ?? SDK_METADATA;
Copy link
Member Author

Choose a reason for hiding this comment

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

Cleaning up this metadata thing by handling it in Clerk.load().

@@ -186,18 +204,18 @@ export class TelemetryCollector {
'Content-Type': 'application/json',
},
})
.catch(err => console.error(err))
.catch(() => void 0)
Copy link
Member Author

Choose a reason for hiding this comment

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

Swallowing errors here to ensure we don't create noise as a result of our telemetry.


jest.useFakeTimers();

describe('TelemetryCollector', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Added some high-level tests for the collector. Most importantly, validating that events aren't sent when disabled or debug are true.

@brkalow brkalow marked this pull request as ready for review November 9, 2023 23:56
@brkalow brkalow requested a review from a team as a code owner November 9, 2023 23:56
@brkalow brkalow merged commit 85c5a45 into brk.feat/telemetry-spike Nov 13, 2023
1 check passed
@brkalow brkalow deleted the brk.feat/telemetry-opt-out branch November 13, 2023 18:40
github-merge-queue bot pushed a commit that referenced this pull request Nov 22, 2023
* 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
desiprisg pushed a commit that referenced this pull request Nov 23, 2023
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants