Skip to content

Add PostHog analytics integration - #2

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog/instrumentation-b0c025
Draft

Add PostHog analytics integration#2
posthog[bot] wants to merge 1 commit into
mainfrom
posthog/instrumentation-b0c025

Conversation

@posthog

@posthog posthog Bot commented Jul 20, 2026

Copy link
Copy Markdown

Summary

This PR adds PostHog analytics to mcplint using the posthog-node SDK (installed via npm). The setup wizard instrumented the CLI to capture events at every meaningful exit point.

  • src/posthog.ts — new PostHog singleton client (Node SDK, flushAt: 1, flushInterval: 0, exception autocapture) for CLI-safe flushing
  • src/cli.ts — imports the client and captures events for successful lint runs, snapshot dumps, rule explanations, threshold failures, and unhandled errors
  • package.json / package-lock.json — adds posthog-node@^5.45.2
  • .gitignore — ignores .env so the API key is never committed

Captured events: lint_run_completed, snapshot_dumped, rule_explained, lint_threshold_failed, lint_run_errored.

Insights and dashboards created

Type Name Link
Dashboard Analytics basics (wizard) https://us.posthog.com/project/520619/dashboard/1875473
Insight Lint runs over time https://us.posthog.com/project/520619/insights/MpBKFY9t
Insight Lint runs by source https://us.posthog.com/project/520619/insights/ODLqrmVn
Insight Avg composite score https://us.posthog.com/project/520619/insights/iyjP2y90
Insight Threshold failures https://us.posthog.com/project/520619/insights/6m9QvhnX
Insight Rules explained https://us.posthog.com/project/520619/insights/3uttxtHV

How to verify

  1. Build and run the CLI against a fixture, with the env vars from the section below set in your shell:
    npm run build
    export POSTHOG_API_KEY=phc_nWALq8MXGHFzBUQ9JxTVQoY4VEYjZd3SXC5ZduKQMPtX
    export POSTHOG_HOST=https://us.i.posthog.com
    npm run lint:good
  2. In PostHog, open Activity — you should see a lint_run_completed event arrive within a minute.
  3. Confirm the dashboard populates: Analytics basics (wizard).

Environment variables (action needed before PostHog works)

mcplint is a Node CLI distributed via npm (run with npx mcplint). There is no server deployment and no committed runtime config file read in production — the code reads process.env.POSTHOG_API_KEY / POSTHOG_HOST directly, and .env is both gitignored and excluded from the npm files bundle, so it would never reach end users anyway. "Production" for a CLI is each user's own shell, so these variables must be set in the environment where the CLI runs.

Name Value
POSTHOG_API_KEY phc_nWALq8MXGHFzBUQ9JxTVQoY4VEYjZd3SXC5ZduKQMPtX
POSTHOG_HOST https://us.i.posthog.com

Set them wherever you run mcplint — e.g. in your shell profile (~/.bashrc / ~/.zshrc) or your CI runner's secret store — and ensure they are exported into the process environment before invoking npx mcplint.

export POSTHOG_API_KEY=phc_nWALq8MXGHFzBUQ9JxTVQoY4VEYjZd3SXC5ZduKQMPtX
export POSTHOG_HOST=https://us.i.posthog.com

When unset, PostHog initializes with an empty key and silently no-ops — the linter still runs normally, it just does not emit analytics.


Created with PostHog Code

Add posthog-node as a production dependency and a new src/posthog.ts
singleton client (flushAt 1, flushInterval 0, exception autocapture)
for CLI-safe event flushing. Instrument src/cli.ts to capture lint run
completions, snapshot dumps, rule explanations, threshold failures, and
unhandled errors. Ignore .env to keep the API key out of the repo.

Generated-By: PostHog Code
Task-Id: 61523356-59ce-46bc-bf5c-23388a84ecb6
@posthog

posthog Bot commented Jul 20, 2026

Copy link
Copy Markdown
Author

CI status

This repository has no .github/workflows/ configured, so there are no CI checks running on this branch (gh pr checks reports "no checks reported"). Nothing to keep green — verified the build, type-check, and test suite all pass locally before opening this PR:

  • npm run build
  • npm run typecheck
  • npm test ✅ (30 tests passed)

Note: package.json has no lint script, so that step was skipped (the repo genuinely doesn't define one).

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.

0 participants