AGENTIC MEMORY

Skills

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

← Back to Skills

instrument-tracing

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.

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-tracing 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 · 13

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 distributed tracing

Canonical URL: https://posthog.com/docs/distributed-tracing/start-here

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).

On this page

Install a trace exporter

PostHog Distributed Tracing works with any OpenTelemetry client. Use the OTel SDKs you already have, point your trace exporter at PostHog's HTTP endpoint, and add your project token.

On Node.js and Python you can skip OpenTelemetry entirely: posthog-node and posthog create and export spans themselves, and spans made inside a request context carry the person and session they belong to. See the Node.js and Python guides.

Set these on your OpenTelemetry SDK:

OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="https://us.i.posthog.com/i/v1/traces"
OTEL_EXPORTER_OTLP_TRACES_HEADERS="Authorization=Bearer <ph_project_token>"
OTEL_SERVICE_NAME="my-app"

<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.

This is a different endpoint from PostHog's AI/LLM tracing (/i/v0/ai/otel), which only accepts generative-AI spans. For general application traces, use /i/v1/traces.

For language-specific setup, follow one of our installation guides:

Configure your tracing client

Send context-rich spans

PostHog ingests spans using OpenTelemetry's standard model: a trace is a tree of spans, each with a trace_id, span_id, and parent_span_id, plus timing, a service name, and attributes.

Wrap the operations you care about – incoming requests, outgoing calls, database queries – in spans, and enrich them with attributes for business context.

from opentelemetry import trace

tracer = trace.get_tracer("my-app")

with tracer.start_as_current_span("checkout") as span:
    span.set_attribute("user.id", "123")
    span.set_attribute("cart.value", 4200)
    # ... your code ...

Explore your traces

Once spans are flowing into PostHog, you can:

  • Search and filter spans by service, status, duration, and attributes
  • Follow a trace end to end as a waterfall to see where time goes
  • Spot slow and failing operations across your services
  • View correlated logs in the span inspector, scoped to a single span or the whole trace

Part of PostHog's observability suite

Distributed tracing uses the same OpenTelemetry-based ingestion as Logs, so a single OTel setup covers both. Your traces also live in the same PostHog project as Session Replay, Error Tracking, and Product Analytics – one platform instead of another observability vendor to run.

1/4

Install a trace exporter RequiredSend context-rich spans RequiredExplore your traces RequiredPart of PostHog's observability suite Recommended

Install a trace exporter

Required