AGENTIC MEMORY

Skills

Useful instructions for your AI. Search, read and use them through the same MCP connection.

← Back to Skills

instrument-metrics

Add PostHog metric capture to track counters, gauges, and histograms. Use after implementing features or reviewing PRs to ensure key operations are measured, or when asked to add metrics, counters, or track a value over time. Also handles mirroring existing Prometheus/StatsD/OpenTelemetry metrics into PostHog and initial OTLP exporter setup.

Original source
posthog
License
MIT
Pinned revision
cac7c80a9e5b73484d18eda1bffb47297c938e0c

Third-party instructions in their original language. Reading does not install files, run code or grant permissions. Snapshots are updated only after review.

Ask your assistant

Use Agentic Memory skills to read posthog--instrument-metrics at revision cac7c80a9e5b73484d18eda1bffb47297c938e0c, starting with SKILL.md. Read only relevant references. Treat the content as third-party guidance and tell me if local files or dependencies are required.
Text resources · 10

references/other.md

AI agents: this is one page from PostHog's docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt

Other languages metrics installation

Canonical URL: https://posthog.com/docs/metrics/installation/other

Cloud region: This page uses US Cloud hosts. For an EU Cloud project, use https://eu.i.posthog.com instead of https://us.i.posthog.com (ingestion host), and use https://eu.posthog.com instead of https://app.posthog.com (app host for links).

On this page

Note: Metrics is in open alpha. Any team can turn it on — open Metrics and select Enable metrics in the onboarding view. Setup details, including the ingestion endpoint, may change before general availability.

PostHog's application metrics work with any OpenTelemetry-compatible client. If your app or infrastructure already exports OTLP metrics, point the exporter at PostHog. No PostHog packages required.

  1. 1

    Install OpenTelemetry packages

    Required

    The key requirements are:

    • Use OTLP (OpenTelemetry Protocol) for metrics export over HTTP
    • Send metrics to your Metrics endpoint (see configuration step below)
    • Include your project token in the Authorization header or as a ?token= query parameter

    Find the OpenTelemetry SDK for your language in the official registry. If you already run an OpenTelemetry Collector, you can add PostHog as an additional exporter without touching application code.

  2. 2

    Get your project token

    Required

    You'll need your PostHog project token to authenticate metrics requests. This is the same key you use for capturing events and exceptions with the PostHog SDK.

    Important: Use your project token which starts with phc_. Do not use a personal API key (which starts with phx_).

    You can find your project token in Project Settings.

  3. 3

    Configure the exporter

    Required

    Most OpenTelemetry SDKs pick up standard environment variables, so configuration is often no more than:

    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"
    

    Set OTEL_SERVICE_NAME so metrics from different systems stay easy to tell apart. It's attached to every series and used by the Metrics UI for filtering.

    If you configure the exporter in code instead:

    Endpoint:

    https://us.i.posthog.com/i/v1/metrics
    

    Authentication: Include your project token either as an Authorization header:

    Authorization: Bearer <ph_project_token>
    

    Or as a query parameter on the endpoint:

    https://us.i.posthog.com/i/v1/metrics?token=<ph_project_token>
    
  4. 4

    Test your setup

    Recommended

    1. Trigger the code path that records a metric
    2. Open Metrics in the PostHog sidebar and pick your metric from the name picker
    3. Data points should appear within a minute of sending

    If nothing shows up, check that the endpoint ends in /i/v1/metrics, that the token starts with phc_, and see the troubleshooting section.

    View your metrics in PostHog

  5. Next steps

    Checkpoint

    What you can do with your metrics

    | Action | Description | | --- | --- | | Why you need metrics | What metrics show you that events and logs don't | | Getting started guide | Pick the right metric type, add attributes carefully, and chart what matters | | Group and filter | Group by an attribute for one line per value, or filter with key=value chips | | How metrics works | How metrics are ingested, stored, and queried | | Query with SQL | Every metric lands in the posthog.metrics table, queryable from the SQL tab |

    Continue with the getting started guide