Skip to content

fix: print the empty and personal API key setup errors without debug - #996

Open
turnipdabeets wants to merge 4 commits into
fix/v4-v1-rubric-followupsfrom
fix/v4-setup-key-log
Open

turnipdabeets wants to merge 4 commits into
fix/v4-v1-rubric-followupsfrom
fix/v4-setup-key-log

Conversation

@turnipdabeets

@turnipdabeets turnipdabeets commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Follow-up to #989, agreed with the capture v1 spec author on sdk-specs#146: when setup leaves the SDK disabled because projectToken is empty or a personal API key (phx_...), print the reason even with debug off. Otherwise the app silently sends nothing.

  • Both lines now go through PostHogSDK.printWarning, an internal hook that defaults to hedgeLogWarning, which already prints without debug (it's used for the missing capture route warning).
  • The per-flush failure lines stay debug-only, since they can repeat on every flush during an outage.
  • The 4.0 changeset and the migration guide mention the warning.

💚 How did you test it?

  • Added disabledSetupWarns, which injects printWarning and checks both warnings with debug off. It fails if either line goes back to hedgeLog.
  • make test filter=disabledSetupWarns, make lint and make buildSdkSpm pass.

📝 Checklist

  • All commits are signed (see Commit signing)
  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file (updated the existing v4-major-release changeset)

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

  • Claude Code checked the setup logging on the iOS, Android and Flutter v1 branches to answer the spec thread, then made this change.

🤖 Generated with Claude Code

@turnipdabeets turnipdabeets self-assigned this Oct 29, 2026
@turnipdabeets
turnipdabeets requested a review from a team as a code owner October 29, 2026 14:29
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

posthog-ios Compliance Report

Date: 2026-10-31T02:29:18.713312+00:00
Duration: 981050ms

✅ All Tests Passed!

233/233 tests passed


Capture_V1 Tests

✅ 106/106 tests passed

View Details
Test Status Duration
Endpoint And Method.Targets V1 Endpoint ✅ 2789ms
Endpoint And Method.Does Not Use Legacy Endpoints ✅ 2795ms
Required Headers.Has Authorization Bearer Header ✅ 2628ms
Required Headers.Has Content Type Json ✅ 2757ms
Required Headers.Has Posthog Sdk Info Format ✅ 2646ms
Required Headers.Has Posthog Attempt Header ✅ 2635ms
Required Headers.Has Posthog Request Id ✅ 2766ms
Required Headers.Has Posthog Request Timestamp ✅ 2634ms
Required Headers.Has User Agent ✅ 2789ms
Body Format.Body Has Created At And Batch ✅ 2744ms
Body Format.No Api Key In Body ✅ 2806ms
Body Format.No Sent At In Body ✅ 2727ms
Event Format.Event Has Required Root Fields ✅ 2633ms
Event Format.Event Uuid Is Valid ✅ 2649ms
Event Format.Event Timestamp Is Rfc3339 ✅ 2691ms
Event Format.Non Utc Event Timestamp Is Converted To Utc ✅ 2624ms
Event Format.Distinct Id Is String ✅ 2692ms
Event Format.Distinct Id At Root Not Properties ✅ 2606ms
Event Format.Custom Properties Preserved ✅ 2706ms
Event Format.Set Properties Preserved ✅ 2699ms
Event Format.Set Once Properties Preserved ✅ 2785ms
Event Format.Groups Properties Preserved ✅ 2723ms
Event Format.Sdk Generates Uuid If Not Provided ✅ 2808ms
Event Format.Event Has Required Root Fields Batch ✅ 2902ms
Event Format.Event Uuid Is Valid Batch ✅ 2815ms
Event Format.Event Timestamp Is Rfc3339 Batch ✅ 2802ms
Event Format.Distinct Id Is String Batch ✅ 2788ms
Event Format.Distinct Id At Root Not Properties Batch ✅ 2774ms
Event Format.Custom Properties Preserved Batch ✅ 2735ms
Event Format.Set Properties Preserved Batch ✅ 2816ms
Event Format.Set Once Properties Preserved Batch ✅ 2852ms
Event Format.Groups Properties Preserved Batch ✅ 2732ms
Event Format.Sdk Generates Uuid If Not Provided Batch ✅ 415ms
Batch Behavior.Multiple Events In Single Batch ✅ 2885ms
Batch Behavior.Batch Envelope Smoke ✅ 2800ms
Batch Behavior.Flush With No Events Sends Nothing ✅ 324ms
Batch Behavior.Flush At Triggers Batch ✅ 1124ms
Batch Behavior.Created At Reflects Batch Creation Time ✅ 2751ms
Deduplication.Generates Unique Uuids ✅ 2834ms
Deduplication.Different Events Same Content Different Uuids ✅ 2767ms
Deduplication.Preserves Uuid On Retry ✅ 9274ms
Deduplication.Preserves Timestamp On Retry ✅ 9298ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 7818ms
Deduplication.No Duplicate Events In Batch ✅ 2865ms
Header Behavior On Retry.Attempt Header Starts At One ✅ 2632ms
Header Behavior On Retry.Attempt Header Increments On Retry ✅ 16773ms
Header Behavior On Retry.Request Id Preserved On Retry ✅ 9202ms
Header Behavior On Retry.Different Requests Have Different Request Ids ✅ 5006ms
Header Behavior On Retry.Request Timestamp Changes On Retry ✅ 5239ms
Response Format Validation.Success Response Has Uuid Keyed Results ✅ 2788ms
Response Format Validation.Success Response Has Ok For Each Event ✅ 2785ms
Response Format Validation.Success No Retry After When All Ok ✅ 2820ms
Response Format Validation.Success Retry After Present When Retry Events ✅ 2699ms
Response Format Validation.Success No Retry After When Drop Only ✅ 2754ms
Response Format Validation.Response Echoes Request Id ✅ 2736ms
Retry Behavior.Retries On 408 ✅ 9251ms
Retry Behavior.Retries On 500 ✅ 9331ms
Retry Behavior.Retries On 503 ✅ 11597ms
Retry Behavior.Retries On 504 ✅ 9192ms
Retry Behavior.Retries On 404 ✅ 8684ms
Retry Behavior.Retries On 429 ✅ 8751ms
Retry Behavior.Retries On 502 ✅ 9262ms
Retry Behavior.Retryable Errors Have Retry After ✅ 5784ms
Retry Behavior.Respects Retry After On Retryable Error ✅ 10686ms
Retry Behavior.Does Not Retry On 400 ✅ 4641ms
Retry Behavior.Does Not Retry On 401 ✅ 4744ms
Retry Behavior.Does Not Retry On 402 ✅ 4764ms
Retry Behavior.Does Not Retry On 413 ✅ 4638ms
Retry Behavior.Does Not Retry On 415 ✅ 4758ms
Retry Behavior.Non Retryable Errors Have No Retry After ✅ 4679ms
Retry Behavior.Implements Backoff ✅ 17795ms
Partial Batch Handling.Handles 200 Full Success ✅ 4760ms
Partial Batch Handling.Handles 200 With All Ok ✅ 5751ms
Partial Batch Handling.Does Not Retry Dropped Events ✅ 5679ms
Partial Batch Handling.Does Not Retry Warning Events ✅ 5802ms
Partial Batch Handling.Prunes Ok Events On Partial Retry ✅ 7702ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry ✅ 7680ms
Partial Batch Handling.Retries Only Retry Events From Partial ✅ 7817ms
Partial Batch Handling.Partial Retry Preserves Uuids ✅ 7808ms
Partial Batch Handling.Partial Retry Attempt Header Increments ✅ 7728ms
Partial Batch Handling.Partial Retry Request Id Preserved ✅ 7685ms
Partial Batch Handling.Respects Retry After On Partial ✅ 7815ms
Partial Batch Handling.Unknown Result Treated As Terminal ✅ 5796ms
Partial Batch Handling.Mixed Ok Drop Warning No Retry ✅ 5700ms
Compression.Sends Gzip Content Encoding ✅ 2643ms
Compression.No Content Encoding When Disabled ✅ 2758ms
Compression.Compressed Body Is Decompressible ✅ 2617ms
Error Handling.Does Not Retry On Unknown 4Xx ✅ 4718ms
Event Options.Cookieless Mode Override ✅ 2674ms
Event Options.Disable Skew Correction Override ✅ 2652ms
Event Options.Process Person Profile Override ✅ 2733ms
Event Options.Product Tour Id Override ✅ 2720ms
Event Options.Unset Options Omitted ✅ 2781ms
Event Options.Options Override In Batch ✅ 2700ms
Event Options.Unknown Option Passes Through ✅ 2772ms
Event Options.Option Value Is Not Converted ✅ 2755ms
Event Options.Lenient Bool Option Values Are Not Converted ✅ 2746ms
Event Options.Option Wins Over Legacy Property ✅ 250ms
Event Options.Legacy Property Fills Unset Option ✅ 2750ms
Event Options.Null Option Falls Back To Legacy Property ✅ 2761ms
Property Layers.Caller Property Beats Registered Property ✅ 231ms
Property Layers.Before Send Runs Last ✅ 2713ms
Fail Open.Empty Api Key Sends Nothing ✅ 1320ms
Fail Open.Personal Api Key Sends Nothing ✅ 1202ms
Geoip And Historical Migration.Geoip Disable Injected Into Properties ✅ 2769ms
Geoip And Historical Migration.Historical Migration Absent By Default ✅ 2749ms

Capture_Ai_V1 Tests

✅ 110/110 tests passed

View Details
Test Status Duration
Endpoint And Method.Targets V1 Endpoint ✅ 2772ms
Endpoint And Method.Does Not Use Legacy Endpoints ✅ 2756ms
Endpoint And Method.Capture Does Not Reroute Ai Named Events ✅ 344ms
Endpoint And Method.Capture Ai Does Not Reroute Non Ai Events ✅ 323ms
Lane Isolation.Failing Ai Lane Does Not Delay Analytics ✅ 11784ms
Required Headers.Has Authorization Bearer Header ✅ 2626ms
Required Headers.Has Content Type Json ✅ 304ms
Required Headers.Has Posthog Sdk Info Format ✅ 2631ms
Required Headers.Has Posthog Attempt Header ✅ 2619ms
Required Headers.Has Posthog Request Id ✅ 2757ms
Required Headers.Has Posthog Request Timestamp ✅ 2725ms
Required Headers.Has User Agent ✅ 2729ms
Body Format.Body Has Created At And Batch ✅ 397ms
Body Format.No Api Key In Body ✅ 2739ms
Body Format.No Sent At In Body ✅ 2667ms
Event Format.Event Has Required Root Fields ✅ 2757ms
Event Format.Event Uuid Is Valid ✅ 2743ms
Event Format.Event Timestamp Is Rfc3339 ✅ 2697ms
Event Format.Non Utc Event Timestamp Is Converted To Utc ✅ 2750ms
Event Format.Distinct Id Is String ✅ 336ms
Event Format.Distinct Id At Root Not Properties ✅ 2758ms
Event Format.Custom Properties Preserved ✅ 2754ms
Event Format.Set Properties Preserved ✅ 2746ms
Event Format.Set Once Properties Preserved ✅ 2759ms
Event Format.Groups Properties Preserved ✅ 2771ms
Event Format.Sdk Generates Uuid If Not Provided ✅ 2749ms
Event Format.Event Has Required Root Fields Batch ✅ 2754ms
Event Format.Event Uuid Is Valid Batch ✅ 2731ms
Event Format.Event Timestamp Is Rfc3339 Batch ✅ 2697ms
Event Format.Distinct Id Is String Batch ✅ 2772ms
Event Format.Distinct Id At Root Not Properties Batch ✅ 2730ms
Event Format.Custom Properties Preserved Batch ✅ 2796ms
Event Format.Set Properties Preserved Batch ✅ 2707ms
Event Format.Set Once Properties Preserved Batch ✅ 2792ms
Event Format.Groups Properties Preserved Batch ✅ 2800ms
Event Format.Sdk Generates Uuid If Not Provided Batch ✅ 2700ms
Batch Behavior.Multiple Events In Single Batch ✅ 2839ms
Batch Behavior.Batch Envelope Smoke ✅ 2809ms
Batch Behavior.Flush At Triggers Batch ✅ 1140ms
Batch Behavior.Created At Reflects Batch Creation Time ✅ 345ms
Deduplication.Generates Unique Uuids ✅ 3099ms
Deduplication.Different Events Same Content Different Uuids ✅ 2802ms
Deduplication.Preserves Uuid On Retry ✅ 9134ms
Deduplication.Preserves Timestamp On Retry ✅ 9140ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 7751ms
Deduplication.No Duplicate Events In Batch ✅ 2700ms
Header Behavior On Retry.Attempt Header Starts At One ✅ 378ms
Header Behavior On Retry.Attempt Header Increments On Retry ✅ 16645ms
Header Behavior On Retry.Request Id Preserved On Retry ✅ 8821ms
Header Behavior On Retry.Different Requests Have Different Request Ids ✅ 7253ms
Header Behavior On Retry.Request Timestamp Changes On Retry ✅ 9238ms
Response Format Validation.Success Response Has Uuid Keyed Results ✅ 2636ms
Response Format Validation.Success Response Has Ok For Each Event ✅ 2800ms
Response Format Validation.Success No Retry After When All Ok ✅ 2664ms
Response Format Validation.Success Retry After Present When Retry Events ✅ 2807ms
Response Format Validation.Success No Retry After When Drop Only ✅ 2689ms
Response Format Validation.Response Echoes Request Id ✅ 352ms
Retry Behavior.Retries On 408 ✅ 9259ms
Retry Behavior.Retries On 500 ✅ 9315ms
Retry Behavior.Retries On 503 ✅ 11685ms
Retry Behavior.Retries On 504 ✅ 9134ms
Retry Behavior.Retries On 404 ✅ 5332ms
Retry Behavior.Retries On 429 ✅ 9215ms
Retry Behavior.Retries On 502 ✅ 9318ms
Retry Behavior.Retryable Errors Have Retry After ✅ 5730ms
Retry Behavior.Respects Retry After On Retryable Error ✅ 10710ms
Retry Behavior.Does Not Retry On 400 ✅ 4670ms
Retry Behavior.Does Not Retry On 401 ✅ 4672ms
Retry Behavior.Does Not Retry On 402 ✅ 4748ms
Retry Behavior.Does Not Retry On 413 ✅ 4621ms
Retry Behavior.Does Not Retry On 415 ✅ 4779ms
Retry Behavior.Non Retryable Errors Have No Retry After ✅ 4663ms
Retry Behavior.Implements Backoff ✅ 18799ms
Partial Batch Handling.Handles 200 Full Success ✅ 4771ms
Partial Batch Handling.Handles 200 With All Ok ✅ 5806ms
Partial Batch Handling.Does Not Retry Dropped Events ✅ 5748ms
Partial Batch Handling.Does Not Retry Warning Events ✅ 5792ms
Partial Batch Handling.Prunes Ok Events On Partial Retry ✅ 7782ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry ✅ 7741ms
Partial Batch Handling.Retries Only Retry Events From Partial ✅ 7672ms
Partial Batch Handling.Partial Retry Preserves Uuids ✅ 7765ms
Partial Batch Handling.Partial Retry Attempt Header Increments ✅ 7761ms
Partial Batch Handling.Partial Retry Request Id Preserved ✅ 7766ms
Partial Batch Handling.Respects Retry After On Partial ✅ 7735ms
Partial Batch Handling.Unknown Result Treated As Terminal ✅ 5775ms
Partial Batch Handling.Mixed Ok Drop Warning No Retry ✅ 5837ms
Compression.Sends Gzip Content Encoding ✅ 2731ms
Compression.No Content Encoding When Disabled ✅ 2650ms
Compression.Compressed Body Is Decompressible ✅ 2799ms
Error Handling.Does Not Retry On Unknown 4Xx ✅ 2337ms
Event Options.Cookieless Mode Override ✅ 2719ms
Event Options.Disable Skew Correction Override ✅ 2760ms
Event Options.Process Person Profile Override ✅ 2749ms
Event Options.Product Tour Id Override ✅ 2767ms
Event Options.Unset Options Omitted ✅ 2766ms
Event Options.Options Override In Batch ✅ 2753ms
Event Options.Unknown Option Passes Through ✅ 2720ms
Event Options.Option Value Is Not Converted ✅ 352ms
Event Options.Lenient Bool Option Values Are Not Converted ✅ 2652ms
Event Options.Option Wins Over Legacy Property ✅ 2763ms
Event Options.Legacy Property Fills Unset Option ✅ 2735ms
Event Options.Null Option Falls Back To Legacy Property ✅ 2692ms
Event Size.Event Over Ceiling Is Not Sent ✅ 6405ms
Event Size.Batches Close Before Byte Target ✅ 8331ms
Geoip And Historical Migration.Geoip Disable Injected Into Properties ✅ 2697ms
Geoip And Historical Migration.Historical Migration Absent By Default ✅ 236ms
Property Layers.Caller Property Beats Registered Property ✅ 2659ms
Property Layers.Before Send Runs Last ✅ 2743ms
Fail Open.Empty Api Key Sends Nothing ✅ 1216ms
Fail Open.Personal Api Key Sends Nothing ✅ 1171ms

Feature_Flags Tests

✅ 17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 2770ms
Request Payload.Flags Request Uses V2 Query Param ✅ 2700ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 2634ms
Request Payload.Flags Request Omits Authorization Header ✅ 2784ms
Request Payload.Token In Flags Body Matches Init ✅ 2719ms
Request Payload.Groups Round Trip ✅ 2784ms
Request Payload.Groups Default To Empty Object ✅ 2649ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 2797ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 2702ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 2765ms
Request Lifecycle.No Flags Request On Init Alone ✅ 48ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 2642ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 5414ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 2782ms
Retry Behavior.Retries Flags On 502 ✅ 2749ms
Retry Behavior.Retries Flags On 504 ✅ 2772ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 2896ms

@eli-r-ph eli-r-ph left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The compliance check here runs harness 1.14.0 (214/219), because #989 doesn't include #938's harness bump (#988) yet. Updating #989 from #938 should rerun these on 1.26.0.

A personal API key (`phx_...`) in `projectToken` now disables the SDK at setup, as an empty token does, and logs why when `debug` is on.

This PR prints the key error without debug, so this line can say it prints a warning, also without debug.

Comment thread PostHog/PostHogSDK.swift Outdated

if config.projectToken.isEmpty {
hedgeLog("PostHog SDK will be disabled because projectToken is empty.")
hedgeLogWarning("PostHog SDK will be disabled because projectToken is empty.")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could a test check that these two warnings print with debug off? Going back to hedgeLog would still pass CI today. An injectable printer like PostHogApi.printWarning would make it testable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 74093d6 — added PostHogSDK.printWarning and a test that fails if either line goes back to hedgeLog.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased onto #989's new tip, so this commit is now 2d0d16a.

@turnipdabeets
turnipdabeets force-pushed the fix/v4-v1-rubric-followups branch from dcb70b9 to bda7086 Compare October 30, 2026 16:12
@turnipdabeets

Copy link
Copy Markdown
Contributor Author

@eli-r-ph Your review summary points: the guide line is fixed in c76f612, and #989 now includes #988, so compliance here runs the 1.26.0 harness (233/233).

@dustinbyrne dustinbyrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both setup-warning cases are covered, and the migration guide now matches the behavior. No issues found.

AI-assisted review.

… p3-996

# Conflicts:
#	.changeset/v4-capture-v1.md
#	docs/migration-3.x-to-4.0.md

This branch has not been deployed

No deployments
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.

3 participants