Skip to content

fix: resolve PostHog clients through configured DI - #1780

Open
kang-heewon wants to merge 1 commit into
trunkfrom
fix/1705-posthog-di
Open

fix: resolve PostHog clients through configured DI#1780
kang-heewon wants to merge 1 commit into
trunkfrom
fix/1705-posthog-di

Conversation

@kang-heewon

Copy link
Copy Markdown
Member

Outcome

@croco/integrations-posthog now exports a typed POSTHOG_CONFIG_TOKEN and registerPostHogConfig() startup path. Registration validates the API key and HTTP(S) host, resolves and freezes environment-provided host values, and remains usable before a logger is registered.

PostHogClient injects the configuration token, so Container.get(PostHogClient) works after documented setup. Missing registration and invalid values produce stable Croco diagnostics. Existing mutable PostHogConfig input typing and direct construction remain supported.

Fixes #1705

Verification

  • pnpm --filter @croco/integrations-posthog test — 13 passed
  • package typecheck, lint, and build — passed
  • packed ESM/CJS decorator metadata smoke — passed with an explicit 120-second test limit (46.55 seconds)
  • pre-push workspace test — 234/234 tasks passed
  • pre-push workspace typecheck — 233/233 tasks passed
  • pnpm public-api:check — 115 package snapshots matched
  • pnpm problem-registry:check — 581/581 codes matched
  • pnpm package-manifests:check — 115 manifests normalized
  • pnpm strict-contract-typecheck — 503 baseline diagnostics matched
  • pnpm check — 24/25 repository gates passed; 1 not applicable
  • pnpm changeset-required:check -- --base origin/trunk --head HEAD — passed

Review gates

  • Correctness and regression — PASS. Coverage proves registered singleton resolution, missing-provider diagnostics, invalid API key and host diagnostics, environment-host normalization and freezing, logger-free bootstrap, direct construction, and shutdown behavior.
  • API, security, compatibility, and release — PASS. Existing mutable configuration input and direct construction remain compatible; the new registration result and token are readonly. Public API, Problem registry, manifests, generated PostHog API pages, and a patch changeset are synchronized. No dependency, lockfile, secret, or event surface changed.
  • Maintainability and minimality — PASS. Configuration validation and registration live in one focused module while the client only consumes the explicit token. No unrelated generated documentation changes are included.
  • Independent adversarial review — PASS after fixes. Review identified logger-free bootstrap and mutable input compatibility gaps; both received regressions and final re-review reported no remaining findings.

Validation gap

The full API-doc drift check built 4,527 pages and also reported existing drift in unrelated packages. The affected PostHog pages were regenerated with TypeDoc and exact signatures were rechecked after the final compatibility change.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@kang-heewon, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 18 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 50c4a1c6-ced9-40e6-99d4-27cf6f501735

📥 Commits

Reviewing files that changed from the base of the PR and between 6795b4d and 319124f.

📒 Files selected for processing (9)
  • .changeset/posthog-explicit-di-config.md
  • packages/docs/src/content/docs/api/integrations-posthog/src/functions/registerPostHogConfig.md
  • packages/docs/src/content/docs/api/integrations-posthog/src/variables/POSTHOG_CONFIG_TOKEN.md
  • packages/integrations-posthog/README.md
  • packages/integrations-posthog/src/index.ts
  • packages/integrations-posthog/src/libs/PostHogClient.ts
  • packages/integrations-posthog/src/libs/PostHogConfig.ts
  • packages/integrations-posthog/src/tests/PostHogClient.spec.ts
  • public-api-surface.snapshot.json

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

📊 Benchmark Results

✅ All benchmarks passed

Benchmark p75 Threshold Baseline vs Baseline Status Notes
CrocoApp constructor 20.7μs 30.0ms 8.2μs +153.0% -
CrocoApp lambdaHandler (10 controllers) 804.2μs 50.0ms 258.4μs +211.2% -
Lambda cold-start simulation 832.8μs 80.0ms 418.1μs +99.2% -
Lambda cold-start with headers 841.2μs 80.0ms 369.7μs +127.6% -
Lambda cold-start with binary body 801.3μs 80.0ms 339.1μs +136.3% -
Lambda cold-start with query params 745.2μs 80.0ms 301.3μs +147.3% -
Lambda cold-start with authorizer context 728.1μs 80.0ms 299.8μs +142.9% -
Lambda cold-start realistic scenario 696.2μs 80.0ms 299.2μs +132.7% -
EventBusConfig.start (10 handlers) 1.1μs 10.0ms 1.4μs -23.9% -
EventPublisher.publishNow single event 1.2μs 2.0ms 1.7μs -26.8% -
DefaultHandlerResolver.resolve × 10 0.0μs 5.0ms 0.1μs -37.5% -
Container.get singleton (cold) 32.5μs 5.0ms 70.3μs -53.7% -
Container.register × 50 components 1.7ms 10.0ms 3.2ms -48.5% -
Container.validate (50 components) 1.9ms 20.0ms 3.4ms -44.9% -
Container.get singleton (warm) 0.9μs 500.0μs 1.6μs -45.4% -
TelemetryRuntime.init (lambda preset) 1.1μs 200.0ms 1.1ms -99.9% -
lambdaPreset config creation 0.7μs 2.0ms 1.4μs -50.0% -

Updated: 2026-08-08T08:05:05.726Z · Commit: b28a3a6

@kang-heewon

Copy link
Copy Markdown
Member Author

Required validate is currently blocked by repository-wide issue #1782 (nanoid GHSA-2v37-7h3g-55p8). The audit failure reproduces on the exact trunk base and this PR does not change dependency manifests or pnpm-lock.yaml; the other selected verification checks passed. Per #1782, the security-policy/dependency correction belongs on trunk rather than in this PostHog feature fix.

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.

[integrations-posthog] Make PostHogClient resolvable through Croco DI with explicit configuration

1 participant