AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a structured approach to instrumenting applications with PostHog metrics. It supports various platforms including Web, Node.js, Python, and Kubernetes, and offers a path for integrating existing OpenTelemetry setups. The skill emphasizes non-intrusive instrumentation, advising developers to add PostHog calls alongside existing metrics rather than replacing them. It includes guidance on selecting appropriate metric types, maintaining low cardinality for performance, and configuring environment variables securely.
What it does
- Detects existing metrics instrumentation and platform-specific requirements.
- Implements PostHog metric capture for counters, gauges, and histograms.
- Mirrors existing Prometheus, StatsD, or OpenTelemetry metrics into PostHog.
- Configures OTLP exporters for applications already using OpenTelemetry.
- Provides guidance on setting up necessary environment variables for authentication.
- Ensures metrics are correctly flushed in short-lived processes.
When to use it
- After implementing new features that require performance or usage tracking.
- When asked to add specific counters or gauges to an existing codebase.
- When you need to track values over time, such as queue depths or API durations.
- When migrating or mirroring existing metrics from other providers into PostHog.
- When you need to set up initial OTLP exporter configurations.
Advantages
- Non-destructive: adds metrics alongside existing instrumentation without restructuring code.
- Flexible: supports native SDKs and standard OpenTelemetry protocols.
- Performance-conscious: provides clear rules on maintaining low cardinality to prevent series explosion.
- Secure: mandates the use of environment variables for sensitive configuration keys.
- Robust: includes error handling guidelines to ensure metrics collection does not break application boot.
Usage examples
- “Add a counter to track the number of successful user signups in my Python application.”
- The agent will analyze the Python environment, identify the appropriate PostHog SDK or OTLP setup, and insert a counter increment call at the successful signup logic point.
- “Mirror my existing Prometheus metrics into PostHog.”
- The agent will identify the existing OTLP exporter or Prometheus client, configure the endpoint to point to PostHog, and ensure the project token is correctly set via environment variables.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/posthog/instrument-metrics/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip instrument-metrics.zip -d .agents/skills
Documentation by PostHog
Add PostHog metric capture
Use this skill to add PostHog metric capture (counters, gauges, and histograms) for new or changed code. Use it after implementing features or reviewing PRs to ensure key operations are measured, when the user asks to add metrics or counters, or to mirror existing metrics instrumentation into PostHog. Supports any platform or language.
Supported platforms: Web (JavaScript), Node.js, Python via the posthog.metrics SDK API, Kubernetes via the metrics agent, and any language via OpenTelemetry (OTLP).
Instructions
Follow these steps IN ORDER:
STEP 1: Analyze the codebase and detect the platform.
Detect the language, framework, and existing metrics setup.
Look for dependency files and project files (package.json, requirements.txt, pyproject.toml, go.mod, pom.xml, etc.).
Look for existing metrics instrumentation: Prometheus clients (prom-client, prometheus_client), StatsD/Datadog clients, OpenTelemetry meters, or an OpenTelemetry Collector config.
Check whether a PostHog SDK (posthog-js, posthog-node, posthog-python) is already installed.
STEP 2: Choose the capture path.
If a PostHog SDK is installed (or the platform supports one), use the
posthog.metricsAPI — no OpenTelemetry packages needed. Read the matching platform reference now.If the codebase already exports OpenTelemetry metrics, point the existing OTLP metrics exporter (or Collector) at PostHog instead — read the "Other Languages" reference. No application code changes needed beyond exporter config.
If neither applies, use the "Other Languages" reference as a fallback — it covers the generic OpenTelemetry approach.
STEP 3: Instrument alongside existing metrics.
Where the codebase already records a metric (a Prometheus counter, a StatsD call, an OTel instrument), add the PostHog call next to the existing one, reusing the same metric name and attributes. Do NOT remove or restructure the existing instrumentation.
Do not alter the fundamental architecture of existing files. Make additions minimal and targeted.
You must read a file immediately before attempting to write it.
STEP 4: Add new metrics where they belong.
Where the user asked for new metrics, or key operations have no coverage, add PostHog metric calls at the sites they belong: count successes and failures of critical flows, time external calls and jobs with histograms, gauge queue depths and pool sizes.
Pick the right type: counters for things that only go up, gauges for values that go up and down, histograms for distributions like durations. Set an explicit unit on histograms (
ms,bytes).Use stable, descriptive, dot-separated names (
jobs.processed,api.request.duration) and set a service name so systems stay easy to tell apart.
STEP 5: Keep cardinality low.
Attributes like
route,status,plan, orqueueare good; user IDs, session IDs, request IDs, and timestamps are not. Every unique attribute combination creates a new series.If something needs per-user or per-request detail, that's a job for PostHog logs or traces, not metrics.
STEP 6: Set up environment variables. (Skip if the PostHog SDK is already configured — posthog.metrics reuses the SDK's existing project token.)
Check if the project already has PostHog environment variables configured (e.g. in
.env,.env.local, or framework-specific env files). If valid values already exist, skip this step.If the PostHog project token is missing, use the PostHog MCP server's
projects-gettool to retrieve the project'sapi_token. If multiple projects are returned, ask the user which project to use. If the MCP server is not connected or not authenticated, ask the user for their PostHog project token instead.For the PostHog host URL: check the
projects-getMCP response for aregionfield —USmaps tohttps://us.i.posthog.com,EUmaps tohttps://eu.i.posthog.com. If the region is not available from the MCP response or from existing project configuration, ask the user: "Are you on PostHog US Cloud or EU Cloud?" Do not assume US Cloud.For the OTLP metrics endpoint, use
https://us.i.posthog.com/i/v1/metrics(US) orhttps://eu.i.posthog.com/i/v1/metrics(EU), matching the region determined above, with the project token as anAuthorization: Bearerheader.Write these values to the appropriate env file using the framework's naming convention.
Reference these environment variables in code instead of hardcoding them.
STEP 7: Verify metrics arrive.
For short-lived processes (scripts, cron jobs, serverless), flush before exit (
posthog.metrics.flush(), or the OTel provider'sforceFlush()/shutdown()).Open Metrics in the PostHog sidebar and pick the metric from the name picker; data points should appear within a minute of sending.
Reference files
references/javascript.md- JavaScript (web) metrics installationreferences/nodejs.md- Node.js metrics installationreferences/python.md- Python metrics installationreferences/kubernetes.md- Kubernetes metrics installationreferences/other.md- Other languages metrics installationreferences/start-here.md- Getting started with metricsreferences/basics.md- Why you need metricsreferences/architecture.md- How metrics worksreferences/COMMANDMENTS.md- Framework-specific rules the integration must follow
Each platform reference contains specific SDK setup, OTLP configuration, and integration patterns. Find the one matching the user's stack.
Key principles
Environment variables: Always use environment variables for PostHog keys and OpenTelemetry endpoints. Never hardcode them.
Minimal changes: Add PostHog metric capture alongside existing metrics. Don't replace or restructure existing instrumentation.
Prefer the SDK: When a PostHog SDK is present,
posthog.metricsneeds no new packages and no extra authentication. Reserve OTLP setup for codebases already invested in OpenTelemetry or languages without SDK support.Low cardinality: Every unique attribute combination creates a new series. Attach bounded dimensions like route, status, or plan — never user IDs, session IDs, or request IDs.
Files
- ATTRIBUTION.mdAdded by AutoGineer940 B
- LICENSELicence file added by AutoGineer1.0 KiB
- SKILL.md6.5 KiB
- references/COMMANDMENTS.md1.5 KiB
- references/architecture.md7.0 KiB
- references/basics.md5.4 KiB
- references/javascript.md4.4 KiB
- references/kubernetes.md9.0 KiB
- references/nodejs.md4.6 KiB
- references/other.md4.5 KiB
- references/python.md4.5 KiB
- references/start-here.md6.6 KiB
references/start-here.md
AI agents: this is one page from PostHog's docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt
Getting started with metrics
Canonical URL: https://posthog.com/docs/metrics/start-here
Cloud region: This page uses US Cloud hosts. For an EU Cloud project, use
https://eu.i.posthog.cominstead ofhttps://us.i.posthog.com(ingestion host), and usehttps://eu.posthog.cominstead ofhttps://app.posthog.com(app host for links).
On this page
Send your first metrics
Pick the right metric type
Add attributes, carefully
Verify metrics are arriving
Chart what matters
Query with SQL or ask AI
Metrics is in open alpha
Any team can turn on metrics: open Metrics in PostHog and select Enable metrics in the onboarding view. See turn on metrics for the full flow. Setup details, including the ingestion endpoint, may change before general availability. During the alpha, PostHog keeps metrics data for 30 days.
Send your first metrics
There are three ways to get metrics into PostHog, and all take just a few minutes.
If posthog-js is already running on your site, record metrics directly with the posthog.metrics API. No new packages, no extra authentication:
posthog.metrics.count("checkout.completed");
posthog.metrics.gauge("cart.items", 3);
posthog.metrics.histogram("api.request.duration", 187, { unit: "ms" });If you use OpenTelemetry anywhere else (backend services, infrastructure, an existing Collector), point your OTLP metrics exporter at PostHog. No PostHog packages are required:
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT="https://us.i.posthog.com/i/v1/metrics"
OTEL_EXPORTER_OTLP_METRICS_HEADERS="Authorization=Bearer <ph_project_token>"
OTEL_SERVICE_NAME="my-app"If you run Kubernetes and your pods already expose Prometheus metrics, install the PostHog metrics agent Helm chart to scrape and forward them automatically:
helm install posthog-metrics-agent oci://ghcr.io/posthog/charts/posthog-metrics-agent \
--set posthog.apiKey=<ph_project_token><ph_client_api_host> and <ph_project_token> are filled in with your project's values when you're logged in. Use your project token (the same one you use for capturing events), not a personal API key.
For per-platform setup, including the posthog.metrics API in Node.js and Python, see the installation guides.
Pick the right metric type
Metrics come in three shapes, and picking the right one determines which aggregations make sense later:
Counters only go up: requests handled, jobs processed, errors raised. Chart them with
rateorincrease.Gauges go up and down: queue depth, active connections, memory in use. Chart them with
avg.Histograms record distributions: request durations, payload sizes. Chart them with percentiles like
p95.
Give each metric a stable, descriptive name (http.server.duration, jobs.processed.total) and set a service name so metrics from different systems stay easy to tell apart.
Add attributes, carefully
Attributes let you slice a metric by dimension: route, status code, plan, region. Every unique combination of attribute values creates a new series, so attach dimensions with a small, bounded set of values.
Good attributes: route, status, plan, queue. Bad attributes: user IDs, session IDs, request IDs, timestamps. Each of those would create a series per user or per request, which makes charts unreadable and ingestion expensive.
If you need to know what happened for one specific user or request, that's a job for logs or traces, not metrics.
Verify metrics are arriving
Open Metrics in the PostHog sidebar. The Overview tab shows your services, metric names, and active series over the last day, so you can confirm data is landing. In the Viewer tab, pick your metric from the name picker and you should see data points within a minute of sending. The viewer recommends an aggregation based on the metric's type, so a counter defaults to increase and a gauge to avg.
If nothing shows up, check that the endpoint ends in /i/v1/metrics, that the token starts with phc_, and see the troubleshooting section.
Chart what matters
Once data flows, build the views you'll actually watch:
Group by an attribute to get one line per value, for example request rate per route or queue depth per worker.
Filter with
key=valuechips to focus on one service, environment, or status.Watch for the anomaly badge — when the metric moves against its baseline, it shows the change and the label values that drove it.
Turn on auto-refresh to update the chart every few seconds while you watch a deploy or an incident.
When a chart is worth keeping, save it as an insight or add it to a dashboard — or use New service dashboard to build one insight per metric in a single step.
Query with SQL or ask AI
Every metric lands in the posthog.metrics table, so the SQL tab in the metrics viewer gives you full query access for anything the chart controls don't cover.
If you use the PostHog MCP server, your AI tools can query metrics directly: ask your agent to chart a metric, compare error rates between services, or characterize an anomaly, all without leaving your editor.
For the full tour of the viewer — anomaly detection, pivoting into logs and traces, and dashboards — see Use your metrics.
1/6
Send your first metrics RequiredPick the right metric type RequiredAdd attributes, carefully RequiredVerify metrics are arriving RequiredChart what matters RecommendedQuery with SQL or ask AI Optional
Send your first metrics
Required
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs an MCP server, Needs Python, Needs Node.js
Security
What our scanner noticed· Low risk
- Instructions that use the network
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- PostHog
- Publisher
- PostHog (Official)
- Source
- PostHog/skills · skills/omnibus/instrument-metrics · commit a5d30e7
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by PostHog or PostHog.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download instrument-metrics.zip