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
from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor
63
+
from openobserve import openobserve_init
64
+
65
+
# Initialize OpenObserve and instrument Anthropic
66
+
AnthropicInstrumentor().instrument()
67
+
openobserve_init()
68
+
69
+
from anthropic import Anthropic
70
+
71
+
# Use Claude as normal - traces are automatically captured
72
+
client = Anthropic()
73
+
response = client.messages.create(
74
+
model="claude-3-5-sonnet-20241022",
75
+
max_tokens=1024,
76
+
messages=[{"role": "user", "content": "Hello!"}]
77
+
)
78
+
print(response.content[0].text)
79
+
```
80
+
50
81
### Selecting Signals
51
82
52
-
`openobserve_init()` initializes logs, metrics, and traces when no signal arguments are provided. As soon as you pass any of the `logs`, `metrics`, or `traces` flags, only the explicitly provided signals are enabled.
83
+
By default, `openobserve_init()` initializes all signals (logs, metrics, traces). You can also initialize selectively:
53
84
54
85
```python
55
-
# All signals (logs + metrics + traces)
86
+
# All signals (default)
56
87
openobserve_init()
57
88
58
-
#Logs only
89
+
#Specific signals only
59
90
openobserve_init(logs=True)
91
+
openobserve_init(metrics=True)
92
+
openobserve_init(traces=True)
93
+
94
+
# Combine signals
95
+
openobserve_init(logs=True, metrics=True) # no traces
96
+
```
97
+
98
+
**Note:** For logs, you still need to bridge Python's standard `logging` module:
99
+
```python
100
+
import logging
101
+
from opentelemetry.sdk._logs import LoggingHandler
#Or install from source (includes both HTTP/Protobuf and gRPC support)
149
+
#From source (development)
105
150
pip install -e .
106
151
107
-
#Or using requirements.txt
152
+
#Using requirements.txt
108
153
pip install -r requirements.txt
109
154
```
110
155
156
+
Both HTTP/Protobuf (default) and gRPC protocols are included in all installations.
157
+
158
+
## Supported Instruments
159
+
160
+
The SDK works with OpenTelemetry instrumentation packages:
161
+
162
+
-**OpenAI** – Use with `opentelemetry-instrumentation-openai` for API call traces
163
+
-**Anthropic** – Use with `opentelemetry-instrumentation-anthropic` for Claude API traces
164
+
-**LangChain** – Use with `opentelemetry-instrumentation-langchain` for LLM chain tracing
165
+
-**Standard Python Logging** – Built-in support via `LoggingHandler`
166
+
-**Metrics** – OpenTelemetry counters, histograms, and up/down counters
167
+
111
168
## Examples
112
169
113
-
-`examples/openai_example.py` – end-to-end traces example with the OpenAI instrumentation.
114
-
-`examples/logs_example.py` – bridges standard Python logging through OpenTelemetry and ships the records to OpenObserve. Run with `uv run examples/logs_example.py`.
115
-
-`examples/metrics_example.py` – demonstrates counters, histograms, and up/down counters exported to OpenObserve. Run with `uv run examples/metrics_example.py`.
116
-
-`examples/session_demo.py`, `examples/qa_chain.py`, etc. – additional traces-first demos.
170
+
Run any of these examples to see the SDK in action. First, ensure environment variables are set:
0 commit comments