Skip to content

chore(logging): move device_id into Segment identity traits MONGOSH-2234 #2450

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

Merged
merged 9 commits into from
Jun 2, 2025

Conversation

gagik
Copy link
Contributor

@gagik gagik commented May 7, 2025

Our track function was misleadingly typed with regards to Segment SDK.

For device_id to actually be used by Segment we'd need it to be in traits.device_id in the identify function.

This ties our types closer to the Segment SDK and moves the device ID to traits instead.

this.currentUserId = message.userId ?? message.anonymousId;

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.currentUserId = message.userId ?? message.anonymousId!;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately because of the more derivative type I think TypeScript can no longer correctly resolve this scenario

@gagik gagik added the no-title-validation Skips validation of PR titles (conventional commit adherence + JIRA ticket inclusion) label May 7, 2025
Copy link
Collaborator

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

Code changes LGTM, is there a ticket that should be attached to this?

@gagik gagik changed the title chore(logging): move device_id into Segment identity traits chore(logging): move device_id into Segment identity traits MONGOSH-2234 Jun 2, 2025
@gagik gagik force-pushed the gagik/move-device_id branch from 163850a to 66e1d89 Compare June 2, 2025 08:15
export type MongoshAnalyticsIdentity = Omit<
SegmentIdentity,
'context' | 'traits' | 'timestamp'
>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

[2025/06/02 10:17:26.877] src/cli-repl.ts(646,11): error TS2322: Type 'Analytics | undefined' is not assignable to type 'MongoshAnalytics | undefined'.
[2025/06/02 10:17:26.877]   Type 'Analytics' is not assignable to type 'MongoshAnalytics'.
[2025/06/02 10:17:26.877]     Types of property 'identify' are incompatible.
[2025/06/02 10:17:26.877]       Type '({ userId, anonymousId, traits, context, timestamp, integrations, }: IdentifyParams, callback?: Callback | undefined) => void' is not assignable to type '(message: AnalyticsIdentifyMessage) => void'.
[2025/06/02 10:17:26.877]         Types of parameters '__0' and 'message' are incompatible.
[2025/06/02 10:17:26.877]           Type 'AnalyticsIdentifyMessage' is not assignable to type 'IdentifyParams'.
[2025/06/02 10:17:26.877]             Type 'AnalyticsIdentifyMessage' is not assignable to type '{ traits?: UserTraits | undefined; context?: ExtraContext | undefined; timestamp?: Timestamp | undefined; integrations?: Integrations | undefined; } & { ...; }'.
[2025/06/02 10:17:26.877]               Type 'AnalyticsIdentifyMessage' is not assignable to type '{ userId?: string | undefined; anonymousId: string; }'.
[2025/06/02 10:17:26.877]                 Types of property 'anonymousId' are incompatible.
[2025/06/02 10:17:26.877]                   Type 'string | undefined' is not assignable to type 'string'.
[2025/06/02 10:17:26.877]                     Type 'undefined' is not assignable to type 'string'.

@gagik gagik force-pushed the gagik/move-device_id branch from ae019cb to de74a6f Compare June 2, 2025 09:30
@gagik gagik force-pushed the gagik/move-device_id branch from 6a195a3 to 3788ddd Compare June 2, 2025 10:22
@gagik gagik merged commit 81dbf27 into main Jun 2, 2025
14 of 15 checks passed
@gagik gagik deleted the gagik/move-device_id branch June 2, 2025 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-title-validation Skips validation of PR titles (conventional commit adherence + JIRA ticket inclusion)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants