-
Notifications
You must be signed in to change notification settings - Fork 33
feat: propagate userProperties and groups in feature flag events & log request headers in debug mode #382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…g request headers in debug mode This change addresses two issues: 1. When `getFeatureFlagStateless` calls `captureStateless` for the `$feature_flag_called` event, it now propagates the `personProperties` (as userProperties) and `groups` to the event. Previously these properties were available but not passed through, meaning the feature flag evaluation context was lost in the captured event. 2. In debug mode, the HTTP API now logs all request headers that are being sent. This helps developers troubleshoot issues by seeing exactly what headers are included in requests (User-Agent, Content-Type, Authorization, etc.).
The server module's PostHogConfig was missing the evaluationContexts property that exists in the core PostHogConfig. This meant that even when users set evaluationContexts in their server config, it wasn't being propagated to the core config and therefore wasn't sent in /flags API requests. This change: - Adds evaluationContexts property to server PostHogConfig constructor - Propagates evaluationContexts to core config in asCoreConfig() - Adds evaluationContexts() method to the Builder class - Adds comprehensive tests for all the above
did not see this issue. trying to solving three problems:
|
|
Also @marandaneto I am seeing here that the library is setting the user agent to posthog-server, and due to that is not being identified as server runtime call. https://posthog.com/docs/api/flags#runtime-detection |
|
@marandaneto as workaround i will override the user agent for the server posthog config :) |
…tion Workaround: 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. Also adds $lib and $lib_version to flags requests for SDK identification, and makes userAgent configurable in PostHogConfig.
c7fde9d to
76e6f3c
Compare
…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
|
the issue 314 (thanks for pointing out this) lets address this in different PRs to make it easier evaluation context has been added recently posthog-android/posthog/CHANGELOG.md Line 8 in 234e186
i think its just not exposed to server yet? @dustinbyrne i dont think we should allow changing the userAgent, whats the use case? lets split this up in 3 PRs |
|
The user agent is just an workaround due to the problem in PostHog/posthog#45652 |
again, this is another issue, another PR |
|
Closing this PR and splitting into 4 focused PRs as requested:
Each PR addresses a specific concern for easier review and merging. |
Summary
personPropertiesandgroupstocaptureStatelesswhen$feature_flag_calledevents are sent during feature flag evaluationevaluationContextssupport to server module'sPostHogConfig(was missing and not propagated to core config)$liband$lib_versionto/flagsAPI requests for SDK identificationposthog-java/serverUser-Agent for server-side runtime detection (PostHog doesn't recognizeposthog-server/yet)Details
Feature Flag Event Context
When
getFeatureFlagStatelesscallscaptureStatelessfor the$feature_flag_calledevent, thepersonPropertiesandgroupsare now propagated to provide full context.Debug Header Logging
When
debug=true, request headers are logged before sending and response headers + final request headers (after interceptors like gzip) are logged after receiving the response.Server-side Runtime Detection
PostHog uses User-Agent patterns to detect server-side vs client-side SDKs. The recognized patterns include
posthog-java/,posthog-python/, etc., but notposthog-server/.As a workaround, the server SDK now uses
posthog-java/server/{version}as the User-Agent, which matches PostHog's detection patterns and allows server-only feature flags to be returned correctly.The
userAgentproperty inPostHogConfigis now configurable, falling back to{sdkName}/{sdkVersion}if not explicitly set.