Skip to content

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

Merged
merged 3 commits into from
Feb 15, 2025
Merged

Conversation

haacked
Copy link
Collaborator

@haacked haacked commented Feb 15, 2025

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.

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.
Copy link
Contributor

@greptile-apps greptile-apps bot left a 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
Copy link
Contributor

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();
Copy link
Contributor

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

Comment on lines +111 to +113
UnencryptedRemoteConfigSetting = (await posthog.GetRemoteConfigPayloadAsync("unencrypted-remote-config-setting", HttpContext.RequestAborted))?.RootElement.GetRawText();

EncryptedRemoteConfigSetting = (await posthog.GetRemoteConfigPayloadAsync("encrypted-remote-config-setting", HttpContext.RequestAborted))?.RootElement.GetRawText();
Copy link
Contributor

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

@haacked haacked enabled auto-merge February 15, 2025 01:14
@haacked haacked disabled auto-merge February 15, 2025 01:14
@haacked haacked merged commit 3990a7a into main Feb 15, 2025
4 checks passed
@haacked haacked deleted the haacked/remote-config-fix branch February 15, 2025 01:14
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