-
Notifications
You must be signed in to change notification settings - Fork 585
feat: Add Snap export handler usage tracking #3281
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
base: main
Are you sure you want to change the base?
Conversation
d7e1569
to
5006f1a
Compare
Use registry for metadata Replace controller with hook approach Fix broken unit tests Add unit tests
0683058
to
8bd8e34
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3281 +/- ##
==========================================
+ Coverage 94.73% 97.80% +3.07%
==========================================
Files 518 364 -154
Lines 11947 9940 -2007
Branches 1836 1622 -214
==========================================
- Hits 11318 9722 -1596
+ Misses 629 218 -411 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@@ -1025,6 +1046,25 @@ export class SnapController extends BaseController< | |||
Object.values(this.state?.snaps ?? {}).forEach((snap) => | |||
this.#setupRuntime(snap.id), | |||
); | |||
|
|||
this.#trackSnapExport = throttleTracking( |
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 should check with Christian if we want to track exports for preinstalled Snaps 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.
Can you explain what would be the difference here? Why aren't they tracked with this?
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.
For other metrics, we don't always track preinstalled Snaps because they have a lot of usage and spam the metrics a bit.
E.g. https://github.com/MetaMask/metamask-extension/blob/main/app/scripts/metamask-controller.js#L3048
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 makes sense to skip it then. Added some logic to skip tracking of preinstalled Snaps.
async #getMetadata(snapId: string): Promise<SnapsRegistryMetadata | null> { | ||
const database = await this.#getDatabase(); | ||
return database?.verifiedSnaps[snapId]?.metadata ?? null; | ||
#getMetadata(snapId: string): SnapsRegistryMetadata | null { |
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.
Technically this is a breaking change, but I don't think we use this anywhere?
cc @Mrtenz
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.
Doesn't seem to be used anywhere in the extension outside of the SnapController
at least, but like you said it's still a breaking change technically. If we want to avoid breaking it, we could keep the function async for now, and pair removing it with another breaking change in the future.
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.
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.
IMO not worth it to keep it async, we don't want the performance hit of potentially updating the registry just for analytics
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.
I mean keeping the function signature the same, but returning the result without fetching it asynchronously.
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.
origin, | ||
]; | ||
|
||
if (!previousCalls.has(key) || now - lastCall >= timeout) { |
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.
if (!previousCalls.has(key) || now - lastCall >= timeout) { | |
if (now - lastCall >= timeout) { |
I don't think we need the extra condition since we have a default for lastCall
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.
Updated.
async getRegistryMetadata( | ||
snapId: SnapId, | ||
): Promise<SnapsRegistryMetadata | null> { | ||
getRegistryMetadata(snapId: SnapId): SnapsRegistryMetadata | null { | ||
this.#assertCanUsePlatform(); | ||
return await this.messagingSystem.call('SnapsRegistry:getMetadata', snapId); | ||
return this.messagingSystem.call('SnapsRegistry:getMetadata', snapId); | ||
} |
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.
Honestly this function should probably be deleted, I have no idea why you would want to call SnapController:getRegistryMetadata
when you can just use the registry directly
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.
I don't know, probably I saw it exist and wanted to be consistent in some way. But, it's probably redundant.
Updated now with direct call to SnapsRegistry:getMetadata
, and also removed getRegistryMetadata
function.
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.
Oh I don't mean why you specifically would do it for this PR. I mean why would anyone call this function that we expose 😂
This PR moves MetaMetrics tracking of Snap export usage to Snap Controller.
Related issue: #3259
Extension integration PR: MetaMask/metamask-extension#31553
Mobile integration PR: MetaMask/metamask-mobile#14428