Skip to content

fix!: analytics setup problems never fail the app - #369

Merged
eli-r-ph merged 3 commits into
v1from
v1-disabled-client
Oct 22, 2026
Merged

eli-r-ph merged 3 commits into
v1from
v1-disabled-client

Conversation

@eli-r-ph

@eli-r-ph eli-r-ph commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

#356 made both constructors fail on a blank API key, so a missing env var can now crash a Go app.
Every other PostHog SDK returns a disabled client instead; this restores that behavior, keeps (Client, error) for invalid config, and applies the same rule to the MCP and OpenTelemetry integrations.

Changes

  • An empty or personal (phx_...) API key returns a disabled client, a nil error and one error log.
  • A disabled client sends nothing, and its methods return ErrSDKDisabled.
  • New Config.Disabled builds a disabled client for tests and local development.
  • The key is never logged, and a phx_ key is never sent.
  • posthogmcpsdk.NewMiddleware and Instrument no longer panic on nil analytics; they report one error and pass every request through unchanged.
  • The otel bridge's NewExporter and NewSpanProcessor treat an empty or phx_ key the same way: one error log and an exporter or processor that sends nothing.

@dustinbyrne this partly reverses #356, so a key problem never stops an app in any SDK.

💚 How did you test it?

  • A table test covers empty, whitespace, phx_ and Config.Disabled keys: no requests, one error log, no key in logs.
  • The same cases for the otel constructors, and a nil-analytics MCP server whose tool calls and schemas stay unchanged.
  • go test -race passes alone and merged onto the top of the v1 stack (docs: complete the v2 migration guide and changesets #368).

🤖 Agent context

Autonomy: Human-driven (agent-assisted). Written with Claude Code; restores the no-op client removed in #356.

🤖 Generated with Claude Code

@eli-r-ph eli-r-ph self-assigned this Oct 13, 2026
@eli-r-ph
eli-r-ph marked this pull request as ready for review October 13, 2026 01:52
@eli-r-ph
eli-r-ph requested a review from a team as a code owner October 13, 2026 01:52
@eli-r-ph

Copy link
Copy Markdown
Contributor Author

👋 hey @dustinbyrne some context on reversing 356 here - while researching other parity issues and locking in global decisions for v1 SDK behavior as I prep public release docs, I found some things about the 356 change:

  • Only Go SDK would have this fail-fast behavior so far
  • Makes creating a no-op client prickly
  • Introduces new hard errors in end user's existing posthog-go usage

If you think this compromise (error on wrong token type; no-op client on missing token at init) is a bad call, or your goal is to normalize the fail-fast behavior across all v1 SDKs, that works for me, let's chat about it.

If not, I'm hoping to normalize the behavior here across all v1 SDKs (including those with live prep branches and future conversions for the fleet.)

@eli-r-ph eli-r-ph changed the title fix: return a disabled client for a missing or personal API key fix: missing or personal API key disables the client Oct 13, 2026
@eli-r-ph eli-r-ph changed the title fix: missing or personal API key disables the client fix!: analytics setup problems never fail the app Oct 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@github-actions github-actions Bot added the stale label Oct 21, 2026

@marandaneto marandaneto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Automated advisory code review.

Comment thread noop_posthog.go Outdated
@marandaneto
marandaneto requested a review from a team October 21, 2026 12:43
@marandaneto marandaneto removed the stale label Oct 21, 2026
eli-r-ph and others added 3 commits October 22, 2026 08:36
An empty or personal (phx_) project API key gives a disabled client and a
nil error again, with one error log, so a missing key never stops an app.
Constructors still return a nil client and an error for invalid config.
Config.Disabled builds a disabled client on purpose, for tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
posthogmcpsdk.NewMiddleware and Instrument panicked on a nil
*posthogmcp.Analytics, and the otel bridge's NewExporter and
NewSpanProcessor returned an error for an empty API key. Both now report
one error and return a version that does nothing, like the core client
does for an empty or personal key, so analytics setup never stops the
application. The otel constructors also treat a personal (phx_) key as
unusable and never log the key. An invalid WithHost still returns an
error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The disabled client and the quota-limited GetAllFlags path returned one
shared result and map, so a caller's fallback changed what every other
caller received.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@eli-r-ph
eli-r-ph merged commit 17e7e8d into v1 Oct 22, 2026
32 checks passed
@eli-r-ph
eli-r-ph deleted the v1-disabled-client branch October 22, 2026 15:53
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.

2 participants