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

Add extensionTelemetry #10057

Merged
merged 9 commits into from
Dec 4, 2024
Merged

Add extensionTelemetry #10057

merged 9 commits into from
Dec 4, 2024

Conversation

strseb
Copy link
Collaborator

@strseb strseb commented Nov 20, 2024

Description

This PR adds commands for the extension to send telemetry to the client.
It's a bit bigger, therefore i've split this across 3 commits, for easyier reivew.

  1. In : d6e1d77
    I've only added the metrics, the data review happens in a google doc, i can link that if it's done.
  2. In a897f14
    I add 3 commands: {t:telemetry, name: metric_name: args: any} {t:start_session} {t:stop_session} - Those allow the extension to send any events or counts. For the bools we save them and attach them to the next ping, similar how we do that with our settings related bools.
  3. fa836d6
    I tried the least refactoring solution to allow us to enable telemetry either for the extension or the client. All data is attached to a ping with a name. I've added the ability for glean to filter out on a per ping_name basis. I use that to filter the extensions pings if they are not enabled and the client pings if those are disabled.

@strseb strseb force-pushed the basti/telemetry_ext branch 3 times, most recently from f61f638 to fa836d6 Compare November 25, 2024 13:48
@strseb strseb requested review from oskirby, lesleyjanenorton and mcleinman and removed request for oskirby and lesleyjanenorton November 25, 2024 13:57
@strseb strseb marked this pull request as ready for review November 25, 2024 13:58
@mcleinman
Copy link
Collaborator

This can have an updated title (dropping WIP), right?

@strseb strseb changed the title WIP Add extensionTelemetry Add extensionTelemetry Nov 25, 2024
@strseb
Copy link
Collaborator Author

strseb commented Nov 25, 2024

@mcleinman yes sorry :)

Copy link
Collaborator

@mcleinman mcleinman left a comment

Choose a reason for hiding this comment

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

Thanks for this! Several questions.

It seems like we're doing a bunch of work to allow the user to have glean enabled for the extension but not the client (or the reverse). I'm not sure this is worth the code needed for it - was that a product directive?

src/telemetry/pings.yaml Outdated Show resolved Hide resolved
src/telemetry/extension_metrics.yaml Outdated Show resolved Hide resolved
src/telemetry/extension_metrics.yaml Outdated Show resolved Hide resolved
src/telemetry/extension_metrics.yaml Outdated Show resolved Hide resolved
src/telemetry/extension_metrics.yaml Outdated Show resolved Hide resolved
Comment on lines +112 to +117
description: >
True if the user has disabled the VPN for firefox
Copy link
Collaborator

Choose a reason for hiding this comment

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

Over what length of time are we measuring this? I believe we default to ping in Glean... is this supposed to be "has disabled this ever"? Or "has disabled this in the current session"?

Copy link
Collaborator Author

@strseb strseb Nov 25, 2024

Choose a reason for hiding this comment

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

The metric has a lifetime of ping (and will be attached similar to using_system_language) , the underlying info lives in the Settings and will be cleaned on logout.
We want to measure "has this user ever ever used feature x?"

Copy link
Collaborator

Choose a reason for hiding this comment

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

But unlike using_system_language, we're sending it in every start ping (in recordAllFlags). This seems more appropriate for a lifetime of user - a lifetime of ping where we record it from a app-saved setting doesn't feel like how we'd typically handle Glean.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed that part :)

src/telemetry/extension_metrics.yaml Show resolved Hide resolved
src/telemetry/extension_metrics.yaml Show resolved Hide resolved
src/glean/mzglean.cpp Outdated Show resolved Hide resolved
@strseb
Copy link
Collaborator Author

strseb commented Nov 25, 2024

It seems like we're doing a bunch of work to allow the user to have glean enabled for the extension but not the client (or the reverse). I'm not sure this is worth the code needed for it - was that a product directive?

Yeeeep. Product ask (q_q )" - for the extension we have to offer an extra data opt-in flow just for data related to the extension.
And we the fear is otherwise people press "yes" to collect data but still have glean disabled so nothing gets out.

@oskirby
Copy link
Collaborator

oskirby commented Nov 25, 2024

Maybe this is a silly question to ask, but why do we need an API for the extension send telemetry to the client, only for the client to turn around and send to glean? Couldn't the extension send the telemetry to glean on its own? Surely Mozilla already has some solid mechanisms for intstrumenting extensions in this way?

@@ -783,3 +785,23 @@ SETTING_BOOL(addonApiSetting, // getter
false // sensitive (do not log)
)
#endif

SETTING_UINT(extensionTelemetryFlags, // getter
Copy link
Collaborator

Choose a reason for hiding this comment

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

This feels like an anti-pattern for Glean, and has some possible data retention concerns. The point of Glean is that it handles recording our metrics, and the lifetimes should be able to handle our use cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are totally right, TIL about lifetime =! ping - ripped all of that code out and moved that into the metrics.yaml

@strseb strseb requested a review from mcleinman December 3, 2024 18:53
@strseb
Copy link
Collaborator Author

strseb commented Dec 3, 2024

Maybe this is a silly question to ask, but why do we need an API for the extension send telemetry to the client, only for the client to turn around and send to glean? Couldn't the extension send the telemetry to glean on its own? Surely Mozilla already has some solid mechanisms for intstrumenting extensions in this way?

That is a fair question! - Glean.js is not supported for extensions anymore, so noone knows what would break, there is browser.telemetry forwarding events to firefox glean but for that we need to be privileged, which is a no for a lot of reasons.
Therefore we're here

@@ -73,3 +73,23 @@ daemonsession:
(Android only) Sent every three hours during an active VPN session.
daemon_end: >
Sent after as session ending metric is recorded.
extensionsession:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: There were two line breaks, I thought there should be just one (but wasn't clear, sorry). It was updated to be zero.

src/telemetry/extension_metrics.yaml Outdated Show resolved Hide resolved
Copy link
Collaborator

@mcleinman mcleinman left a comment

Choose a reason for hiding this comment

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

Looks good. A few nits, and one metric typo that I think should be fixed before merging. Thank you!

src/glean/mzglean.cpp Outdated Show resolved Hide resolved
- [email protected]
expires: 2025-06-30

fx_protetion_disabled:
Copy link
Collaborator

Choose a reason for hiding this comment

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

More than other typos, I think this typo should be fixed before merging as it's difficult to change metric names.

Suggested change
fx_protetion_disabled:
fx_protection_disabled:

subscription_needed, signin_needed, split_tunneled
type: string
expires: 2025-06-30
fx_protection_enabled:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
fx_protection_enabled:
fx_protection_enabled:

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Line break

- Added extension_metrics.yaml file to the telemetry directory.
- Defined new metrics for extension usage, including onboarding completion, feature usage, and website exclusions.
- Added extension_metrics.yaml to the list of metrics sent in the extensionsession ping.
- Updated pings.yaml to include extensionsession as a new ping type.
- Included client ID in extensionsession ping.
- Updated bugs, data reviews, and notification emails for the new metrics.
- Added reasons for sending extensionsession ping on session start and end.
- Updated comments to reflect changes.
- Added a new `WebExtensionTelemetry` class to handle WebExtension telemetry events.
- Implemented `fromJson` function to parse JSON telemetry data into `TelemetryInfo` objects.
- Added `recordTelemetry` function to record telemetry events to Glean.
- Implemented `startSession` and `stopSession` functions to track session start and end events.
- Added new handlers for various telemetry events and flags in `handlers.cpp`.
- Updated `webextensionadapter.cpp` to handle telemetry requests.
- Updated `pings.yaml` to include new telemetry pings.
- Updated `webextensiontelemetry.h` to define new telemetry functions and structures.
- Update MZGlean::upadateUploadEnabled() to MZGlean::updateUploadEnabled() for consistency in naming.
- Ensure that the static function updateUploadEnabled() is called correctly in the MZGlean class.
- Update the documentation comments for clarity and consistency.
- Changed the function declaration of `flag` from `consteval` to `constexpr` to ensure that it is a compile-time constant expression.
- This change ensures that the function is not evaluated at runtime, improving performance and avoiding potential issues with runtime evaluation.
@strseb strseb force-pushed the basti/telemetry_ext branch from 077c633 to 5646001 Compare December 4, 2024 14:11
@strseb strseb merged commit 2aa9528 into main Dec 4, 2024
120 checks passed
@strseb strseb deleted the basti/telemetry_ext branch December 4, 2024 15:28
strseb added a commit that referenced this pull request Dec 4, 2024
strseb added a commit that referenced this pull request Dec 10, 2024
* Add extension metrics to extension session ping

- Added extension_metrics.yaml file to the telemetry directory.
- Defined new metrics for extension usage, including onboarding completion, feature usage, and website exclusions.
- Added extension_metrics.yaml to the list of metrics sent in the extensionsession ping.
- Updated pings.yaml to include extensionsession as a new ping type.
- Included client ID in extensionsession ping.
- Updated bugs, data reviews, and notification emails for the new metrics.
- Added reasons for sending extensionsession ping on session start and end.
- Updated comments to reflect changes.

* Add support for WebExtension Telemetry

- Added a new `WebExtensionTelemetry` class to handle WebExtension telemetry events.
- Implemented `fromJson` function to parse JSON telemetry data into `TelemetryInfo` objects.
- Added `recordTelemetry` function to record telemetry events to Glean.
- Implemented `startSession` and `stopSession` functions to track session start and end events.
- Added new handlers for various telemetry events and flags in `handlers.cpp`.
- Updated `webextensionadapter.cpp` to handle telemetry requests.
- Updated `pings.yaml` to include new telemetry pings.
- Updated `webextensiontelemetry.h` to define new telemetry functions and structures.

* Allow filtering on a per-ping basis

* Use glean lifetimes instead of homebrewed stuff

* Address feedback in metrics_yaml

* Address feedback in pings.yaml

* fix typos in c++

* Update upload enablement in MZGlean

- Update MZGlean::upadateUploadEnabled() to MZGlean::updateUploadEnabled() for consistency in naming.
- Ensure that the static function updateUploadEnabled() is called correctly in the MZGlean class.
- Update the documentation comments for clarity and consistency.

* Update flag handling in webextensiontelemetry.cpp

- Changed the function declaration of `flag` from `consteval` to `constexpr` to ensure that it is a compile-time constant expression.
- This change ensures that the function is not evaluated at runtime, improving performance and avoiding potential issues with runtime evaluation.
@strseb strseb mentioned this pull request Dec 10, 2024
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.

3 participants