You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tokens and costs are more generally supported by any instrumentation that follows the standard [OpenTelemetry semantic conventions for GenAI spans](https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/). The following snippet shows the attributes required if you want to log the data manually:
Copy file name to clipboardExpand all lines: docs/integrations/llms/anthropic.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,9 @@ With that you get:
45
45
46
46
## Methods covered
47
47
48
+
!!! note
49
+
This is separate from [Claude Agent SDK instrumentation](../llms/claude-agent-sdk.md). The Claude Agent SDK doesn't actually use the `anthropic` package under the hood.
description: "Guide for using Logfire with Claude Agent SDK via Langsmith OpenTelemetry tracing, including setup instructions and example trace output."
4
+
integration: "third-party"
5
+
---
6
+
# Claude Agent SDK
7
+
8
+
You can instrument the Python [Claude Agent SDK](https://platform.claude.com/docs/en/agent-sdk/overview) using **Logfire** and [Langsmith](https://docs.langchain.com/langsmith/trace-claude-agent-sdk).
9
+
10
+
!!! note
11
+
This is separate from the [`anthropic` integration](../llms/anthropic.md). The Claude Agent SDK doesn't actually use the `anthropic` package under the hood.
12
+
13
+
First, install dependencies:
14
+
15
+
```bash
16
+
pip install 'langsmith[claude-agent-sdk, otel]'
17
+
```
18
+
19
+
Here's an example script:
20
+
21
+
```python
22
+
from langsmith.integrations.claude_agent_sdk import configure_claude_agent_sdk
23
+
import logfire
24
+
import os
25
+
import asyncio
26
+
from claude_agent_sdk import (
27
+
ClaudeAgentOptions,
28
+
ClaudeSDKClient,
29
+
tool,
30
+
create_sdk_mcp_server,
31
+
)
32
+
from typing import Any
33
+
34
+
# These environment variables enable Langsmith OpenTelemetry tracing,
35
+
# instead of sending traces to Langsmith directly.
36
+
os.environ['LANGSMITH_OTEL_ENABLED'] ="true"
37
+
os.environ['LANGSMITH_OTEL_ONLY'] ="true"
38
+
os.environ['LANGSMITH_TRACING'] ="true"
39
+
40
+
# Ensure that OpenTelemetry traces are sent to Logfire
41
+
logfire.configure()
42
+
43
+
# Instrument the Claude Agent SDK with Langsmith
44
+
configure_claude_agent_sdk()
45
+
46
+
# Example of using a tool in the Claude Agent SDK:
Copy file name to clipboardExpand all lines: docs/integrations/llms/langchain.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,11 @@ integration: "built-in"
5
5
---
6
6
# LangChain
7
7
8
-
[LangChain](https://www.langchain.com/) (and thus [LangGraph](https://www.langchain.com/langgraph)) has [built-in OpenTelemetry tracing via Langsmith](https://docs.smith.langchain.com/observability/how_to_guides/trace_langchain_with_otel) which you can use with **Logfire**. It's enabled by these two environment variables:
8
+
[LangChain](https://www.langchain.com/) (and thus [LangGraph](https://www.langchain.com/langgraph)) has [built-in OpenTelemetry tracing via Langsmith](https://docs.smith.langchain.com/observability/how_to_guides/trace_langchain_with_otel) which you can use with **Logfire**. It's enabled by these environment variables:
9
9
10
10
```
11
11
LANGSMITH_OTEL_ENABLED=true
12
+
LANGSMITH_OTEL_ONLY=true
12
13
LANGSMITH_TRACING=true
13
14
```
14
15
@@ -21,6 +22,7 @@ import logfire
21
22
22
23
# These environment variables need to be set before importing langchain or langgraph
0 commit comments