Skip to content

feat: add billable event api and route token#1340

Open
prakharritik wants to merge 1 commit into
mainfrom
claude/festive-gates-6eOcd
Open

feat: add billable event api and route token#1340
prakharritik wants to merge 1 commit into
mainfrom
claude/festive-gates-6eOcd

Conversation

@prakharritik

@prakharritik prakharritik commented Jun 9, 2026

Copy link
Copy Markdown

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates

Description

Additional Changes

  • This PR modifies the database schema (database migration added)
  • This PR modifies dhall configs/environment variables

Motivation and Context

How did you test it?

Checklist

  • I formatted the code and addressed linter errors ./dev/format-all-files.sh
  • I reviewed submitted code
  • I added unit tests for my changes where possible
  • I added a CHANGELOG entry if applicable

Summary by CodeRabbit

  • New Features

    • Best-effort reporting of billable events to Google Maps Mobility Billing (non-blocking, logs failures).
    • Optional configuration for a custom Mobility Billing endpoint.
  • Updates

    • Routes now capture and surface optional route tokens when provided by Google Maps.
    • Routing requests ask for route tokens and route-construction/route-data structures updated across providers to propagate them consistently.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds optional routeToken to route types and provider mappings, requests routes.routeToken from Google Maps for advanced directions, adds mobilityBillingUrl to Google config, introduces a MobilityBilling client and exported reportBillableEvent, and exposes the new module in the library.

Changes

Route Token Support

Layer / File(s) Summary
Route information schema updates
lib/mobility-core/src/Kernel/External/Maps/Interface/Types.hs, lib/mobility-core/src/Kernel/External/Maps/Google/MapsClient/Types.hs
RouteInfo record extended with routeToken :: Maybe Text; RouteV2 extended with routeToken :: Maybe Text for Google Maps JSON.
Google Maps client and interface
lib/mobility-core/src/Kernel/External/Maps/Google/MapsClient.hs, lib/mobility-core/src/Kernel/External/Maps/Interface/Google.hs
Google Maps field-mask updated to request routes.routeToken; mkRoute' maps Google response route.routeToken into RouteInfo.routeToken for advanced directions; basic directions set routeToken = Nothing.
Alternative provider route mapping
lib/mobility-core/src/Kernel/External/Maps/Interface/MMI.hs, lib/mobility-core/src/Kernel/External/Maps/Interface/NextBillion.hs, lib/mobility-core/src/Kernel/External/Maps/Interface/OSRM.hs
MMI, NextBillion, and OSRM providers updated to include routeToken field (set to Nothing) when constructing RouteInfo.
Google Mobility Billing service
lib/mobility-core/src/Kernel/External/Maps/Google/MobilityBilling.hs, lib/mobility-core/src/Kernel/External/Maps/Google/Config.hs
New module defines ReportBillableEventAPI and exports reportBillableEvent, a best-effort POST client that logs success or error without throwing; GoogleCfg gains optional mobilityBillingUrl.
Library module exposition
lib/mobility-core/mobility-core.cabal
Kernel.External.Maps.Google.MobilityBilling added to library exposed-modules.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 I found a token on the trail,
I logged a hop, I wagged my tail,
Providers give what they can share,
A billing ping floats through the air,
I munch a carrot, then I sail.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add billable event api and route token' accurately summarizes the main changes: adding the MobilityBilling API and extending RouteInfo/RouteV2 with routeToken support across multiple files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/festive-gates-6eOcd

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/mobility-core/src/Kernel/External/Maps/Google/MobilityBilling.hs`:
- Around line 76-77: The logs currently emit raw billableEventId in the success
and error branches (the Right _ -> logInfo ... and Left err -> logError ...
calls); change those to log a redacted or hashed identifier instead — e.g.
compute a deterministic pseudonym like sha256(billableEventId) or mask all but
the last N characters and log that derived value (e.g. hashedId or maskedId)
along with the message and, in the error case, include show err; update both
places so no raw billableEventId is written to logs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5d58548a-81e7-4ead-a0b2-4834f2ecc950

📥 Commits

Reviewing files that changed from the base of the PR and between b63a48c and 382a1bf.

📒 Files selected for processing (9)
  • lib/mobility-core/mobility-core.cabal
  • lib/mobility-core/src/Kernel/External/Maps/Google/MapsClient.hs
  • lib/mobility-core/src/Kernel/External/Maps/Google/MapsClient/Types.hs
  • lib/mobility-core/src/Kernel/External/Maps/Google/MobilityBilling.hs
  • lib/mobility-core/src/Kernel/External/Maps/Interface/Google.hs
  • lib/mobility-core/src/Kernel/External/Maps/Interface/MMI.hs
  • lib/mobility-core/src/Kernel/External/Maps/Interface/NextBillion.hs
  • lib/mobility-core/src/Kernel/External/Maps/Interface/OSRM.hs
  • lib/mobility-core/src/Kernel/External/Maps/Interface/Types.hs

Comment on lines +76 to +77
Right _ -> logInfo $ "Reported Google mobility billable event for trip " <> billableEventId
Left err -> logError $ "Failed to report Google mobility billable event for trip " <> billableEventId <> ": " <> show err

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Avoid logging raw billableEventId values in info/error logs.

These logs persist trip identifiers verbatim, which can create avoidable privacy/compliance exposure in centralized logging. Prefer redaction or hashing before logging.

Suggested patch
-  case result of
-    Right _ -> logInfo $ "Reported Google mobility billable event for trip " <> billableEventId
-    Left err -> logError $ "Failed to report Google mobility billable event for trip " <> billableEventId <> ": " <> show err
+  let tripRef = "(redacted)"
+  case result of
+    Right _ -> logInfo $ "Reported Google mobility billable event for trip " <> tripRef
+    Left err -> logError $ "Failed to report Google mobility billable event for trip " <> tripRef <> ": " <> show err
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/mobility-core/src/Kernel/External/Maps/Google/MobilityBilling.hs` around
lines 76 - 77, The logs currently emit raw billableEventId in the success and
error branches (the Right _ -> logInfo ... and Left err -> logError ... calls);
change those to log a redacted or hashed identifier instead — e.g. compute a
deterministic pseudonym like sha256(billableEventId) or mask all but the last N
characters and log that derived value (e.g. hashedId or maskedId) along with the
message and, in the error case, include show err; update both places so no raw
billableEventId is written to logs.

@prakharritik prakharritik force-pushed the claude/festive-gates-6eOcd branch from a80eb34 to 4dc9c98 Compare June 10, 2026 06:53
@prakharritik prakharritik force-pushed the claude/festive-gates-6eOcd branch from da63efe to 84a7942 Compare June 10, 2026 09:50
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