Skip to content

MPP-4012 - feat(glean): log API access as Glean server event #5500

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

Merged
merged 4 commits into from
Apr 15, 2025

Conversation

groovecoder
Copy link
Member

@groovecoder groovecoder commented Apr 9, 2025

TODO

Introduce a new api.accessed Glean event to capture accesses to Relay API endpoints. This includes the HTTP method and endpoint path, and logs events for all /api/ prefixed routes via a new middleware component.

  • Added record_api_accessed() to EventsServerEventLogger
  • Extended RelayGleanLogger with log_api_accessed() for easier integration
  • Registered GleanApiAccessMiddleware to log access for all API routes
  • Added corresponding unit test for API access logging
  • Updated relay-server-metrics.yaml to define the api.accessed metric
  • Updated notification email for several existing metrics to use [email protected]

This PR fixes #MPP-4012 and #MPP-4014.

How to test:

  1. Run pytest should test that glean logging is working
    - https://app.circleci.com/pipelines/github/mozilla/fx-private-relay/21940/workflows/94f38d67-3f2c-4c0a-baac-19fb47402351/jobs/251876
  2. The glean probe scraper GitHub workflow should pass
    - https://github.com/mozilla/fx-private-relay/actions/runs/14453273732/job/40530682690?pr=5500
  • l10n changes have been submitted to the l10n repository, if any.
  • I've added a unit test to test for potential regressions of this bug.
  • I've added or updated relevant docs in the docs/ directory.
  • All UI revisions follow the coding standards, and use Protocol / Nebula colors where applicable (see /frontend/src/styles/colors.scss).
  • Commits in this PR are minimal and have descriptive commit messages.

@groovecoder groovecoder requested a review from jwhitlock April 9, 2025 20:22
@groovecoder groovecoder force-pushed the add-api-count-MPP-4012 branch 2 times, most recently from 742c483 to a2534c3 Compare April 11, 2025 21:00
Introduce a new `api.accessed` Glean event to capture accesses to Relay API
endpoints. This includes the HTTP method and endpoint path, and logs events
for all `/api/` prefixed routes via a new middleware component.

- Added `record_api_accessed()` to `EventsServerEventLogger`
- Extended `RelayGleanLogger` with `log_api_accessed()` for easier integration
- Registered `GleanApiAccessMiddleware` to log access for all API routes
- Added corresponding unit test for API access logging
- Updated `relay-server-metrics.yaml` to define the `api.accessed` metric
- Updated notification email for several existing metrics to use [email protected]
@groovecoder groovecoder force-pushed the add-api-count-MPP-4012 branch from a2534c3 to e14c6c3 Compare April 11, 2025 22:16
Comment on lines +117 to +119
"endpoint": str(endpoint),
"method": str(method),
"fxa_id": str(fxa_id),
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure why glean_parser wrapped these argument values in str() calls this time, but not in other places?

…ents

Add metric definitions for `text_received` and `call_received` to the Glean YAML.

Log the events with `fxa_id` if metrics are enabled for the user.
@groovecoder groovecoder marked this pull request as ready for review April 14, 2025 18:49
@groovecoder groovecoder changed the title WIP: MPP-4012 - feat(glean): log API access as Glean server event MPP-4012 - feat(glean): log API access as Glean server event Apr 14, 2025
@groovecoder groovecoder added this pull request to the merge queue Apr 15, 2025
Merged via the queue into main with commit 2788ea5 Apr 15, 2025
32 checks passed
@groovecoder groovecoder deleted the add-api-count-MPP-4012 branch April 15, 2025 15:16
Copy link

sentry-io bot commented Apr 23, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ SystemExit: 1 /api/v1/relayaddresses/ View Issue
  • ‼️ SystemExit: 1 /api/v1/relayaddresses/ View Issue

Did you find this useful? React with a 👍 or 👎

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