traceable-agent 2.0.1__tar.gz → 2.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- traceable_agent-2.3.1/PKG-INFO +326 -0
- traceable_agent-2.3.1/README.md +272 -0
- traceable_agent-2.3.1/pyproject.toml +15 -0
- traceable_agent-2.3.1/setup.py +101 -0
- traceable_agent-2.3.1/src/traceable_agent.egg-info/PKG-INFO +326 -0
- traceable_agent-2.3.1/src/traceable_agent.egg-info/SOURCES.txt +28 -0
- traceable_agent-2.3.1/src/traceable_agent.egg-info/entry_points.txt +6 -0
- traceable_agent-2.3.1/src/traceable_agent.egg-info/requires.txt +39 -0
- traceable_agent-2.3.1/src/traceableai/__init__.py +14 -0
- traceable_agent-2.3.1/src/traceableai/agent.py +92 -0
- traceable_agent-2.3.1/src/traceableai/autoinstrumentation/sitecustomize.py +34 -0
- {traceable-agent-2.0.1 → traceable_agent-2.3.1}/src/traceableai/autoinstrumentation/wrapper.py +25 -29
- traceable_agent-2.3.1/src/traceableai/config/__init__.py +1 -0
- traceable_agent-2.3.1/src/traceableai/config/config.py +73 -0
- traceable_agent-2.3.1/src/traceableai/config/default.py +38 -0
- traceable_agent-2.3.1/src/traceableai/config/environment.py +77 -0
- {traceable-agent-2.0.1 → traceable_agent-2.3.1}/src/traceableai/custom_logger.py +4 -2
- {traceable-agent-2.0.1 → traceable_agent-2.3.1}/src/traceableai/filter/__init__.py +7 -12
- traceable_agent-2.3.1/src/traceableai/filter/libtraceable_common.py +56 -0
- traceable_agent-2.3.1/src/traceableai/filter/traceable.py +530 -0
- traceable_agent-2.3.1/src/traceableai/plugins/__init__.py +1 -0
- traceable_agent-2.3.1/src/traceableai/plugins/traceable_control.py +112 -0
- {traceable-agent-2.0.1 → traceable_agent-2.3.1}/src/traceableai/version.py +1 -1
- traceable_agent-2.3.1/src/traceableai/version_format.py +26 -0
- traceable-agent-2.0.1/PKG-INFO +0 -97
- traceable-agent-2.0.1/README.md +0 -82
- traceable-agent-2.0.1/pyproject.toml +0 -8
- traceable-agent-2.0.1/setup.py +0 -67
- traceable-agent-2.0.1/src/traceable_agent.egg-info/PKG-INFO +0 -97
- traceable-agent-2.0.1/src/traceable_agent.egg-info/SOURCES.txt +0 -45
- traceable-agent-2.0.1/src/traceable_agent.egg-info/entry_points.txt +0 -3
- traceable-agent-2.0.1/src/traceable_agent.egg-info/requires.txt +0 -28
- traceable-agent-2.0.1/src/traceableai/__init__.py +0 -7
- traceable-agent-2.0.1/src/traceableai/agent.py +0 -186
- traceable-agent-2.0.1/src/traceableai/agent_init.py +0 -168
- traceable-agent-2.0.1/src/traceableai/autoinstrumentation/sitecustomize.py +0 -37
- traceable-agent-2.0.1/src/traceableai/config/__init__.py +0 -0
- traceable-agent-2.0.1/src/traceableai/config/config.py +0 -84
- traceable-agent-2.0.1/src/traceableai/config/config_pb2.py +0 -91
- traceable-agent-2.0.1/src/traceableai/config/default.py +0 -54
- traceable-agent-2.0.1/src/traceableai/config/environment.py +0 -150
- traceable-agent-2.0.1/src/traceableai/constants.py +0 -9
- traceable-agent-2.0.1/src/traceableai/env.py +0 -7
- traceable-agent-2.0.1/src/traceableai/filter/filter.py +0 -18
- traceable-agent-2.0.1/src/traceableai/filter/registry.py +0 -42
- traceable-agent-2.0.1/src/traceableai/filter/traceable.py +0 -260
- traceable-agent-2.0.1/src/traceableai/instrumentation/__init__.py +0 -230
- traceable-agent-2.0.1/src/traceableai/instrumentation/aiohttp/__init__.py +0 -182
- traceable-agent-2.0.1/src/traceableai/instrumentation/aws_lambda/__init__.py +0 -200
- traceable-agent-2.0.1/src/traceableai/instrumentation/boto/__init__.py +0 -11
- traceable-agent-2.0.1/src/traceableai/instrumentation/botocore/__init__.py +0 -11
- traceable-agent-2.0.1/src/traceableai/instrumentation/django/__init__.py +0 -64
- traceable-agent-2.0.1/src/traceableai/instrumentation/django/django_auto_instrumentation_compat.py +0 -70
- traceable-agent-2.0.1/src/traceableai/instrumentation/fast_api/__init__.py +0 -189
- traceable-agent-2.0.1/src/traceableai/instrumentation/fast_api/fast_api_auto_instrumentation_compat.py +0 -65
- traceable-agent-2.0.1/src/traceableai/instrumentation/flask/__init__.py +0 -184
- traceable-agent-2.0.1/src/traceableai/instrumentation/grpc/__init__.py +0 -266
- traceable-agent-2.0.1/src/traceableai/instrumentation/instrumentation_definitions.py +0 -99
- traceable-agent-2.0.1/src/traceableai/instrumentation/mysql/__init__.py +0 -11
- traceable-agent-2.0.1/src/traceableai/instrumentation/postgresql/__init__.py +0 -13
- traceable-agent-2.0.1/src/traceableai/instrumentation/requests/__init__.py +0 -35
- {traceable-agent-2.0.1 → traceable_agent-2.3.1}/MANIFEST.in +0 -0
- {traceable-agent-2.0.1 → traceable_agent-2.3.1}/setup.cfg +0 -0
- {traceable-agent-2.0.1 → traceable_agent-2.3.1}/src/traceable_agent.egg-info/dependency_links.txt +0 -0
- {traceable-agent-2.0.1 → traceable_agent-2.3.1}/src/traceable_agent.egg-info/top_level.txt +0 -0
- {traceable-agent-2.0.1 → traceable_agent-2.3.1}/src/traceableai/autoinstrumentation/__init__.py +0 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: traceable-agent
|
|
3
|
+
Version: 2.3.1
|
|
4
|
+
Summary: Traceable.ai Python Agent
|
|
5
|
+
Home-page: https://traceable.ai
|
|
6
|
+
Author: Traceable.ai
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: harness-sdk>=0.1.0
|
|
12
|
+
Requires-Dist: opentelemetry-api==1.41.1
|
|
13
|
+
Requires-Dist: opentelemetry-exporter-otlp==1.41.1
|
|
14
|
+
Requires-Dist: opentelemetry-instrumentation==0.62b1
|
|
15
|
+
Requires-Dist: opentelemetry-instrumentation-aiohttp-client==0.62b1
|
|
16
|
+
Requires-Dist: opentelemetry-instrumentation-botocore==0.62b1
|
|
17
|
+
Requires-Dist: opentelemetry-instrumentation-wsgi==0.62b1
|
|
18
|
+
Requires-Dist: opentelemetry-instrumentation-fastapi==0.62b1
|
|
19
|
+
Requires-Dist: opentelemetry-instrumentation-flask==0.62b1
|
|
20
|
+
Requires-Dist: opentelemetry-instrumentation-mysql==0.62b1
|
|
21
|
+
Requires-Dist: opentelemetry-instrumentation-psycopg2==0.62b1
|
|
22
|
+
Requires-Dist: opentelemetry-instrumentation-requests==0.62b1
|
|
23
|
+
Requires-Dist: opentelemetry-instrumentation-httpx==0.62b1
|
|
24
|
+
Requires-Dist: opentelemetry-instrumentation-grpc==0.62b1
|
|
25
|
+
Requires-Dist: opentelemetry-instrumentation-django==0.62b1
|
|
26
|
+
Requires-Dist: opentelemetry-instrumentation-mcp==0.60.0
|
|
27
|
+
Requires-Dist: opentelemetry-semantic-conventions-ai<0.6.0,>=0.5.1
|
|
28
|
+
Requires-Dist: opentelemetry-propagator-b3==1.41.1
|
|
29
|
+
Requires-Dist: opentelemetry-proto==1.41.1
|
|
30
|
+
Requires-Dist: opentelemetry-sdk==1.41.1
|
|
31
|
+
Requires-Dist: opentelemetry-util-http==0.62b1
|
|
32
|
+
Requires-Dist: google>=3.0.0
|
|
33
|
+
Requires-Dist: pyyaml
|
|
34
|
+
Requires-Dist: protobuf
|
|
35
|
+
Requires-Dist: psutil
|
|
36
|
+
Requires-Dist: distro
|
|
37
|
+
Requires-Dist: cffi
|
|
38
|
+
Requires-Dist: setuptools
|
|
39
|
+
Requires-Dist: jaraco.text
|
|
40
|
+
Requires-Dist: platformdirs
|
|
41
|
+
Provides-Extra: anthropic
|
|
42
|
+
Requires-Dist: anthropic>=0.34.0; extra == "anthropic"
|
|
43
|
+
Provides-Extra: openai
|
|
44
|
+
Requires-Dist: openai>=1.40.0; extra == "openai"
|
|
45
|
+
Provides-Extra: litellm
|
|
46
|
+
Requires-Dist: litellm>=1.60.0; extra == "litellm"
|
|
47
|
+
Dynamic: author
|
|
48
|
+
Dynamic: classifier
|
|
49
|
+
Dynamic: home-page
|
|
50
|
+
Dynamic: provides-extra
|
|
51
|
+
Dynamic: requires-dist
|
|
52
|
+
Dynamic: requires-python
|
|
53
|
+
Dynamic: summary
|
|
54
|
+
|
|
55
|
+
# Python Agent
|
|
56
|
+
|
|
57
|
+
This repository ships two related packages:
|
|
58
|
+
|
|
59
|
+
| Package | PyPI name | Import | Role |
|
|
60
|
+
|---------|-----------|--------|------|
|
|
61
|
+
| **otel-python-sdk** | `harness-sdk` | `harness_sdk` | Generic OpenTelemetry-based instrumentation SDK (HTTP, gRPC, DB, GenAI, plugins). |
|
|
62
|
+
| **Traceable agent** | `traceable-agent` | `traceableai` | Extends the SDK with Traceable blocking (`libtraceable`), remote config, and sampling. Depends on `harness-sdk`. |
|
|
63
|
+
|
|
64
|
+
The SDK lives in [`otel-python-sdk/`](otel-python-sdk/). The Traceable wrapper and native filter are under [`src/traceableai/`](src/traceableai/).
|
|
65
|
+
|
|
66
|
+
**Requirements:** Python >= 3.10
|
|
67
|
+
|
|
68
|
+
**Supported OS for `libtraceable` (blocking filter):** Ubuntu 18.04+, CentOS 7+, Debian 10+, Amazon Linux 2+
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Installation
|
|
73
|
+
|
|
74
|
+
### Local development (both packages)
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
python3 -m venv venv
|
|
78
|
+
source venv/bin/activate
|
|
79
|
+
|
|
80
|
+
# Vendor GenAI instrumentation (needed for anthropic/openai tests and builds)
|
|
81
|
+
bash scripts/fetch-vendor.sh
|
|
82
|
+
python3 otel-python-sdk/scripts/bundle_vendor.py
|
|
83
|
+
|
|
84
|
+
# Editable SDK + Traceable agent
|
|
85
|
+
pip install -e "./otel-python-sdk[dev]"
|
|
86
|
+
pip install -r requirements.txt -r dev-requirements.txt
|
|
87
|
+
pip install -e .
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Optional GenAI extras:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pip install -e "./otel-python-sdk[anthropic,openai,litellm]"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
If `grpc` fails to compile, prepend: `GRPC_PYTHON_BUILD_SYSTEM_ZLIB=true`
|
|
97
|
+
|
|
98
|
+
### Production install
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
pip install harness-sdk # SDK only
|
|
102
|
+
pip install traceable-agent # SDK + Traceable (includes libtraceable on supported Linux)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Configuration
|
|
108
|
+
|
|
109
|
+
Configuration is layered: **defaults → YAML file → environment variables**. Use separate files for SDK vs Traceable-specific settings.
|
|
110
|
+
|
|
111
|
+
| Setting | Config file env | Prefix | Examples |
|
|
112
|
+
|---------|-----------------|--------|----------|
|
|
113
|
+
| SDK (instrumentation, reporting, GenAI, plugins) | `HA_CONFIG_FILE` | `HA_*` | `HA_SERVICE_NAME`, `HA_REPORTING_ENDPOINT`, `HA_CONTROL_PLUGINS` |
|
|
114
|
+
| Traceable (blocking, remote config, sampling) | `TA_CONFIG_FILE` | `TA_*` | `TA_BLOCKING_CONFIG_ENABLED`, `TA_REMOTE_CONFIG_ENABLED` |
|
|
115
|
+
|
|
116
|
+
Legacy aliases `AT_CONFIG_FILE` / `AT_*` are still read for SDK settings during migration.
|
|
117
|
+
|
|
118
|
+
### SDK config (`HA_CONFIG_FILE`)
|
|
119
|
+
|
|
120
|
+
Example `agent-config.yaml`:
|
|
121
|
+
|
|
122
|
+
```yaml
|
|
123
|
+
service_name: my-service
|
|
124
|
+
enabled: true
|
|
125
|
+
|
|
126
|
+
reporting:
|
|
127
|
+
endpoint: http://localhost:4318/v1/traces
|
|
128
|
+
trace_reporter_type: OTLP # or ZIPKIN
|
|
129
|
+
secure: false
|
|
130
|
+
token: ""
|
|
131
|
+
|
|
132
|
+
data_capture:
|
|
133
|
+
http_headers:
|
|
134
|
+
request: true
|
|
135
|
+
response: true
|
|
136
|
+
http_body:
|
|
137
|
+
request: true
|
|
138
|
+
response: true
|
|
139
|
+
body_max_size_bytes: 131072
|
|
140
|
+
|
|
141
|
+
propagation_formats: ["TRACECONTEXT", "B3"]
|
|
142
|
+
|
|
143
|
+
gen_ai:
|
|
144
|
+
enabled: true
|
|
145
|
+
payload_capture_enabled: true
|
|
146
|
+
payload_evaluation_enabled: true
|
|
147
|
+
|
|
148
|
+
plugins:
|
|
149
|
+
control: [] # e.g. custom control plugins by name
|
|
150
|
+
observability:
|
|
151
|
+
- builtin_pipeline
|
|
152
|
+
- builtin_span_attributes
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Point the agent at the file:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
export HA_CONFIG_FILE=/path/to/agent-config.yaml
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Common environment overrides:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
export HA_SERVICE_NAME=my-service
|
|
165
|
+
export HA_REPORTING_ENDPOINT=http://otel-collector:4318/v1/traces
|
|
166
|
+
export HA_REPORTING_TRACE_REPORTER_TYPE=OTLP
|
|
167
|
+
export HA_ENABLED=true
|
|
168
|
+
export HA_GEN_AI_ENABLED=true
|
|
169
|
+
export HA_CONTROL_PLUGINS=traceable # comma-separated control plugin names
|
|
170
|
+
export HA_ENABLE_CONSOLE_SPAN_EXPORTER=true # dev only: print spans to stdout
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Traceable config (`TA_CONFIG_FILE`)
|
|
174
|
+
|
|
175
|
+
Example `traceable-config.yaml`:
|
|
176
|
+
|
|
177
|
+
```yaml
|
|
178
|
+
blocking_config:
|
|
179
|
+
enabled: true
|
|
180
|
+
evaluate_body: true
|
|
181
|
+
max_recursion_depth: 20
|
|
182
|
+
|
|
183
|
+
remote_config:
|
|
184
|
+
enabled: true
|
|
185
|
+
endpoint: localhost:5442
|
|
186
|
+
poll_period_seconds: 30
|
|
187
|
+
|
|
188
|
+
sampling:
|
|
189
|
+
enabled: false
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
export TA_CONFIG_FILE=/path/to/traceable-config.yaml
|
|
194
|
+
export TA_REMOTE_CONFIG_ENABLED=false # disable remote config polling in dev/tests
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
For integration tests, see [`test/traceableai/agent/integration-agent-config.yaml`](test/traceableai/agent/integration-agent-config.yaml) and [`test/traceableai/agent/traceable-integration-config.yaml`](test/traceableai/agent/traceable-integration-config.yaml).
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## Usage
|
|
202
|
+
|
|
203
|
+
### SDK only (`harness_sdk`)
|
|
204
|
+
|
|
205
|
+
Use when you want instrumentation and OTLP/ZIPKIN export without Traceable blocking or remote config.
|
|
206
|
+
|
|
207
|
+
**Code-based instrumentation**
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
from harness_sdk.agent import Agent
|
|
211
|
+
|
|
212
|
+
app = Flask(__name__)
|
|
213
|
+
|
|
214
|
+
agent = Agent()
|
|
215
|
+
agent.instrument(app) # Flask + other supported libraries
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
**Auto-instrumentation**
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
export HA_CONFIG_FILE=/path/to/agent-config.yaml
|
|
222
|
+
harness-instrument flask run -p 5000
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Traceable agent (`traceableai`)
|
|
226
|
+
|
|
227
|
+
Use for production Traceable deployments (blocking, remote config, `libtraceable`).
|
|
228
|
+
|
|
229
|
+
**Code-based instrumentation**
|
|
230
|
+
|
|
231
|
+
```python
|
|
232
|
+
from traceableai.agent import Agent
|
|
233
|
+
|
|
234
|
+
app = Flask(__name__)
|
|
235
|
+
|
|
236
|
+
agent = Agent()
|
|
237
|
+
agent.instrument(app)
|
|
238
|
+
|
|
239
|
+
# Prefer plugins.control in HA_CONFIG_FILE; this remains for backward compatibility:
|
|
240
|
+
agent.add_traceable_filter()
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Recommended: enable the Traceable control plugin via config instead of calling `add_traceable_filter()`:
|
|
244
|
+
|
|
245
|
+
```yaml
|
|
246
|
+
# agent-config.yaml (HA_CONFIG_FILE)
|
|
247
|
+
plugins:
|
|
248
|
+
control:
|
|
249
|
+
- traceable
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
**Auto-instrumentation**
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
export HA_CONFIG_FILE=/path/to/agent-config.yaml
|
|
256
|
+
export TA_CONFIG_FILE=/path/to/traceable-config.yaml
|
|
257
|
+
traceableai-instrument flask run -p 5000
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
`traceableai-instrument` loads `sitecustomize`, starts the agent, auto-instruments supported libraries, and registers the Traceable control plugin (unless deferred for gunicorn post-fork).
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## Developing
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
python3 -m venv venv
|
|
268
|
+
source venv/bin/activate
|
|
269
|
+
bash scripts/fetch-vendor.sh
|
|
270
|
+
python3 otel-python-sdk/scripts/bundle_vendor.py
|
|
271
|
+
pip install -e "./otel-python-sdk[dev,anthropic,openai,litellm]"
|
|
272
|
+
pip install -r requirements.txt -r dev-requirements.txt
|
|
273
|
+
pip install -e .
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Testing
|
|
277
|
+
|
|
278
|
+
**SDK unit tests** (matches CI “SDK Unit Tests”):
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
./scripts/run-sdk-unit-tests.sh
|
|
282
|
+
# Full integration tests (mysql/postgres/docker):
|
|
283
|
+
RUN_SDK_INTEGRATION_TESTS=1 ./scripts/run-sdk-unit-tests.sh
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
**Traceable unit tests** (from repo root; skips native filter and duplicate instrumentation tree):
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
python3 -m pytest \
|
|
290
|
+
--ignore=test/traceableai/agent/instrumentation
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Integration services (optional):
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
cd test/externalServices && docker compose up -d
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Building
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
pip install -r requirements.txt
|
|
303
|
+
python3 -m build
|
|
304
|
+
# Or all wheel variants:
|
|
305
|
+
# CIBW_SKIP="*37* *38* ..." ./build_artifacts.sh
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
Docker-based unit test image (legacy):
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
docker build -f docker/test_apps/unittest.Dockerfile -t pythonunittest .
|
|
312
|
+
docker run --rm pythonunittest
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Updating libtraceable
|
|
316
|
+
|
|
317
|
+
1. Update `filter/libtraceable.h` if the header changed.
|
|
318
|
+
2. Edit `./src/download.py` and bump `LIBTRACEABLE_VERSION`.
|
|
319
|
+
3. Verify with a test app under `docker/test_apps/`.
|
|
320
|
+
|
|
321
|
+
### Updating protos
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
git submodule update --init --recursive
|
|
325
|
+
./scripts/build_proto.sh
|
|
326
|
+
```
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
# Python Agent
|
|
2
|
+
|
|
3
|
+
This repository ships two related packages:
|
|
4
|
+
|
|
5
|
+
| Package | PyPI name | Import | Role |
|
|
6
|
+
|---------|-----------|--------|------|
|
|
7
|
+
| **otel-python-sdk** | `harness-sdk` | `harness_sdk` | Generic OpenTelemetry-based instrumentation SDK (HTTP, gRPC, DB, GenAI, plugins). |
|
|
8
|
+
| **Traceable agent** | `traceable-agent` | `traceableai` | Extends the SDK with Traceable blocking (`libtraceable`), remote config, and sampling. Depends on `harness-sdk`. |
|
|
9
|
+
|
|
10
|
+
The SDK lives in [`otel-python-sdk/`](otel-python-sdk/). The Traceable wrapper and native filter are under [`src/traceableai/`](src/traceableai/).
|
|
11
|
+
|
|
12
|
+
**Requirements:** Python >= 3.10
|
|
13
|
+
|
|
14
|
+
**Supported OS for `libtraceable` (blocking filter):** Ubuntu 18.04+, CentOS 7+, Debian 10+, Amazon Linux 2+
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
### Local development (both packages)
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
python3 -m venv venv
|
|
24
|
+
source venv/bin/activate
|
|
25
|
+
|
|
26
|
+
# Vendor GenAI instrumentation (needed for anthropic/openai tests and builds)
|
|
27
|
+
bash scripts/fetch-vendor.sh
|
|
28
|
+
python3 otel-python-sdk/scripts/bundle_vendor.py
|
|
29
|
+
|
|
30
|
+
# Editable SDK + Traceable agent
|
|
31
|
+
pip install -e "./otel-python-sdk[dev]"
|
|
32
|
+
pip install -r requirements.txt -r dev-requirements.txt
|
|
33
|
+
pip install -e .
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Optional GenAI extras:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install -e "./otel-python-sdk[anthropic,openai,litellm]"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
If `grpc` fails to compile, prepend: `GRPC_PYTHON_BUILD_SYSTEM_ZLIB=true`
|
|
43
|
+
|
|
44
|
+
### Production install
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install harness-sdk # SDK only
|
|
48
|
+
pip install traceable-agent # SDK + Traceable (includes libtraceable on supported Linux)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Configuration
|
|
54
|
+
|
|
55
|
+
Configuration is layered: **defaults → YAML file → environment variables**. Use separate files for SDK vs Traceable-specific settings.
|
|
56
|
+
|
|
57
|
+
| Setting | Config file env | Prefix | Examples |
|
|
58
|
+
|---------|-----------------|--------|----------|
|
|
59
|
+
| SDK (instrumentation, reporting, GenAI, plugins) | `HA_CONFIG_FILE` | `HA_*` | `HA_SERVICE_NAME`, `HA_REPORTING_ENDPOINT`, `HA_CONTROL_PLUGINS` |
|
|
60
|
+
| Traceable (blocking, remote config, sampling) | `TA_CONFIG_FILE` | `TA_*` | `TA_BLOCKING_CONFIG_ENABLED`, `TA_REMOTE_CONFIG_ENABLED` |
|
|
61
|
+
|
|
62
|
+
Legacy aliases `AT_CONFIG_FILE` / `AT_*` are still read for SDK settings during migration.
|
|
63
|
+
|
|
64
|
+
### SDK config (`HA_CONFIG_FILE`)
|
|
65
|
+
|
|
66
|
+
Example `agent-config.yaml`:
|
|
67
|
+
|
|
68
|
+
```yaml
|
|
69
|
+
service_name: my-service
|
|
70
|
+
enabled: true
|
|
71
|
+
|
|
72
|
+
reporting:
|
|
73
|
+
endpoint: http://localhost:4318/v1/traces
|
|
74
|
+
trace_reporter_type: OTLP # or ZIPKIN
|
|
75
|
+
secure: false
|
|
76
|
+
token: ""
|
|
77
|
+
|
|
78
|
+
data_capture:
|
|
79
|
+
http_headers:
|
|
80
|
+
request: true
|
|
81
|
+
response: true
|
|
82
|
+
http_body:
|
|
83
|
+
request: true
|
|
84
|
+
response: true
|
|
85
|
+
body_max_size_bytes: 131072
|
|
86
|
+
|
|
87
|
+
propagation_formats: ["TRACECONTEXT", "B3"]
|
|
88
|
+
|
|
89
|
+
gen_ai:
|
|
90
|
+
enabled: true
|
|
91
|
+
payload_capture_enabled: true
|
|
92
|
+
payload_evaluation_enabled: true
|
|
93
|
+
|
|
94
|
+
plugins:
|
|
95
|
+
control: [] # e.g. custom control plugins by name
|
|
96
|
+
observability:
|
|
97
|
+
- builtin_pipeline
|
|
98
|
+
- builtin_span_attributes
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Point the agent at the file:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
export HA_CONFIG_FILE=/path/to/agent-config.yaml
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Common environment overrides:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
export HA_SERVICE_NAME=my-service
|
|
111
|
+
export HA_REPORTING_ENDPOINT=http://otel-collector:4318/v1/traces
|
|
112
|
+
export HA_REPORTING_TRACE_REPORTER_TYPE=OTLP
|
|
113
|
+
export HA_ENABLED=true
|
|
114
|
+
export HA_GEN_AI_ENABLED=true
|
|
115
|
+
export HA_CONTROL_PLUGINS=traceable # comma-separated control plugin names
|
|
116
|
+
export HA_ENABLE_CONSOLE_SPAN_EXPORTER=true # dev only: print spans to stdout
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Traceable config (`TA_CONFIG_FILE`)
|
|
120
|
+
|
|
121
|
+
Example `traceable-config.yaml`:
|
|
122
|
+
|
|
123
|
+
```yaml
|
|
124
|
+
blocking_config:
|
|
125
|
+
enabled: true
|
|
126
|
+
evaluate_body: true
|
|
127
|
+
max_recursion_depth: 20
|
|
128
|
+
|
|
129
|
+
remote_config:
|
|
130
|
+
enabled: true
|
|
131
|
+
endpoint: localhost:5442
|
|
132
|
+
poll_period_seconds: 30
|
|
133
|
+
|
|
134
|
+
sampling:
|
|
135
|
+
enabled: false
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
export TA_CONFIG_FILE=/path/to/traceable-config.yaml
|
|
140
|
+
export TA_REMOTE_CONFIG_ENABLED=false # disable remote config polling in dev/tests
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
For integration tests, see [`test/traceableai/agent/integration-agent-config.yaml`](test/traceableai/agent/integration-agent-config.yaml) and [`test/traceableai/agent/traceable-integration-config.yaml`](test/traceableai/agent/traceable-integration-config.yaml).
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Usage
|
|
148
|
+
|
|
149
|
+
### SDK only (`harness_sdk`)
|
|
150
|
+
|
|
151
|
+
Use when you want instrumentation and OTLP/ZIPKIN export without Traceable blocking or remote config.
|
|
152
|
+
|
|
153
|
+
**Code-based instrumentation**
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
from harness_sdk.agent import Agent
|
|
157
|
+
|
|
158
|
+
app = Flask(__name__)
|
|
159
|
+
|
|
160
|
+
agent = Agent()
|
|
161
|
+
agent.instrument(app) # Flask + other supported libraries
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**Auto-instrumentation**
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
export HA_CONFIG_FILE=/path/to/agent-config.yaml
|
|
168
|
+
harness-instrument flask run -p 5000
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Traceable agent (`traceableai`)
|
|
172
|
+
|
|
173
|
+
Use for production Traceable deployments (blocking, remote config, `libtraceable`).
|
|
174
|
+
|
|
175
|
+
**Code-based instrumentation**
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
from traceableai.agent import Agent
|
|
179
|
+
|
|
180
|
+
app = Flask(__name__)
|
|
181
|
+
|
|
182
|
+
agent = Agent()
|
|
183
|
+
agent.instrument(app)
|
|
184
|
+
|
|
185
|
+
# Prefer plugins.control in HA_CONFIG_FILE; this remains for backward compatibility:
|
|
186
|
+
agent.add_traceable_filter()
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Recommended: enable the Traceable control plugin via config instead of calling `add_traceable_filter()`:
|
|
190
|
+
|
|
191
|
+
```yaml
|
|
192
|
+
# agent-config.yaml (HA_CONFIG_FILE)
|
|
193
|
+
plugins:
|
|
194
|
+
control:
|
|
195
|
+
- traceable
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**Auto-instrumentation**
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
export HA_CONFIG_FILE=/path/to/agent-config.yaml
|
|
202
|
+
export TA_CONFIG_FILE=/path/to/traceable-config.yaml
|
|
203
|
+
traceableai-instrument flask run -p 5000
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
`traceableai-instrument` loads `sitecustomize`, starts the agent, auto-instruments supported libraries, and registers the Traceable control plugin (unless deferred for gunicorn post-fork).
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## Developing
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
python3 -m venv venv
|
|
214
|
+
source venv/bin/activate
|
|
215
|
+
bash scripts/fetch-vendor.sh
|
|
216
|
+
python3 otel-python-sdk/scripts/bundle_vendor.py
|
|
217
|
+
pip install -e "./otel-python-sdk[dev,anthropic,openai,litellm]"
|
|
218
|
+
pip install -r requirements.txt -r dev-requirements.txt
|
|
219
|
+
pip install -e .
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Testing
|
|
223
|
+
|
|
224
|
+
**SDK unit tests** (matches CI “SDK Unit Tests”):
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
./scripts/run-sdk-unit-tests.sh
|
|
228
|
+
# Full integration tests (mysql/postgres/docker):
|
|
229
|
+
RUN_SDK_INTEGRATION_TESTS=1 ./scripts/run-sdk-unit-tests.sh
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
**Traceable unit tests** (from repo root; skips native filter and duplicate instrumentation tree):
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
python3 -m pytest \
|
|
236
|
+
--ignore=test/traceableai/agent/instrumentation
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Integration services (optional):
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
cd test/externalServices && docker compose up -d
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Building
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
pip install -r requirements.txt
|
|
249
|
+
python3 -m build
|
|
250
|
+
# Or all wheel variants:
|
|
251
|
+
# CIBW_SKIP="*37* *38* ..." ./build_artifacts.sh
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Docker-based unit test image (legacy):
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
docker build -f docker/test_apps/unittest.Dockerfile -t pythonunittest .
|
|
258
|
+
docker run --rm pythonunittest
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Updating libtraceable
|
|
262
|
+
|
|
263
|
+
1. Update `filter/libtraceable.h` if the header changed.
|
|
264
|
+
2. Edit `./src/download.py` and bump `LIBTRACEABLE_VERSION`.
|
|
265
|
+
3. Verify with a test app under `docker/test_apps/`.
|
|
266
|
+
|
|
267
|
+
### Updating protos
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
git submodule update --init --recursive
|
|
271
|
+
./scripts/build_proto.sh
|
|
272
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = [
|
|
3
|
+
"setuptools>=42",
|
|
4
|
+
"wheel",
|
|
5
|
+
|
|
6
|
+
]
|
|
7
|
+
build-backend = "setuptools.build_meta"
|
|
8
|
+
|
|
9
|
+
[tool.pytest.ini_options]
|
|
10
|
+
asyncio_mode = "auto"
|
|
11
|
+
testpaths = ["test"]
|
|
12
|
+
|
|
13
|
+
[tool.pylint.messages_control]
|
|
14
|
+
disable = ["trailing-whitespace"]
|
|
15
|
+
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# pylint: skip-file
|
|
2
|
+
import os
|
|
3
|
+
from setuptools import setup, find_packages, Extension
|
|
4
|
+
|
|
5
|
+
exec(open('src/traceableai/version.py').read())
|
|
6
|
+
|
|
7
|
+
with open("README.md", "r", encoding="utf-8") as fh:
|
|
8
|
+
long_description = fh.read()
|
|
9
|
+
|
|
10
|
+
# GenAI OpenTelemetry instrumentors ship in harness-sdk (see otel-python-sdk), not this wheel.
|
|
11
|
+
|
|
12
|
+
_ROOT = os.path.dirname(os.path.abspath(__file__))
|
|
13
|
+
_OTEL_PYTHON_SDK_PATH = os.path.join(_ROOT, 'otel-python-sdk')
|
|
14
|
+
# Do not bake file:// paths into wheels (cibuildwheel uses /project/... at build time)
|
|
15
|
+
# or into sdists uploaded to PyPI (Harness sets PYTHON_AGENT_RELEASE_BUILD=1).
|
|
16
|
+
_USE_LOCAL_SDK_FOR_INSTALL = (
|
|
17
|
+
os.path.isdir(_OTEL_PYTHON_SDK_PATH)
|
|
18
|
+
and os.environ.get('CIBUILDWHEEL', '0') != '1'
|
|
19
|
+
and os.environ.get('PYTHON_AGENT_RELEASE_BUILD', '0') != '1'
|
|
20
|
+
)
|
|
21
|
+
_HARNESS_SDK_DEP = (
|
|
22
|
+
f"harness-sdk @ file://{os.path.abspath(_OTEL_PYTHON_SDK_PATH)}"
|
|
23
|
+
if _USE_LOCAL_SDK_FOR_INSTALL
|
|
24
|
+
else "harness-sdk>=0.1.0"
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
setup(
|
|
28
|
+
name="traceable-agent",
|
|
29
|
+
version=__version__,
|
|
30
|
+
author="Traceable.ai",
|
|
31
|
+
description="Traceable.ai Python Agent",
|
|
32
|
+
url="https://traceable.ai",
|
|
33
|
+
classifiers=[
|
|
34
|
+
"Programming Language :: Python :: 3",
|
|
35
|
+
"Operating System :: OS Independent"
|
|
36
|
+
],
|
|
37
|
+
package_dir={"": "src"},
|
|
38
|
+
packages=find_packages(where="src", include=["traceableai*"]),
|
|
39
|
+
include_package_data=True,
|
|
40
|
+
python_requires=">=3.10",
|
|
41
|
+
ext_modules=[
|
|
42
|
+
# this option will let wheel builder know to package c extensions when ran from CI. No effect for source tar installs
|
|
43
|
+
Extension(
|
|
44
|
+
name='traceableai.filter._libtraceable',
|
|
45
|
+
sources=[],
|
|
46
|
+
optional=os.environ.get('CIBUILDWHEEL', '0') != '1'
|
|
47
|
+
)
|
|
48
|
+
],
|
|
49
|
+
install_requires=[
|
|
50
|
+
_HARNESS_SDK_DEP,
|
|
51
|
+
"opentelemetry-api==1.41.1",
|
|
52
|
+
"opentelemetry-exporter-otlp==1.41.1",
|
|
53
|
+
"opentelemetry-instrumentation==0.62b1",
|
|
54
|
+
"opentelemetry-instrumentation-aiohttp-client==0.62b1",
|
|
55
|
+
"opentelemetry-instrumentation-botocore==0.62b1",
|
|
56
|
+
"opentelemetry-instrumentation-wsgi==0.62b1",
|
|
57
|
+
"opentelemetry-instrumentation-fastapi==0.62b1",
|
|
58
|
+
"opentelemetry-instrumentation-flask==0.62b1",
|
|
59
|
+
"opentelemetry-instrumentation-mysql==0.62b1",
|
|
60
|
+
"opentelemetry-instrumentation-psycopg2==0.62b1",
|
|
61
|
+
"opentelemetry-instrumentation-requests==0.62b1",
|
|
62
|
+
"opentelemetry-instrumentation-httpx==0.62b1",
|
|
63
|
+
"opentelemetry-instrumentation-grpc==0.62b1",
|
|
64
|
+
"opentelemetry-instrumentation-django==0.62b1",
|
|
65
|
+
"opentelemetry-instrumentation-mcp==0.60.0",
|
|
66
|
+
"opentelemetry-semantic-conventions-ai>=0.5.1,<0.6.0",
|
|
67
|
+
"opentelemetry-propagator-b3==1.41.1",
|
|
68
|
+
"opentelemetry-proto==1.41.1",
|
|
69
|
+
"opentelemetry-sdk==1.41.1",
|
|
70
|
+
"opentelemetry-util-http==0.62b1",
|
|
71
|
+
"google>=3.0.0",
|
|
72
|
+
"pyyaml",
|
|
73
|
+
"protobuf",
|
|
74
|
+
"psutil",
|
|
75
|
+
"distro",
|
|
76
|
+
"cffi",
|
|
77
|
+
"setuptools",
|
|
78
|
+
"jaraco.text",
|
|
79
|
+
"platformdirs"
|
|
80
|
+
],
|
|
81
|
+
entry_points={
|
|
82
|
+
'console_scripts': [
|
|
83
|
+
'traceableai-instrument = traceableai.autoinstrumentation.wrapper:run',
|
|
84
|
+
'harness-instrument = harness_sdk.autoinstrumentation.wrapper:run',
|
|
85
|
+
],
|
|
86
|
+
'harness_sdk_control_plugin': [
|
|
87
|
+
'traceable = traceableai.plugins.traceable_control:factory',
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
extras_require={
|
|
91
|
+
'anthropic': [
|
|
92
|
+
'anthropic>=0.34.0',
|
|
93
|
+
],
|
|
94
|
+
'openai': [
|
|
95
|
+
'openai>=1.40.0',
|
|
96
|
+
],
|
|
97
|
+
'litellm': [
|
|
98
|
+
'litellm>=1.60.0',
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
)
|