Skip to content

chore: defer machine ID resolution #161

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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

chore: defer machine ID resolution #161

wants to merge 17 commits into from

Conversation

gagik
Copy link
Collaborator

@gagik gagik commented Apr 29, 2025

Fixes #122
This defers the device ID resolution and add a timeout for resolution. Buffers events in the meantime.

@gagik gagik requested a review from nirinchev April 29, 2025 11:34
@gagik gagik requested a review from a team as a code owner April 29, 2025 11:34
private readonly eventCache: EventCache
) {}

static create(
Copy link
Collaborator Author

@gagik gagik Apr 29, 2025

Choose a reason for hiding this comment

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

while this is not asyncronous. I'm using create(...) to make it clear there are associated side effects

@gagik gagik force-pushed the gagik/use-machine-id branch 3 times, most recently from f9ba638 to 2eb44fb Compare April 29, 2025 12:54
@gagik gagik force-pushed the gagik/use-machine-id branch 2 times, most recently from b78be48 to 9be3e12 Compare April 29, 2025 13:31
@gagik gagik force-pushed the gagik/use-machine-id branch 3 times, most recently from 5ae2584 to 5348a3a Compare April 29, 2025 14:06
@gagik gagik force-pushed the gagik/use-machine-id branch from af9631b to c869d63 Compare April 29, 2025 14:25
@gagik
Copy link
Collaborator Author

gagik commented Apr 29, 2025

This has revealed a very major problem with our Build vs Jest setup targetting entirely different module resolutions... Unfortunately I can't think of a good solution... node-machine-id is the only CommonJS-only dependency we have and it completely breaks our ability to test and build

gagik added 5 commits April 29, 2025 17:52
We did not have a full ESM configuration for jest and therefore had a discrepancy between our build vs test. This discrepancy leads to issues with CommonJS modules.
@@ -76,8 +76,6 @@ export function setupMongoDBIntegrationTest(): MongoDBIntegrationTest {
let dbsDir = path.join(tmpDir, "mongodb-runner", "dbs");
for (let i = 0; i < 10; i++) {
try {
// TODO: Fix this type once mongodb-runner is updated.
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

drive-by

Copy link
Collaborator

@nirinchev nirinchev left a comment

Choose a reason for hiding this comment

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

Minor comments from me. I wonder if we should split it into 2 - one PR that just replaces native-machine-id with node-machine-id, which should hopefully be a drop-in replacement, then another one that does the deferred telemetry initialization.

Comment on lines +8 to +9
resolve!: (value: T) => void;
reject!: (reason: unknown) => void;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need the assertions here?

Suggested change
resolve!: (value: T) => void;
reject!: (reason: unknown) => void;
resolve: (value: T) => void;
reject: (reason: unknown) => void;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, this is more of a late intialization assertion. typescript isn't smart enough to understand they're being set in the constructor

@gagik gagik changed the title chore: use non-native dependency for machine ID and defer machine ID resolution chore: defer machine ID resolution Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Defer machine ID resolution
2 participants