Skip to content

feat(server): Add request context support#522

Merged
dustinbyrne merged 3 commits into
mainfrom
feat/server-request-context
May 27, 2026
Merged

feat(server): Add request context support#522
dustinbyrne merged 3 commits into
mainfrom
feat/server-request-context

Conversation

@dustinbyrne
Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Server-side SDK users handling frontend requests need a safe way to carry PostHog frontend tracing context into backend captures. This adds request-scoped context support for posthog-server, so captures and exception captures can inherit frontend distinct/session metadata while still preserving explicit SDK call overrides.

💚 How did you test it?

  • ./gradlew :posthog-server:test --tests "com.posthog.server.PostHogRequestContextTest" --tests "com.posthog.server.PostHogEvaluateFlagsTest"
  • make checkFormat
  • ./gradlew :posthog-server:test
  • git diff --check
  • make api

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Added a changeset file (.changeset/request-context-server.md)

@dustinbyrne dustinbyrne force-pushed the feat/server-request-context branch from ec3bde4 to f6c2cdb Compare May 26, 2026 20:29
@dustinbyrne dustinbyrne marked this pull request as ready for review May 26, 2026 20:30
@dustinbyrne dustinbyrne requested a review from a team as a code owner May 26, 2026 20:30
@dustinbyrne dustinbyrne changed the title Add server request context support feat(server): Add request context support May 26, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 26, 2026

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
posthog-server/src/test/java/com/posthog/server/PostHogEvaluateFlagsTest.kt:235-299
**Duplicate tests should be parameterized**

`evaluateFlags uses request context distinctId when omitted` and `evaluateFlags uses request context distinctId when null` are structurally identical — the only difference is calling `postHog.evaluateFlags()` vs `postHog.evaluateFlags(null)`. Per the team's preference for parameterized tests, these two cases should be collapsed into a single `@ParameterizedTest` (e.g. using a boolean parameter or a supplier for the call-under-test).

Reviews (1): Last reviewed commit: "fix: allow nullable request context dist..." | Re-trigger Greptile

@dustinbyrne dustinbyrne enabled auto-merge (squash) May 27, 2026 17:56
@dustinbyrne dustinbyrne merged commit 1aa4328 into main May 27, 2026
12 checks passed
@dustinbyrne dustinbyrne deleted the feat/server-request-context branch May 27, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants