Skip to content

Conversation

@igormq
Copy link
Contributor

@igormq igormq commented Jan 22, 2026

Summary

  • Add PosthogServer variant to Library enum for tracking posthog-server user agent
  • Mark as deprecated since users are migrating to posthog-java
  • Parse posthog-server/X.Y.Z user agents correctly

Related: PostHog/posthog-android#386

…K detection

This adds support for the `posthog-server/*` user agent pattern, allowing
client-side SDKs (like posthog-android, posthog-ios) running in server mode
to be properly detected as server-side runtime.

When a client SDK is used on the server (e.g., Android SDK in a backend
service), it can now send `posthog-server/{version}` as the user agent
to receive server-only feature flags.

Related: PostHog/posthog-android#382
@assign-reviewers-posthog assign-reviewers-posthog bot requested a review from a team January 22, 2026 00:44
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 22, 2026

Greptile found no issues!

From now on, if a review finishes and we haven't found any issues, we will not post anything, but you can confirm that we reviewed your changes in the status check section.

This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR".

@rafaeelaudibert
Copy link
Member

Oof @dustinbyrne, this feels a bit wrong. I feel like the SDK should be saying posthog-java rather than posthog-server. Is that something you'd be willing to change now?

We used to get posthog-java, right? Is there a difference between them? Should it be posthog-java-server instead?


Of course, it's saying posthog-server right now (and it forever will since this is live in prod) so we need to fix the flags service.

@marandaneto
Copy link
Member

Oof @dustinbyrne, this feels a bit wrong. I feel like the SDK should be saying posthog-java rather than posthog-server. Is that something you'd be willing to change now?

We used to get posthog-java, right? Is there a difference between them? Should it be posthog-java-server instead?

Of course, it's saying posthog-server right now (and it forever will since this is live in prod) so we need to fix the flags service.

yeah posthog-server is very generic, agree, either just posthog-java or posthog-java-server
relates to PostHog/posthog-android#382 (comment)

igormq pushed a commit to igormq/posthog-android that referenced this pull request Jan 22, 2026
…tion

PostHog's runtime detection uses User-Agent patterns to determine if
requests come from server-side or client-side SDKs. The pattern
"posthog-server/" is not recognized, so we use "posthog-java/server/"
instead until PostHog adds support for "posthog-server/" in their
detection patterns.

Changes:
- Make userAgent configurable in core PostHogConfig (via setter)
- Add getUserAgent() method for internal use
- Server module sets userAgent to "posthog-java/server/{version}"

See: PostHog/posthog#45652
igormq pushed a commit to igormq/posthog-android that referenced this pull request Jan 22, 2026
…tion

PostHog's runtime detection uses User-Agent patterns to determine if
requests come from server-side or client-side SDKs. The pattern
"posthog-server/" is not recognized, so we use "posthog-java/server/"
instead until PostHog adds support for "posthog-java-server/" in their
detection patterns.

Changes:
- Add internal userAgent property to core PostHogConfig (@PostHogInternal)
- Add getUserAgent() method that returns userAgent or falls back to sdkName/sdkVersion
- Server module sets userAgent to "posthog-java/server/{version}"

See: PostHog/posthog#45652
Address PR review feedback to use a more specific SDK name.
@igormq igormq force-pushed the feat/feature-flags-posthog-server-user-agent branch from 16f8460 to 1f7d956 Compare January 22, 2026 15:57
@igormq igormq changed the title feat(feature-flags): add posthog-server user agent for server-side SDK detection feat(feature-flags): add posthog-java-server user agent for server-side SDK detection Jan 22, 2026
@igormq
Copy link
Contributor Author

igormq commented Jan 22, 2026

made the change to use posthog-java-server

@dustinbyrne
Copy link
Contributor

In this context I agree, it's definitely way too vague. However, we have active users on the posthog-server user agent, so I don't know that we should just ignore that. The Library enum is used by some internal metrics tracking, so missing posthog-server means we're also not properly bucketing usage.

I think it's clear that some clean up is in order here, though, and possibly beyond just changing the user agent. To simplify things, I think it makes sense if we begin migrating the SDK back toward posthog-java (or posthog-jvm if we really need to differentiate between the two, but I'm not so sure that's important anymore).

For now, we should definitely track the posthog-server user agent. posthog-java is already included, so if we're good with that, we can begin migrating users over.

@igormq igormq changed the title feat(feature-flags): add posthog-java-server user agent for server-side SDK detection feat(feature-flags): add posthog-server user agent for server-side SDK detection Jan 23, 2026
@dustinbyrne
Copy link
Contributor

Thank you @igormq!

@dustinbyrne dustinbyrne merged commit 546e6d0 into PostHog:master Jan 23, 2026
132 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.

5 participants