Skip to content

fix: mirror rails request user agent into $raw_user_agent#216

Draft
lricoy wants to merge 1 commit into
mainfrom
lricoy/mirror-raw-user-agent
Draft

fix: mirror rails request user agent into $raw_user_agent#216
lricoy wants to merge 1 commit into
mainfrom
lricoy/mirror-raw-user-agent

Conversation

@lricoy

@lricoy lricoy commented Jul 3, 2026

Copy link
Copy Markdown
Member

💡 Motivation and Context

posthog-rails attaches the request's User-Agent to events as $user_agent, but PostHog's server-side classification — web analytics bot detection ($virt_is_bot and friends) and the materialized-column fast path — keys on the standardized $raw_user_agent property (the one posthog-js sends). Server-side-tracked pageviews forwarding a real client UA are exactly the traffic where bot classification matters, and today they miss it.

PostHog/posthog#68253 removes the $user_agent query-time fallback for performance (it forced a full properties-blob read on every classification query — see the PR for production measurements), so this change mirrors the header into $raw_user_agent, aligning posthog-rails with the standardized property. Related: PostHog/posthog#68232.

$user_agent is still sent for backwards compatibility.

💚 How did you test it?

Agent-authored. Extended the request-context specs to assert $raw_user_agent carries the same value in all four scenarios that assert $user_agent; relying on CI to run rspec (no compatible local ruby toolchain in this session).

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • Changeset added for posthog-rails.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Built with Claude Code as part of a cross-repo effort to standardize on $raw_user_agent (PostHog/posthog#68232, PostHog/posthog#68253, with sibling PRs to posthog-android and posthog-python).

@lricoy lricoy self-assigned this Jul 3, 2026
@greptile-apps

greptile-apps Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix: mirror rails request user agent int..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

posthog-ruby Compliance Report

Date: 2026-07-03 15:26:53 UTC
Duration: 97975ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 106ms
Format Validation.Event Has Uuid 105ms
Format Validation.Event Has Lib Properties 108ms
Format Validation.Distinct Id Is String 106ms
Format Validation.Token Is Present 105ms
Format Validation.Custom Properties Preserved 106ms
Format Validation.Event Has Timestamp 106ms
Retry Behavior.Retries On 503 5312ms
Retry Behavior.Does Not Retry On 400 2108ms
Retry Behavior.Does Not Retry On 401 2108ms
Retry Behavior.Respects Retry After Header 8014ms
Retry Behavior.Implements Backoff 15621ms
Retry Behavior.Retries On 500 5211ms
Retry Behavior.Retries On 502 5211ms
Retry Behavior.Retries On 504 5210ms
Retry Behavior.Max Retries Respected 15517ms
Deduplication.Generates Unique Uuids 109ms
Deduplication.Preserves Uuid On Retry 5211ms
Deduplication.Preserves Uuid And Timestamp On Retry 10315ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5213ms
Deduplication.No Duplicate Events In Batch 109ms
Deduplication.Different Events Have Different Uuids 106ms
Compression.Sends Gzip When Enabled 105ms
Batch Format.Uses Proper Batch Structure 105ms
Batch Format.Flush With No Events Sends Nothing 4ms
Batch Format.Multiple Events Batched Together 108ms
Error Handling.Does Not Retry On 403 2107ms
Error Handling.Does Not Retry On 413 2108ms
Error Handling.Retries On 408 5210ms

Feature_Flags Tests

17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 108ms
Request Payload.Flags Request Uses V2 Query Param 107ms
Request Payload.Flags Request Hits Flags Path Not Decide 108ms
Request Payload.Flags Request Omits Authorization Header 105ms
Request Payload.Token In Flags Body Matches Init 106ms
Request Payload.Groups Round Trip 106ms
Request Payload.Groups Default To Empty Object 106ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 105ms
Request Payload.Disable Geoip Omitted Defaults To False 106ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 106ms
Request Lifecycle.No Flags Request On Init Alone 3ms
Request Lifecycle.No Flags Request On Normal Capture 105ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 109ms
Request Lifecycle.Mock Response Value Is Returned To Caller 104ms
Retry Behavior.Retries Flags On 502 209ms
Retry Behavior.Retries Flags On 504 208ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 108ms

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.

1 participant