-
-
Notifications
You must be signed in to change notification settings - Fork 268
feat!: add time-based delay for first metrics sending #7624
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!: add time-based delay for first metrics sending #7624
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@metamaskbot publish-previews |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
|
@metamaskbot publish-previews |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
|
@metamaskbot publish-previews |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
|
No dependency changes detected. Learn more about Socket for GitHub. 👍 No dependency changes detected in pull request |
|
@metamaskbot publish-previews |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
| /** | ||
| * The default delay duration before data is sent for the first time, in milliseconds. | ||
| */ | ||
| export const DEFAULT_INITIAL_DELAY_DURATION = 10 * 60 * 1000; // 10 minutes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a nice method in @metamask/utils for this:
| export const DEFAULT_INITIAL_DELAY_DURATION = 10 * 60 * 1000; // 10 minutes | |
| export const DEFAULT_INITIAL_DELAY_DURATION = inMilliseconds(10, Duration.Minute); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's cool! changed in 750feaa
| // it must have opted in during onboarding, or during a previous session. | ||
| this.skipInitialDelay(); | ||
| } | ||
| this.#queueFirstSyncIfNeeded().catch(console.error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this use messenger.captureException?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely, changed to this.messenger.captureException ?? console.error in a70fe32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
messenger.captureException should always be defined in practice, so I think just using messenger?.captureException is ok, but this is fine too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be defined as optional:
core/packages/messenger/src/Messenger.ts
Line 263 in 0237820
| readonly captureException?: (error: Error) => void; |
Without using
console.error as fallback, I still get no-floating-promises errors
Explanation
ProfileMetricsControlleris being overhauled to rely on a timestamp-based delay for the first sending of metrics, rather than waiting for a second App Unlock event. This change ensures that metrics are sent even if the user only unlocks the app once during a session.The delay is skipped immediately if:
KeyringController:unlockis fired (this covers both users who have opted-in in a previous session, and users who just onboarded and opted-in during onboarding)..skipInitialDelay()method or theProfileMetricsController:skipInitialDelayaction via messenger.References
Checklist
Note
Introduces a timestamp-based initial delay for first profile metrics send, with configurable duration and multiple skip paths.
initialDelayEndTimestampstate and default 10-minute delay; constructor acceptsinitialDelayDurationskipInitialDelay()method andProfileMetricsController:skipInitialDelayaction; auto-skip onKeyringController:unlockwhen already opted-in and onTransactionController:transactionSubmitted_executePollexits until delay completes; state metadata updated to persist/expose new fieldTransactionController:transactionSubmitted; add@metamask/transaction-controllerdependency and TS references; export new method-action types; tests and README dependency graph updatedWritten by Cursor Bugbot for commit 0237820. This will update automatically on new commits. Configure here.