Skip to content

feat(admin/logs): expose location and device on admin logs feed#242

Merged
akinwalexander merged 1 commit into
feat/admin-logs-capture-user-agentfrom
feat/admin-logs-expose-location-device
Jun 10, 2026
Merged

feat(admin/logs): expose location and device on admin logs feed#242
akinwalexander merged 1 commit into
feat/admin-logs-capture-user-agentfrom
feat/admin-logs-expose-location-device

Conversation

@ibraheembello

@ibraheembello ibraheembello commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Description

Second of two stacked PRs for the admin activity log. Stacked on #241 (capture user agent); base will be retargeted to dev once that merges. This PR surfaces two derived fields on GET /admin/logs:

  • device: the stored user agent parsed into a Browser Major . OS Version label (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.
  • location: a Region, CC label (e.g. Lagos, NG) resolved from ip_address via freeipapi.com, a keyless HTTPS endpoint, over the built-in fetch. Resolved at read time, cached per IP, and degrades to null on any failure so the feed never breaks.

Both fields are null when 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 fetch instead. Trade-off: location depends on an external service and is null if 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

  • feat: New feature

How Has This Been Tested?

  • Unit tests

  • Manual tests

  • pnpm exec jest src/modules/admin/logs passes (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.21 resolves to Lagos, NG with device Firefox 132 . Windows 10; 8.8.8.8 to California, US; null IP/UA to null.

Test Evidence

image image

Screenshot: admin-logs spec run + the live response showing location and device attached.
image

Additional Notes

Swagger example and description updated to document location and device.

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).
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: a71f2ca0-3299-477f-8513-e5be32ac29be

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/admin-logs-expose-location-device

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@akinwalexander akinwalexander merged commit 7dfa74e into feat/admin-logs-capture-user-agent Jun 10, 2026
5 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