Skip to content

ads-client: make telemetry a singleton with the glean-sym API - #7653

Merged
Almaju merged 4 commits into
mozilla:mainfrom
Almaju:ads-client-telemetry-singleton
Oct 15, 2026
Merged

Almaju merged 4 commits into
mozilla:mainfrom
Almaju:ads-client-telemetry-singleton

Conversation

@Almaju

@Almaju Almaju commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Telemetry becomes a process-wide singleton recorded with plain telemetry::record_* calls, matching the API glean-sym will use. For now the backend still forwards to the MozAdsTelemetry callback.

  • Removes the T: Telemetry generic; nothing threads telemetry through the clients, transport or store any more.
  • Core owns a Telemetry trait and the singleton; the FFI layer wraps MozAdsTelemetry to implement it. Switching to glean-sym only swaps telemetry/backend.rs.
  • MozAdsClientBuilder::build() installs the callback; MozAdsClient::shutdown() uninstalls it unless another client has replaced it since.
  • Behaviour change: the callback is global, so it receives metrics from every client in the process. The binding API is unchanged; the usage docs are updated to match.

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • This PR follows the breaking change policy:
      • This PR has no breaking API changes, or
      • There are corresponding PRs for our consumer applications that resolve the breaking changes and have been approved
  • Quality: This PR builds and tests run cleanly
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGELOG.md or an explanation of why it does not need one
  • Dependencies: This PR follows our dependency management guidelines

Comment thread components/ads-client/src/lib.rs Outdated
inner: AdsClient<MozAdsTelemetryWrapper>,
inner: AdsClient,
// The telemetry callback this client installed, if any.
telemetry: Option<Installation>,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: I would like to call this something other than Installation if it's being used outside of the telemetry module (eg: here), this line in particular is a bit obscure to me if I were reading it blindly.

Comment thread components/ads-client/src/lib.rs Outdated
// Drop the telemetry callback this client installed, unless another client has replaced it.
if let Some(telemetry) = &self.telemetry {
telemetry.uninstall();
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is there a reason we've moved the telemetry being held within the AdsClient to the FFI/uniffi layer? I'm not opposed to it, but my understanding (esp. given recent lock changes) are we want to remove as much functionality from FFI layer as possible.

(especially given that this encapsulates a Weak and can be copied everywhere)

/// Receives the ads client's metrics, for the app to record in Glean.
#[uniffi::export(callback_interface)]
pub trait MozAdsTelemetry: Send + Sync {
// By design: the foreign callback signature; labels come from `metrics.yaml`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit/question: if our labels are sourced from metrics.yaml (eg: external), might it be better to centralize them or use an enum or something so we can easily ratify it if things change?

(eg: seeing the impl AdsStoreBuilderError block elsewhere).

@thesuzerain

Copy link
Copy Markdown
Collaborator

I generally still have mixed feelings about the singleton of this in the first place, but this is a good implementation IMO and the singleton is still the best step forward here given our discussion.

@Almaju
Almaju marked this pull request as ready for review October 14, 2026 18:53
@Almaju
Almaju requested a review from a team as a code owner October 14, 2026 18:53
@Almaju
Almaju requested review from mashalifshin and removed request for a team October 14, 2026 18:53
Replace the `T: Telemetry` generic threaded through AdsClient, MARSClient,
MARSTransport, AdsStoreBuilder and AdResponse::parse with free
`telemetry::record_*` functions backed by a process-wide singleton. The
recording API matches the one glean-sym will use, so moving to glean-sym
later only swaps the backend.

For now the backend forwards to a core `Telemetry` trait, which the FFI
layer implements by wrapping the `MozAdsTelemetry` callback.
`MozAdsClientBuilder::build()` installs it and `MozAdsClient::shutdown()`
uninstalls it, unless another client has since replaced it.
- Replace the installation handle with plain `telemetry::install()` and
  `telemetry::uninstall()`; telemetry is set up once per process, and
  `AdsClient::shutdown()` drops the callback.
- Keep `MozAdsTelemetryWrapper` private to the FFI telemetry module.
- Define every metric label in `telemetry.rs`, one enum per metric
  mirroring `metrics.yaml`.
- Move `NoopMozAdsTelemetry` to `test_utils`.
@Almaju
Almaju force-pushed the ads-client-telemetry-singleton branch from 34caa99 to 2f729e2 Compare October 14, 2026 19:09
@Almaju
Almaju enabled auto-merge October 14, 2026 19:16
@Almaju
Almaju added this pull request to the merge queue Oct 14, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 14, 2026
@Almaju
Almaju enabled auto-merge October 15, 2026 00:03
@Almaju
Almaju added this pull request to the merge queue Oct 15, 2026
Merged via the queue into mozilla:main with commit d785f1d Oct 15, 2026
15 of 16 checks passed
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.

2 participants