You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@PostHog/team-client-libraries and @haacked i think this is what SDKs should do
can you double check so i can port this fix across SDKs? (i have a bunch of draft PRs already but some of them didnt address all stuff i found during this one)
Same issue as GetRemoteConfigPayloadAsync: IsPersonalApiKeyMissing already logs the generic "personal_api_key is not configured" warning before control reaches LogWarningPersonalApiKeyRequired inside the if-body. The old call is now redundant and should be removed.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/PostHog/PostHogClient.cs
Line: 757-761
Comment:
**Double warning log in `LoadFeatureFlagsAsync`**
Same issue as `GetRemoteConfigPayloadAsync`: `IsPersonalApiKeyMissing` already logs the generic "personal_api_key is not configured" warning before control reaches `LogWarningPersonalApiKeyRequired` inside the `if`-body. The old call is now redundant and should be removed.
How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---### Issue 1 of 2
src/PostHog/PostHogClient.cs:553-556
**Double warning log emitted when `PersonalApiKey` is missing**`IsPersonalApiKeyMissing` already emits `LogWarningPersonalApiKeyMissing` ("PostHog personal_api_key is not configured; {MethodName} is a no-op.") before this `if`-body executes. The call to `LogWarningPersonalApiKeyRequiredForRemoteConfigPayload` on line 555 then fires a second, redundant warning for the same condition. The same pattern exists in `LoadFeatureFlagsAsync` (line 759, `LogWarningPersonalApiKeyRequired`). The old method-specific log calls should be removed now that the unified `IsPersonalApiKeyMissing` helper handles the logging, otherwise every missing-key event produces two warnings.
```suggestion if (IsPersonalApiKeyMissing(nameof(GetRemoteConfigPayloadAsync))) { return null; }```### Issue 2 of 2
src/PostHog/PostHogClient.cs:757-761
**Double warning log in `LoadFeatureFlagsAsync`**
Same issue as `GetRemoteConfigPayloadAsync`: `IsPersonalApiKeyMissing` already logs the generic "personal_api_key is not configured" warning before control reaches `LogWarningPersonalApiKeyRequired` inside the `if`-body. The old call is now redundant and should be removed.
```suggestion if (IsPersonalApiKeyMissing(nameof(LoadFeatureFlagsAsync))) { return; }```
marandaneto
changed the title
Disable client when project token is missing
fix: Disable client when project token is missing
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PostHogOptions.Disabledflag (defaultfalse) and set it when token normalization determines the SDK cannot be initializedpersonal_api_keywhen it is not configured, including local-only feature flag evaluation and remote config payloadsTests
dotnet test tests/UnitTests/UnitTests.csproj --framework net8.0 --filter "FullyQualifiedName~TheDisabledClient|FullyQualifiedName~ThePersonalApiKeyProtectedMethods|FullyQualifiedName~LogsWarningWhenPersonalApiKey|FullyQualifiedName~LogsErrorWhenProjectTokenIsMissing|FullyQualifiedName~LogsWarningWhenProjectApiKeyIsUsed"dotnet test tests/UnitTests/UnitTests.csproj --framework net8.0(fails in existing CaptureException tests:CaptureExceptionWithInvalidFilePathInStackFrame,CaptureExceptionCauseIOFailureEmptyContext)Note: requested context files
context.mdandplan.mdwere not present in this checkout.