Omnibus
Skill 93 of 200
Add PostHog distributed tracing to see how requests flow through services and where time goes.
6 minutes · 1,409 words · 4 sections
Install
npx skills add PostHog/skills --skill instrument-tracingnpx skills add PostHog/skills/plugin marketplace add PostHog/skillsThe first command installs just this skill, by the name in its SKILL.md; the second installs the whole repository.
Use this skill to add PostHog distributed tracing for new or changed code. Use it after implementing features or reviewing PRs to ensure request entry points, outbound calls, and background jobs produce spans, when the user asks to add tracing or spans, or to point existing OpenTelemetry tracing at PostHog. Supports any platform or language.
Supported platforms: Node.js, Next.js, Python (including Django, FastAPI, and Flask), Go, Java, .NET, PHP, Ruby, and any language via OpenTelemetry (OTLP).
PostHog tracing uses the standard OpenTelemetry SDK and an OTLP HTTP trace exporter. It does not need a PostHog SDK.
Follow these steps IN ORDER:
STEP 1: Analyze the codebase and detect the platform.
instrumentation.ts file, an opentelemetry-instrument launch command, an OpenTelemetry Collector config, a Java agent flag, or another vendor’s tracing agent.STEP 2: Choose the capture path.
STEP 3: Install dependencies. (Skip if the codebase already exports OpenTelemetry traces.)
@opentelemetry/auto-instrumentations-node.opentelemetry-distro and opentelemetry-exporter-otlp-proto-http, then run opentelemetry-bootstrap -a install. It installs the instrumentation packages for the libraries the app already uses. Do not install opentelemetry-instrumentation-all.go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp.opentelemetry-javaagent.jar. It needs no dependency changes.OpenTelemetry, OpenTelemetry.Exporter.OpenTelemetryProtocol, and OpenTelemetry.Extensions.Hosting, plus OpenTelemetry.Instrumentation.AspNetCore and OpenTelemetry.Instrumentation.Http.opentelemetry PHP extension (from PECL) and the open-telemetry/opentelemetry-auto-* package for the framework, such as open-telemetry/opentelemetry-auto-slim.opentelemetry-sdk, opentelemetry-exporter-otlp, and opentelemetry-instrumentation-all, enabled with c.use_all.STEP 4: Configure the OTLP trace exporter.
/i/v1/traces on the PostHog host, with the project token in an Authorization: Bearer header. Do not use /i/v0/ai/otel. That endpoint accepts only LLM spans.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT and the header in OTEL_EXPORTER_OTLP_TRACES_HEADERS (Authorization=Bearer <token>). Do not set the base OTEL_EXPORTER_OTLP_ENDPOINT for PostHog. It appends its own /v1/traces path.OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=http/protobuf where the SDK or agent defaults to gRPC. This applies to the Java agent, .NET, and Python with opentelemetry-distro.opentelemetry-distro: start the app with opentelemetry-instrument (for example, opentelemetry-instrument python app.py). It builds the tracer provider from the environment variables, so do not also build a provider in code. The distro also turns on OTLP metric and log export. Set OTEL_METRICS_EXPORTER=none and OTEL_LOGS_EXPORTER=none unless the app already sends those signals somewhere.service.name, or OTEL_SERVICE_NAME) so spans are easy to find in the Tracing UI.instrumentation.ts behind the NEXT_RUNTIME === 'nodejs' check.STEP 5: Add spans where they belong.
GET /users/:id, not GET /users/123. Put variable values in attributes.traceparent header on calls between services, so spans from each service join one trace.STEP 6: Link spans to people and sessions. (Optional.)
posthogDistinctId and sessionId span attributes.tracing_headers for your API hosts. The browser then sends X-POSTHOG-DISTINCT-ID and X-POSTHOG-SESSION-ID headers on each request.posthogDistinctId and sessionId attributes on the active request span. Skip a header that is missing or empty.PostHogContextSpanProcessor from posthog.integrations.otel to the tracer provider. It copies the distinct ID and session ID from the active PostHog context onto each new span. Django’s contexts middleware reads the headers and sets that context.posthog.withSpan, posthog.start_span) inside a PostHog request context get these attributes automatically. This needs posthog-node 5.52.0 or later, or posthog 7.58.0 or later, with the traces option set. These spans go through the PostHog SDK, not the OpenTelemetry provider. Use this only for apps that do not run OpenTelemetry.STEP 7: Set up environment variables.
.env, .env.local, or framework-specific env files). If valid values already exist, skip this step.projects-get tool to retrieve the project’s api_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.phc_). Do not use a personal API key (it starts with phx_).projects-get MCP response for a region field — US maps to https://us.i.posthog.com, EU maps to https://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.https://us.i.posthog.com/i/v1/traces (US) or https://eu.i.posthog.com/i/v1/traces (EU), matching the region determined above, with the project token as an Authorization: Bearer header.STEP 8: Flush spans in short-lived processes.
forceFlush() before the function returns. In Next.js 15.1 and later, call it inside after() from next/server.forceFlush() at the end of each invocation. Do not call shutdown() there, because the runtime reuses the container. Call shutdown() only when the process exits.STEP 9: Verify spans arrive.
Bearer token, the exporter protocol, and the flush step.references/nodejs.md - Node.js tracing installationreferences/nextjs.md - Next.js tracing installationreferences/python.md - Python tracing installationreferences/go.md - Go tracing installationreferences/java.md - Java tracing installationreferences/dotnet.md - .net tracing installationreferences/php.md - Php tracing installationreferences/ruby.md - Ruby tracing installationreferences/installation.md - Install tracingreferences/start-here.md - Getting started with distributed tracingreferences/basics.md - Why you need distributed tracingreferences/COMMANDMENTS.md - Framework-specific rules the integration must followEach platform reference contains specific OpenTelemetry setup, OTLP configuration, and integration patterns. Find the one matching the user’s stack.
Add PostHog distributed tracing to see how requests flow through services and where time goes. Use after implementing features or reviewing PRs to ensure request entry points, outbound calls, and background jobs produce spans, or when asked to add tracing or spans. Also handles pointing existing OpenTelemetry tracing at PostHog and initial OTLP exporter setup.
The verbatim description from this skill’s front matter — the string an agent matches on to decide whether to load it.
main, last pushed 8 November 2026.SKILL.md, not by matching a directory convention. 2 distinct layouts observed: skills/omnibus/*/SKILL.md, skills/posthog/all/skills/*/SKILL.md.h1 and no skipped levels:.claude-plugin/marketplace.json by PostHog, declaring 6 plugins. It is read for editorial metadata only — never as the skill index, which is always the repository tree./PostHog/skills.md, and each skill at its own .md URL.12 files · 75 KB
Everything this skill ships beside its prose. All of it is set here, as subchapters of skill 93.
Documentation the agent loads on demand, rather than up front.