Skip to content

fix: mirror django request user agent into $raw_user_agent#729

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

fix: mirror django request user agent into $raw_user_agent#729
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

The Django middleware tags all events in a request with $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 the middleware with the standardized property. Related: PostHog/posthog#68232.

$user_agent is still sent for backwards compatibility.

💚 How did you test it?

Agent-authored. Extended test_extract_tags_basic to assert both properties carry the request's User-Agent header; ran the middleware extract_tags tests locally (11 passed).

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • Changeset added in .sampo/changesets/.

🤖 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-ruby).

@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 django request user agent in..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

posthog-python Compliance Report

Date: 2026-07-03 15:28:00 UTC
Duration: 177187ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 516ms
Format Validation.Event Has Uuid 1507ms
Format Validation.Event Has Lib Properties 1507ms
Format Validation.Distinct Id Is String 1506ms
Format Validation.Token Is Present 1508ms
Format Validation.Custom Properties Preserved 1506ms
Format Validation.Event Has Timestamp 1507ms
Retry Behavior.Retries On 503 9516ms
Retry Behavior.Does Not Retry On 400 3508ms
Retry Behavior.Does Not Retry On 401 3507ms
Retry Behavior.Respects Retry After Header 9510ms
Retry Behavior.Implements Backoff 23532ms
Retry Behavior.Retries On 500 7505ms
Retry Behavior.Retries On 502 7507ms
Retry Behavior.Retries On 504 7515ms
Retry Behavior.Max Retries Respected 23529ms
Deduplication.Generates Unique Uuids 1496ms
Deduplication.Preserves Uuid On Retry 7515ms
Deduplication.Preserves Uuid And Timestamp On Retry 14512ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 7516ms
Deduplication.No Duplicate Events In Batch 1503ms
Deduplication.Different Events Have Different Uuids 1507ms
Compression.Sends Gzip When Enabled 1506ms
Batch Format.Uses Proper Batch Structure 1507ms
Batch Format.Flush With No Events Sends Nothing 1006ms
Batch Format.Multiple Events Batched Together 1504ms
Error Handling.Does Not Retry On 403 3508ms
Error Handling.Does Not Retry On 413 3508ms
Error Handling.Retries On 408 7514ms

Feature_Flags Tests

17/17 tests passed

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

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