feat(admin/logs): expose location and device on admin logs feed#242
Merged
akinwalexander merged 1 commit intoJun 10, 2026
Conversation
GET /admin/logs now returns two derived fields per entry: - device: the stored user agent parsed into a 'Browser Major . OS Version' label by a dependency-free parser (Chrome, Firefox, Safari, Edge, Opera across Windows, macOS, iOS, Android, Linux). - location: a 'Region, CC' label resolved from ip_address via freeipapi.com, a keyless HTTPS endpoint, over the built-in fetch. Cached per IP and degrades to null on any failure so the feed never breaks. The offline geo-IP database that would avoid the network call is a banned dependency. Both fields are null when they cannot be resolved (no IP, no user agent, private/loopback address, or provider unreachable).
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
akinwalexander
approved these changes
Jun 10, 2026
7dfa74e
into
feat/admin-logs-capture-user-agent
5 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Second of two stacked PRs for the admin activity log. Stacked on #241 (capture user agent); base will be retargeted to
devonce that merges. This PR surfaces two derived fields onGET /admin/logs:Browser Major . OS Versionlabel (e.g.Chrome 134 . macOS 10.15.7) by a dependency-free parser covering Chrome, Firefox, Safari, Edge and Opera across Windows, macOS, iOS, Android and Linux.Region, CClabel (e.g.Lagos, NG) resolved fromip_addressviafreeipapi.com, a keyless HTTPS endpoint, over the built-infetch. Resolved at read time, cached per IP, and degrades tonullon any failure so the feed never breaks.Both fields are
nullwhen unresolvable (no IP, no user agent, private/loopback address, or provider unreachable).Why no new dependency
Device parsing and IP geo-resolution are both done without adding a package, per the team's no-new-deps rule. The offline geo-IP database that would avoid the network call is exactly the kind of dependency the team blocks, so location is looked up at read time over
fetchinstead. Trade-off: location depends on an external service and isnullif it is unreachable.Note on OS version accuracy
Browsers freeze the high-entropy OS version in the legacy User-Agent string (macOS reports
10_15_7, Windows 11 reports NT 10.0), so the OS portion is best-effort. The format matches the design exactly; the values are as precise as the UA allows.Related Issue
N/A. Requested directly by the frontend (admin activity log design adds location and device columns).
Type of Change
How Has This Been Tested?
Unit tests
Manual tests
pnpm exec jest src/modules/admin/logspasses (UA parser, geo service, and the service mapping including location + device).Verified end to end against a local Postgres with live geo lookups:
102.89.33.21resolves toLagos, NGwith deviceFirefox 132 . Windows 10;8.8.8.8toCalifornia, US; null IP/UA tonull.Test Evidence
Screenshot: admin-logs spec run + the live response showing location and device attached.

Additional Notes
Swagger example and description updated to document
locationanddevice.