-
Notifications
You must be signed in to change notification settings - Fork 7
Fix accessing remote config settings #53
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
The remote config endpoint returns JSON encoded in a string. `"{\"foo\": \"bar\",\"baz\": 42}"` Instead of: `{"foo": "bar","baz": 42}` However, we may change that in the future. So this is implemented in a forward-compatible way to handle both options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR enhances the PostHog .NET client's handling of remote config settings to support both string-encoded and raw JSON formats from the API endpoint.
- Added forward-compatible JSON parsing in
PostHogClient.cs
to handle both"{\"foo\": \"bar\"}"
and{"foo": "bar"}
formats - Implemented comprehensive test cases in
RemoteConfigTests.cs
covering various JSON response scenarios (raw, string-encoded, double-encoded) - Added helper method
TryParseJson
with proper error handling for safely parsing string-encoded JSON - Updated version to 1.0.0-beta.10 to reflect the remote config handling improvements
- Enhanced sample web application to demonstrate both encrypted and unencrypted remote config settings
6 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile
await posthog.GetRemoteConfigPayloadAsync( | ||
"unencrypted-remote-config-setting"); | ||
|
||
> @Model.UnencryptedRemoteConfigSetting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: The '>' character before @Model.UnencryptedRemoteConfigSetting seems unnecessary and inconsistent with the encrypted setting display below
@@ -103,6 +107,10 @@ await posthog.IdentifyAsync( | |||
} | |||
|
|||
NonExistentFlag = await posthog.IsFeatureEnabledAsync("non-existent-flag", UserId); | |||
|
|||
UnencryptedRemoteConfigSetting = (await posthog.GetRemoteConfigPayloadAsync("unencrypted-remote-config-setting", HttpContext.RequestAborted))?.RootElement.GetRawText(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: GetRawText() may throw if RootElement is invalid JSON. Consider wrapping in try-catch
UnencryptedRemoteConfigSetting = (await posthog.GetRemoteConfigPayloadAsync("unencrypted-remote-config-setting", HttpContext.RequestAborted))?.RootElement.GetRawText(); | ||
|
||
EncryptedRemoteConfigSetting = (await posthog.GetRemoteConfigPayloadAsync("encrypted-remote-config-setting", HttpContext.RequestAborted))?.RootElement.GetRawText(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: These calls could be parallelized using Task.WhenAll for better performance
The remote config endpoint returns JSON encoded in a string.
"{\"foo\": \"bar\",\"baz\": 42}"
Instead of:
{"foo": "bar","baz": 42}
However, we may change that in the future.
So this is implemented in a forward-compatible way to handle both options.