Skip to main content
guidesSource-backed

OpenTelemetry Observability for Claude Agent SDK Agents

A practical walkthrough of exporting OpenTelemetry traces, metrics, and events from the Claude Agent SDK: enabling telemetry, configuring OTLP exporters, reading agent spans, linking traces to your app, and controlling sensitive data.

by JPette1783·added 2026-06-05·
Review first review before installing

Open the source and read safety notes before installing.

Citation facts

Source-backed facts for citing this resource, derived directly from the registry — also available as plain text for AI assistants.

Source URLs
https://code.claude.com/docs/en/agent-sdk/observability, https://github.com/JSONbored/awesome-claude/blob/main/content/guides/opentelemetry-observability-for-claude-agent-sdk-agents.mdx
Safety notes
Telemetry is off until you set CLAUDE_CODE_ENABLE_TELEMETRY=1 and choose an exporter; turning it on starts exporting usage data, so confirm the destination is approved., Do not use the console exporter through the SDK; stdout is the SDK's message channel. Point OTLP at a collector or local Jaeger instead., Traces are beta and require CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1; span names and attributes may change between releases.
Privacy notes
By default telemetry is structural (durations, model/tool names, token counts), not content; opt-in vars (OTEL_LOG_USER_PROMPTS, OTEL_LOG_TOOL_DETAILS, OTEL_LOG_TOOL_CONTENT, OTEL_LOG_RAW_API_BODIES) add prompt and tool content., Exporter headers can carry tokens; supply them via the environment, not committed config., End-user attribution via OTEL_RESOURCE_ATTRIBUTES creates a per-user audit trail; handle that data per your policy and percent-encode values.
Author
JPette1783
Submitted by
JPette1783
Claim status
unclaimed
Last verified
2026-06-05

Decision playbook

Review trust signals before you adopt

Signals are present but mixed. Use the checklist below to confirm the source and operational safety for your environment.

Compare context
Selected

0

Current score

63

Baseline

Delta

No baseline selected

No major trust-signal divergence detected in the current selection.

Source and provenance checks

Needs review

Confirm ownership and provenance before trusting install instructions.

  • Source link availableRequired

    Open the canonical repository and verify ownership.

    Done
  • Source provenance statusRequired

    Marked as source-backed.

    Done
  • Metadata reviewed

    No reviewed flag detected in metadata.

    Pending

Safety and privacy checks

Complete

Validate risk disclosures before installation or API wiring.

  • Safety notes presentRequired

    Review the listed safety guidance before running commands.

    Done
  • Privacy notes presentRequired

    Review data handling notes before connecting accounts or secrets.

    Done
  • Trust level risk gateRequired

    Trust level does not block evaluation.

    Done

Package and install checks

Needs review

Check package metadata and artifact integrity signals.

  • Install payload available

    Install or copy payload is available for review.

    Done
  • Package verification flag

    No package verification flag provided.

    Pending
  • Checksum metadata

    No checksum provided for downloaded artifact.

    Pending

Compare-driven decision checks

Needs review

Use compare context to validate trade-offs before adoption.

  • Compare tray has multiple entries

    Add at least one more entry to compare trust differences.

    Pending
  • Baseline comparison available

    No baseline peer selected yet.

    Pending
  • Diverging trust signals identified

    No major trust-signal divergence found.

    Pending

Setup at a glance

Copy & paste

Copy-ready — paste the snippet to get started.

Adoption plan

Balanced adoption plan

Current risk score 24/100. Use staged verification before broader rollout.

Risk 24

Pre-adoption checks

Validate source and review signals before any execution.

  • Confirm source provenanceRequired

    Source URL/provenance metadata is present.

    Done
  • Confirm metadata review state

    No review metadata found; increase manual validation.

    Pending
  • Verify install payload

    Install/config payload exists and can be inspected.

    Done

Security checks

Confirm safety, privacy, and package integrity signals.

  • Review safety notesRequired

    Safety notes are present.

    Done
  • Review privacy notesRequired

    Privacy notes are present.

    Done
  • Verify package integrity metadata

    No package verification/checksum metadata.

    Pending

Rollout

Adopt in controlled steps based on the selected plan.

  • Run in isolated sandbox firstRequired

    Use a constrained sandbox and observe behavior across multiple tasks.

    Pending
  • Roll out graduallyRequired

    Roll out to a small cohort before wider usage.

    Pending
  • Set monitoring and fallback

    Define rollback path and monitor errors after adoption.

    Pending

Evidence readiness

Evidence readiness matrix · balanced

Missing required evidence: Metadata review. Risk score 31.

Risk 31

Source provenance

Present

Source repository/provenance is listed.

Required in this preset

Metadata review

Missing

Review metadata is missing.

Required in this preset

Safety notes

Present

Safety notes are present.

Required in this preset

Privacy notes

Present

Privacy notes are present.

Optional in this preset

Package integrity

Missing

Package integrity metadata is missing.

Optional in this preset

Install payload

Present

Install payload is available.

Required in this preset

Required gaps: Metadata review

Decision timeline

Decision timeline · balanced

Blocking gaps: Check metadata review status. Risk 28.

Risk 28

triage

Confirm source provenanceRequired

Source/provenance metadata is available.

Done

triage

Check metadata review statusRequired

Review metadata is missing.

Pending

verify

Review safety notesRequired

Safety notes are available.

Done

verify

Review privacy notes

Privacy notes are available.

Done

verify

Validate package integrity metadata

Package integrity metadata is missing.

Pending

rollout

Verify install payload and commandsRequired

Install payload is available.

Done

Blockers: Check metadata review status

Prerequisite readiness

Prerequisite readiness

3 prerequisites to line up before setup.

0/3 ready
Install & runtime1Configuration1General1

Safety & privacy surface

Safety & privacy surface

3 safety and 3 privacy notes across 3 risk areas. Review closely: credentials & tokens.

3 areas
  • SafetyTelemetryTelemetry is off until you set CLAUDE_CODE_ENABLE_TELEMETRY=1 and choose an exporter; turning it on starts exporting usage data, so confirm the destination is approved.
  • SafetyGeneralDo not use the console exporter through the SDK; stdout is the SDK's message channel. Point OTLP at a collector or local Jaeger instead.
  • SafetyTelemetryTraces are beta and require CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1; span names and attributes may change between releases.
  • PrivacyCredentials & tokensBy default telemetry is structural (durations, model/tool names, token counts), not content; opt-in vars (OTEL_LOG_USER_PROMPTS, OTEL_LOG_TOOL_DETAILS, OTEL_LOG_TOOL_CONTENT, OTEL_LOG_RAW_API_BODIES) add prompt and tool content.
  • PrivacyCredentials & tokensExporter headers can carry tokens; supply them via the environment, not committed config.
  • PrivacyGeneralEnd-user attribution via OTEL_RESOURCE_ATTRIBUTES creates a per-user audit trail; handle that data per your policy and percent-encode values.

Safety notes

  • Telemetry is off until you set CLAUDE_CODE_ENABLE_TELEMETRY=1 and choose an exporter; turning it on starts exporting usage data, so confirm the destination is approved.
  • Do not use the console exporter through the SDK; stdout is the SDK's message channel. Point OTLP at a collector or local Jaeger instead.
  • Traces are beta and require CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1; span names and attributes may change between releases.

Privacy notes

  • By default telemetry is structural (durations, model/tool names, token counts), not content; opt-in vars (OTEL_LOG_USER_PROMPTS, OTEL_LOG_TOOL_DETAILS, OTEL_LOG_TOOL_CONTENT, OTEL_LOG_RAW_API_BODIES) add prompt and tool content.
  • Exporter headers can carry tokens; supply them via the environment, not committed config.
  • End-user attribution via OTEL_RESOURCE_ATTRIBUTES creates a per-user audit trail; handle that data per your policy and percent-encode values.

Prerequisites

  • The Claude Agent SDK installed for Python or TypeScript.
  • An OTLP-compatible backend or collector (Honeycomb, Datadog, Grafana, Jaeger, etc.).
  • Ability to set environment variables for the process or via options.env.

Schema details

Install type
copy
Troubleshooting
No
Full copyable content
## Overview

The Claude Agent SDK can export traces, metrics, and log events as OpenTelemetry
data to any OTLP backend. The SDK runs the Claude Code CLI as a child process; the
CLI has the OpenTelemetry instrumentation and exports directly, while the SDK
passes configuration through as environment variables.

## Enable export

Telemetry is off until you set `CLAUDE_CODE_ENABLE_TELEMETRY=1` and choose at
least one exporter. The three signals are independent:

| Signal | Enable with |
| --- | --- |
| Metrics | `OTEL_METRICS_EXPORTER` |
| Log events | `OTEL_LOGS_EXPORTER` |
| Traces | `OTEL_TRACES_EXPORTER` plus `CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1` |

```typescript
const otelEnv = {
  CLAUDE_CODE_ENABLE_TELEMETRY: "1",
  CLAUDE_CODE_ENHANCED_TELEMETRY_BETA: "1",
  OTEL_TRACES_EXPORTER: "otlp",
  OTEL_METRICS_EXPORTER: "otlp",
  OTEL_LOGS_EXPORTER: "otlp",
  OTEL_EXPORTER_OTLP_PROTOCOL: "http/protobuf",
  OTEL_EXPORTER_OTLP_ENDPOINT: "https://collector.example.com:4318",
};
// TS replaces the inherited env, so spread process.env:
const options = { env: { ...process.env, ...otelEnv } };
```

In Python, `env` merges over the inherited environment. Do not use the `console`
exporter through the SDK; stdout is its message channel.

## Read agent traces

With traces enabled, each step becomes a span: `claude_code.interaction` (a turn),
`claude_code.llm_request` (each model call), `claude_code.tool` (each tool, with
permission-wait and execution children), and `claude_code.hook`. Spans carry a
`session.id` attribute so you can group multiple `query()` calls in one session.

## Link traces to your app

The SDK propagates W3C trace context into the CLI: if you call `query()` while an
OpenTelemetry span is active, the agent run nests inside your span. Set
`TRACEPARENT` in `options.env` to pin a specific parent.

## Tag and attribute

Override `OTEL_SERVICE_NAME` and add `OTEL_RESOURCE_ATTRIBUTES` to filter by agent
and attach deployment metadata. For multi-user apps, inject percent-encoded
`enduser.id`/`tenant.id` resource attributes per call to build a per-user audit
trail.

## Control sensitive data

Telemetry is structural by default (durations, model/tool names, token counts).
Content is added only with opt-in vars: `OTEL_LOG_USER_PROMPTS`,
`OTEL_LOG_TOOL_DETAILS`, `OTEL_LOG_TOOL_CONTENT`, and `OTEL_LOG_RAW_API_BODIES`.
Leave these unset unless your pipeline is approved to store that data.

## Flush short runs

Metrics export every 60s, traces/logs every 5s by default. For short tasks, lower
`OTEL_METRIC_EXPORT_INTERVAL`, `OTEL_LOGS_EXPORT_INTERVAL`, and
`OTEL_TRACES_EXPORT_INTERVAL` so data reaches the collector before exit.

## Source

- Observability with OpenTelemetry: https://code.claude.com/docs/en/agent-sdk/observability

About this resource

Overview

The Claude Agent SDK can export traces, metrics, and log events as OpenTelemetry data to any OTLP backend. The SDK runs the Claude Code CLI as a child process; the CLI has the OpenTelemetry instrumentation and exports directly, while the SDK passes configuration through as environment variables.

Enable export

Telemetry is off until you set CLAUDE_CODE_ENABLE_TELEMETRY=1 and choose at least one exporter. The three signals are independent:

Signal Enable with
Metrics OTEL_METRICS_EXPORTER
Log events OTEL_LOGS_EXPORTER
Traces OTEL_TRACES_EXPORTER plus CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1
const otelEnv = {
  CLAUDE_CODE_ENABLE_TELEMETRY: "1",
  CLAUDE_CODE_ENHANCED_TELEMETRY_BETA: "1",
  OTEL_TRACES_EXPORTER: "otlp",
  OTEL_METRICS_EXPORTER: "otlp",
  OTEL_LOGS_EXPORTER: "otlp",
  OTEL_EXPORTER_OTLP_PROTOCOL: "http/protobuf",
  OTEL_EXPORTER_OTLP_ENDPOINT: "https://collector.example.com:4318",
};
// TS replaces the inherited env, so spread process.env:
const options = { env: { ...process.env, ...otelEnv } };

In Python, env merges over the inherited environment. Do not use the console exporter through the SDK; stdout is its message channel.

Read agent traces

With traces enabled, each step becomes a span: claude_code.interaction (a turn), claude_code.llm_request (each model call), claude_code.tool (each tool, with permission-wait and execution children), and claude_code.hook. Spans carry a session.id attribute so you can group multiple query() calls in one session.

Link traces to your app

The SDK propagates W3C trace context into the CLI: if you call query() while an OpenTelemetry span is active, the agent run nests inside your span. Set TRACEPARENT in options.env to pin a specific parent.

Tag and attribute

Override OTEL_SERVICE_NAME and add OTEL_RESOURCE_ATTRIBUTES to filter by agent and attach deployment metadata. For multi-user apps, inject percent-encoded enduser.id/tenant.id resource attributes per call to build a per-user audit trail.

Control sensitive data

Telemetry is structural by default (durations, model/tool names, token counts). Content is added only with opt-in vars: OTEL_LOG_USER_PROMPTS, OTEL_LOG_TOOL_DETAILS, OTEL_LOG_TOOL_CONTENT, and OTEL_LOG_RAW_API_BODIES. Leave these unset unless your pipeline is approved to store that data.

Flush short runs

Metrics export every 60s, traces/logs every 5s by default. For short tasks, lower OTEL_METRIC_EXPORT_INTERVAL, OTEL_LOGS_EXPORT_INTERVAL, and OTEL_TRACES_EXPORT_INTERVAL so data reaches the collector before exit.

Source

Source citations

Add this badge to your README

Show that OpenTelemetry Observability for Claude Agent SDK Agents is listed on HeyClaude. Paste this Markdown into your README — it renders the badge and links back to this page.

Listed on HeyClaude
[![Listed on HeyClaude](https://heyclau.de/badge/guides/opentelemetry-observability-for-claude-agent-sdk-agents.svg)](https://heyclau.de/entry/guides/opentelemetry-observability-for-claude-agent-sdk-agents)

How it compares

OpenTelemetry Observability for Claude Agent SDK Agents side by side with 3 alternatives on trust, install, platform support, and disclosed safety notes — all from reviewed registry metadata.

1 trust signal differ across this comparison (Submitter).

Field

A practical walkthrough of exporting OpenTelemetry traces, metrics, and events from the Claude Agent SDK: enabling telemetry, configuring OTLP exporters, reading agent spans, linking traces to your app, and controlling sensitive data.

Open dossier

A practical walkthrough of token and spend accounting in the Claude Agent SDK. Read total_cost_usd from the result message, deduplicate parallel tool calls that share an assistant id, break spend down per model with modelUsage, sum cost across query() calls yourself, and read cache_creation/cache_read tokens.

Open dossier

A practical guide to instrumenting LLM and agent applications with traces, metrics, logs, GenAI semantic attributes, sampling, and privacy-aware redaction so teams can debug model calls, tool use, retries, and cost.

Open dossier

A practical walkthrough of using Agent Skills in the Claude Agent SDK: how skills are discovered from the filesystem via settingSources, the skills option to enable or filter them, tool access, and troubleshooting discovery.

Open dossier
Next steps
Trust
Review statusNot reviewedNot reviewedNot reviewedNot reviewed
Package trustPackage not verifiedPackage not verifiedPackage not verifiedPackage not verified
Source provenanceSource-backedSource-backedSource-backedSource-backed
SubmitterDiffersJPette1783JPette1783MkDev11JPette1783
Install riskReview firstReview firstReview firstReview first
Notes Safety ✓ Privacy ✓ Safety ✓ Privacy ✓ Safety ✓ Privacy ✓ Safety ✓ Privacy ✓
Brand
Categoryguidesguidesguidesguides
SourceSource-backedSource-backedSource-backedSource-backed
AuthorJPette1783JPette1783MkDev11JPette1783
Added2026-06-052026-06-052026-06-042026-06-05
Platforms
Harness
Source repo
Safety notesTelemetry is off until you set CLAUDE_CODE_ENABLE_TELEMETRY=1 and choose an exporter; turning it on starts exporting usage data, so confirm the destination is approved. Do not use the console exporter through the SDK; stdout is the SDK's message channel. Point OTLP at a collector or local Jaeger instead. Traces are beta and require CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1; span names and attributes may change between releases.total_cost_usd / costUSD are client-side estimates from a bundled price table, not authoritative billing; do not bill end users or trigger financial decisions from them. Estimates can drift when pricing changes or the SDK version does not recognize a model; use the Usage and Cost API or Console for real billing. Both success and error result messages include usage and cost; read cost regardless of subtype so failed runs are still accounted for.Observability data is production evidence, not proof that an LLM answer or agent action is correct. Do not let tracing wrappers change request ordering, retry behavior, timeout handling, or user-visible agent decisions. Keep alerting focused on actionable symptoms such as latency, error rate, failed tool calls, and budget anomalies.The skills option is a context filter, not a sandbox: unlisted skills are hidden from the model but their files remain on disk and are reachable via Read and Bash. Skills are model-invoked; pair them with a tight allowedTools list (and dontAsk where appropriate) so an invoked skill cannot use more tools than intended. The allowed-tools frontmatter in SKILL.md does not apply through the SDK; control tool access with the main allowedTools option.
Privacy notesBy default telemetry is structural (durations, model/tool names, token counts), not content; opt-in vars (OTEL_LOG_USER_PROMPTS, OTEL_LOG_TOOL_DETAILS, OTEL_LOG_TOOL_CONTENT, OTEL_LOG_RAW_API_BODIES) add prompt and tool content. Exporter headers can carry tokens; supply them via the environment, not committed config. End-user attribution via OTEL_RESOURCE_ATTRIBUTES creates a per-user audit trail; handle that data per your policy and percent-encode values.Usage data is token counts and cost, not content; it is safe to log, though it can reveal activity volume. Per-model and end-user attribution may be sent to an observability backend if you also enable telemetry; govern that data accordingly. The SDK uses prompt caching automatically; cache token fields reveal reuse patterns but not content.Prompts, completions, retrieved documents, tool arguments, tool outputs, embeddings metadata, user ids, and file names may appear in telemetry. Redact or hash sensitive fields before export, and store raw prompt/response content only when the team has an explicit retention policy. Use sampling and field-level controls so debug detail can increase during incidents without retaining every user conversation forever.Skill descriptions are loaded so the model can decide when to use them; keep sensitive workflow detail and secrets out of descriptions. Skills sourced from outside your project run their instructions in your sessions; review them before enabling. Skill content is sent to the model provider when a skill is invoked; treat it like any other prompt content.
Prerequisites
  • The Claude Agent SDK installed for Python or TypeScript.
  • An OTLP-compatible backend or collector (Honeycomb, Datadog, Grafana, Jaeger, etc.).
  • Ability to set environment variables for the process or via options.env.
  • The Claude Agent SDK installed for Python or TypeScript.
  • An async loop over query() results so you can read assistant and result messages.
  • For authoritative billing, access to the Usage and Cost API or the Console.
  • An LLM or agent application with identifiable request, model-call, retrieval, and tool-execution boundaries.
  • An observability backend or collector that can receive OpenTelemetry traces, metrics, and logs.
  • A policy for which prompt, completion, retrieval, and tool data may be retained.
  • Test traffic that exercises normal responses, model failures, retries, and tool errors.
  • The Claude Agent SDK installed for Python or TypeScript.
  • SKILL.md files in .claude/skills/ (project) or ~/.claude/skills/ (user).
  • A cwd that points at or below the directory containing .claude/skills/, within the same repository.
Install
Config
Citations
ClaimUnclaimedUnclaimedUnclaimedUnclaimed
Open 4 picks in the interactive comparison tool

Related guides

Signals

Loading live community signals…

More like this, weekly

A short, calm digest of reviewed Claude resources. Unsubscribe any time.