Anthropic AI Observability installation

Claude PlatformPostHog

Become a trace explorer

Send OpenTelemetry traces from Claude to PostHog with no extra code. Add PostHog as a destination in the Claude Console and run evals on live traces and ship fixes that actually make a difference.

100K free events, every month
Explorer hedgehog holding a folded map

  1. Copy your project token

    Required

    Log in to see your project token here

    A personal API key (phx_...) won't work here.

  2. Choose how to send traces

    Required

    The Claude Platform can send traces from two places. Pick one for each PostHog project. If you use both, each request reaches PostHog twice.

    • SDK tracing: you set it up in your code with the Claude SDK. It covers the calls your app makes and the tools it runs itself. You can link traces to your users and add custom properties.
    • Console destination: you add PostHog in the Claude Console, with no code changes. It covers your Messages API requests, server tools such as web search, and Managed Agents sessions.

    Install the Claude SDK with the steps in Anthropic's OpenTelemetry guide. Then install the OpenTelemetry packages. PostHog has a span processor for Python, Node, and Go. Java and Ruby use the standard OTLP exporter.

    pip install "posthog[otel]"

    Register a tracer provider before your first Claude call. Set the content mode to see prompts and responses, because the SDK sends metadata only by default:

    from anthropic import Anthropic
    from opentelemetry import trace
    from opentelemetry.sdk.resources import SERVICE_NAME, Resource
    from opentelemetry.sdk.trace import TracerProvider
    from posthog.ai.otel import PostHogSpanProcessor
    resource = Resource(attributes={
    SERVICE_NAME: "my-app",
    "posthog.distinct_id": "user_123", # optional: identifies the user in PostHog
    "foo": "bar", # custom properties are passed through
    })
    provider = TracerProvider(resource=resource)
    provider.add_span_processor(
    PostHogSpanProcessor(
    api_key="<ph_project_token>",
    host="https://us.i.posthog.com",
    )
    )
    trace.set_tracer_provider(provider)
    client = Anthropic(open_telemetry={"traces": {"content_mode": "content"}})
    message = client.messages.create(
    model="claude-opus-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Tell me about hedgehogs"}],
    )
    # Flush the batched spans before a script exits.
    provider.shutdown()

    You can also set the content mode with the ANTHROPIC_OPEN_TELEMETRY_TRACES_CONTENT_MODE=content environment variable.

    To group several calls into one session, set a conversation ID on the client or the request, as described in Configure the SDK. PostHog uses it as the session ID.

  3. Call Claude and see the trace

    Required

    Call Claude the way you already do, then open AI Observability. Each request shows up as an anthropic.messages.create trace, with its cost, tokens, and messages.

    • SDK tracing: if you use the tool runner, each tool it runs gets its own span.
    • Console destination: the trace holds an anthropic.model_request span for each model request. A request can have more than one, for example when the model uses web search.

    Using Managed Agents? A Console destination also sends your sessions, with a span for each turn, model request, and tool use:

    A Managed Agents trace in PostHog: session turns with model requests and bash tool uses on a timeline, and the turn input and output

    The turn holds the agent's input and output, each model request holds its tokens and cost, and each tool use holds its arguments and result. A session can span several traces. To follow one session, filter by anthropic.session.id.

  4. Keep an eye on your agent

    Recommended

    Your traces are in. Now put them to work.

    Evaluations

    Quickly monitor how your agent is doing. Score every response for helpfulness, hallucinations, or tone, and see when quality drops.

    Dashboard

    Follow cost, usage, and latency over time, broken down by model or workspace.

    Clusters

    Group similar conversations to see what people ask your agent most.

    Sentiment

    See how users feel while they talk to your agent.

  5. Troubleshooting

    Optional
    • Delivery shows Failing with a 401: the token in the Claude Console is a personal API key. Use your project token.
    • Delivery shows Healthy, but PostHog is empty: check that the token comes from this project and that the region matches your PostHog cloud.
    • No traces from a Console destination: check that the destination's Workspaces setting covers the workspace of your API key. Traces can take up to a minute to arrive.
    • No traces from the Claude SDK: register the tracer provider before the first Claude call. ANTHROPIC_OPEN_TELEMETRY=false turns the spans off.
    • Traces stop at the end of a script: shut down the tracer provider before the script exits, as the samples do, so the last batch is sent.
    • No prompts or responses: in the Claude Console, the destination uses Metadata only. Organizations with a data-handling restriction, such as HIPAA, always export metadata only. With the Claude SDK, set the content mode to content on the client.
    • Each request appears twice: a Claude Console destination and the Claude SDK both send this project the same requests. Remove one of the two.

    For other questions, see AI Observability troubleshooting.

Still have questions?

Was this page useful?