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

refactor(types,shared,elements): Assign telemetry property to main Clerk interface #3329

Merged
merged 8 commits into from
May 7, 2024

Conversation

LauraBeatris
Copy link
Member

@LauraBeatris LauraBeatris commented May 6, 2024

Description

Unblocks SDK-1672

Assigns telemetry property to main Clerk instance to access it within React hooks from shared package, like so:

const clerk = useClerkInstanceContext();
clerk.telemetry?.record(eventMethodCalled('useOrganization'));

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:

@LauraBeatris LauraBeatris self-assigned this May 6, 2024
Copy link

changeset-bot bot commented May 6, 2024

🦋 Changeset detected

Latest commit: 4adcdd5

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

This PR includes changesets to release 15 packages
Name Type
@clerk/shared Patch
@clerk/types Patch
@clerk/elements Patch
@clerk/backend Patch
@clerk/chrome-extension Patch
@clerk/clerk-js Patch
@clerk/clerk-expo Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/clerk-react Patch
@clerk/remix Patch
@clerk/clerk-sdk-node Patch
@clerk/testing Patch
@clerk/themes 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

@LauraBeatris LauraBeatris changed the title refactor(types,shared): Introduce separate type interface for TelemetryCollector refactor(types,shared): Assign telemetry property to main Clerk interface May 6, 2024
@LauraBeatris LauraBeatris force-pushed the add-telemetry-collector-type-interface branch from 6e21347 to 1447a67 Compare May 6, 2024 16:54
@LauraBeatris LauraBeatris force-pushed the add-telemetry-collector-type-interface branch from 1447a67 to b0fb616 Compare May 6, 2024 17:24
@LauraBeatris LauraBeatris requested a review from BRKalow May 6, 2024 17:37
@LauraBeatris LauraBeatris marked this pull request as ready for review May 6, 2024 17:37
@@ -151,7 +151,7 @@ export class Clerk implements ClerkInterface {
public organization: OrganizationResource | null | undefined;
public user: UserResource | null | undefined;
public __internal_country?: string | null;
public telemetry?: TelemetryCollector;
public telemetry: TelemetryCollector | undefined;
Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to | undefined instead of |, otherwise it leads to a build error: Property 'telemetry' is optional in type 'Clerk' but required in type 'Clerk'.

I think it's also good to keep it consistent with the other attributes in here.

Comment on lines 3 to 36
export type TelemetryEvent = {
event: string;
/**
* publishableKey
*/
pk?: string;
/**
* secretKey
*/
sk?: string;
/**
* instanceType
*/
it: InstanceType;
/**
* clerkVersion
*/
cv: string;
/**
* SDK
*/
sdk?: string;
/**
* SDK Version
*/
sdkv?: string;
payload: Record<string, string | number | boolean>;
};

export type TelemetryEventRaw<Payload = TelemetryEvent['payload']> = {
event: TelemetryEvent['event'];
eventSamplingRate?: number;
payload: Payload;
};
Copy link
Member

Choose a reason for hiding this comment

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

Now that we are exposing these as public API i feel that we need to do the following

Rename TelemetryEventRaw to TelemetryEvent
Rename TelemetryEvent to TelemetryRecordedEvent or TelemetryStoredEvent

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree that Raw seems a bit generic here 🤔 - @BRKalow do you have other suggestions on that naming?

Copy link
Member

Choose a reason for hiding this comment

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

🤔 I wouldn't really consider these part of the public API, it's an internal type that we're forced to expose due to how our packages are structured...

Raw feels accurate because it's the "raw" event that we're collecting before transforming it to send to our backend. TelemetryRecordedEvent is fine if we want to rename that.

We could also put a JSDoc with @internal to make it clear these aren't meant for public usage:

/**
 * @internal
 */
export type TelemetryEventRaw = ...

Copy link
Member Author

Choose a reason for hiding this comment

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

Raw feels accurate because it's the "raw" event that we're collecting before transforming it to send to our backend. TelemetryRecordedEvent is fine if we want to rename that.

@BRKalow thanks for the context! I'm going to move forward with adding @internal JSDocs to those interfaces.

@panteliselef
Copy link
Member

@LauraBeatris With this change, this piece of code can be updated as well

@LauraBeatris LauraBeatris changed the title refactor(types,shared): Assign telemetry property to main Clerk interface refactor(types,shared,elements): Assign telemetry property to main Clerk interface May 6, 2024
@LauraBeatris LauraBeatris force-pushed the add-telemetry-collector-type-interface branch from 5f62e54 to c86ab3e Compare May 6, 2024 19:40
@LauraBeatris
Copy link
Member Author

@LauraBeatris With this change, this piece of code can be updated as well

@panteliselef I've just removed the assertion & ts-ignore comment. I'd prefer to remove the entire hook tho, but don't have a strong opinion on this.

It seems that it was only added to override the telemetry type, and the actual benefit is that you don't have to call useClerk() and access it every time.

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.

💯

@LekoArts LekoArts enabled auto-merge (squash) May 7, 2024 09:00
@LekoArts LekoArts merged commit f70c885 into main May 7, 2024
10 checks passed
@LekoArts LekoArts deleted the add-telemetry-collector-type-interface branch May 7, 2024 09:12
@clerk-cookie clerk-cookie mentioned this pull request May 7, 2024
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.

None yet

5 participants