> ## Documentation Index
> Fetch the complete documentation index at: https://docs.scorecard.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Agent SDK Tracing

> Trace your Claude Agent SDK applications with Scorecard.

export const DarkLightImage = ({lightSrc, caption, alt, darkSrc = null, width = "1000"}) => {
  const getAbsoluteUrl = src => {
    if (src.startsWith('http://') || src.startsWith('https://')) {
      return src;
    }
    const currentUrl = typeof window !== 'undefined' ? window.location.origin : '';
    if (currentUrl.includes('.mintlify.app')) {
      const subdomain = currentUrl.split('.')[0].replace('https://', '');
      return `https://mintlify.s3.us-west-1.amazonaws.com/${subdomain}${src.startsWith('/') ? '' : '/'}${src}`;
    } else if (currentUrl === 'https://docs.scorecard.io') {
      return `https://mintlify.s3.us-west-1.amazonaws.com/scorecard-d65b5e8a${src.startsWith('/') ? '' : '/'}${src}`;
    } else {
      return `${currentUrl}${src.startsWith('/') ? '' : '/'}${src}`;
    }
  };
  const content = <>
      <img className="block dark:hidden" width={width} src={getAbsoluteUrl(lightSrc)} alt={alt} />
      <img className="hidden dark:block" width={width} src={getAbsoluteUrl(darkSrc || lightSrc.replace('light', 'dark'))} alt={alt} />
    </>;
  if (caption) {
    return <Frame caption={caption}>{content}</Frame>;
  } else {
    return content;
  }
};

The Claude Agent SDK is Anthropic's framework for building AI agents that can reason, use tools, and complete multi-step tasks. It includes built-in support for OpenTelemetry tracing, making it easy to capture detailed telemetry from your agent workflows.

This quickstart shows how to send traces from your Claude Agent SDK (Python v0.1.18+, TypeScript v0.1.71+) applications to Scorecard for observability, debugging, and evaluation.

<Info>
  **Using the standard Anthropic SDK?** Check out the general [Tracing Quickstart](/intro/tracing-quickstart) for the proxy method that works with any Anthropic client.
</Info>

## Steps

<Steps>
  <Step title="Set up environment variables">
    Configure the OpenTelemetry exporter to send traces to Scorecard. You'll need your Scorecard API key from [Settings](https://app.scorecard.io/settings).

    ```bash theme={null}
    export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer <your_scorecard_api_key>"
    export ENABLE_BETA_TRACING_DETAILED=1
    export BETA_TRACING_ENDPOINT="https://tracing.scorecard.io/otel"
    export OTEL_LOG_USER_PROMPTS=1
    export OTEL_LOG_TOOL_DETAILS=1
    export OTEL_LOG_TOOL_CONTENT=1
    export OTEL_RESOURCE_ATTRIBUTES="scorecard.project_id=<your-project-id>"
    ```

    <Note>
      Replace `<your_scorecard_api_key>` with your actual Scorecard API key (starts with `ak_`), and `<your-project-id>` with the project you want traces to land in.
    </Note>

    <Warning>
      If the project ID is wrong or invalid, traces will be sent to the **oldest project** in your organization.
    </Warning>
  </Step>

  <Step title="Run your agent">
    With the environment variables configured, run your Claude Agent SDK application. All agent activity is automatically traced.

    ```python title="example.py" [expandable] theme={null}
    import anyio
    from claude_agent_sdk import (
        AssistantMessage,
        TextBlock,
        query,
    )

    async def main():
        async for message in query(prompt="What is 2 + 2?"):
            if isinstance(message, AssistantMessage):
                for block in message.content:
                    if isinstance(block, TextBlock):
                        print(f"Claude: {block.text}")

    anyio.run(main)
    ```
  </Step>

  <Step title="View traces in Scorecard">
    Navigate to the [**Records**](/features/records) page in [Scorecard](https://app.scorecard.io) to see your agent traces. Click any record to open its trace detail panel, which breaks the trace into four tabs: **Conversation**, **Timeline**, **Chat**, and **Debug**.

    <DarkLightImage lightSrc="/images/records-table-claude-sdk-light.png" darkSrc="/images/records-table-claude-sdk-dark.png" alt="Records page with a record selected, showing the trace detail panel" caption="Selecting a record opens its trace detail panel." />

    The **Conversation** tab shows a chat-like replay of user messages, assistant responses, and tool calls.

    <DarkLightImage lightSrc="/images/claude-sdk-conversation-view-light.png" darkSrc="/images/claude-sdk-conversation-view-dark.png" alt="Conversation tab showing user messages, assistant responses, and tool call results" caption="Conversation tab of an agent trace." />

    The **Timeline** tab shows a Gantt chart-style breakdown of every span, so you can see how LLM calls and tool executions overlap and how long each takes.

    <DarkLightImage lightSrc="/images/claude-sdk-trace-timeline-light.png" darkSrc="/images/claude-sdk-trace-timeline-dark.png" alt="Timeline tab showing span hierarchy with duration bars for LLM calls and tool executions" caption="Timeline tab of an agent trace." />

    The **Chat** tab lets you ask questions about the trace in natural language—what happened, why a step failed, or how it performed—and compare records side by side.

    <DarkLightImage lightSrc="/images/claude-sdk-chat-view-light.png" darkSrc="/images/claude-sdk-chat-view-dark.png" alt="Chat tab answering a natural-language question about the trace" caption="Chat tab: ask questions about a trace." />

    The **Debug** tab pairs the full span tree with a trace overview—duration, cost, tokens, and model—plus the raw span data for deeper inspection.

    <DarkLightImage lightSrc="/images/claude-sdk-debug-view-light.png" darkSrc="/images/claude-sdk-debug-view-dark.png" alt="Debug tab showing the span tree alongside the trace overview dashboard" caption="Debug tab: span tree and trace overview." />
  </Step>
</Steps>

## Anatomy of a trace

Explore how a Claude Agent SDK trace is structured—spans, tool calls, model usage, and metadata—in this interactive demo:

<iframe className="w-full rounded-xl border-0" style={{ aspectRatio: "3 / 2" }} src="https://scorecard-git-feat-trace-anatomy-demo-embed-scorecard-ai.vercel.app/demo/trace-anatomy" title="Anatomy of a Claude Agent SDK trace" />

## Next Steps

<CardGroup cols={2}>
  <Card title="Tracing Features" icon="chart-line" href="/features/tracing">
    Learn about advanced tracing patterns and trace grouping
  </Card>

  <Card title="Metrics" icon="gauge" href="/features/metrics">
    Create custom metrics to evaluate agent performance
  </Card>
</CardGroup>
