traceable-agent 2.1.0b1__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.
Files changed (107) hide show
  1. traceable_agent-2.3.1/PKG-INFO +326 -0
  2. traceable_agent-2.3.1/README.md +272 -0
  3. {traceable_agent-2.1.0b1 → traceable_agent-2.3.1}/setup.py +20 -32
  4. traceable_agent-2.3.1/src/traceable_agent.egg-info/PKG-INFO +326 -0
  5. traceable_agent-2.3.1/src/traceable_agent.egg-info/SOURCES.txt +28 -0
  6. traceable_agent-2.3.1/src/traceable_agent.egg-info/entry_points.txt +6 -0
  7. {traceable_agent-2.1.0b1 → traceable_agent-2.3.1}/src/traceable_agent.egg-info/requires.txt +1 -1
  8. traceable_agent-2.3.1/src/traceable_agent.egg-info/top_level.txt +1 -0
  9. traceable_agent-2.3.1/src/traceableai/__init__.py +14 -0
  10. traceable_agent-2.3.1/src/traceableai/agent.py +92 -0
  11. traceable_agent-2.3.1/src/traceableai/autoinstrumentation/sitecustomize.py +34 -0
  12. {traceable_agent-2.1.0b1 → traceable_agent-2.3.1}/src/traceableai/autoinstrumentation/wrapper.py +25 -29
  13. traceable_agent-2.3.1/src/traceableai/config/__init__.py +1 -0
  14. traceable_agent-2.3.1/src/traceableai/config/config.py +73 -0
  15. traceable_agent-2.3.1/src/traceableai/config/default.py +38 -0
  16. traceable_agent-2.3.1/src/traceableai/config/environment.py +77 -0
  17. {traceable_agent-2.1.0b1 → traceable_agent-2.3.1}/src/traceableai/custom_logger.py +1 -1
  18. {traceable_agent-2.1.0b1 → traceable_agent-2.3.1}/src/traceableai/filter/libtraceable_common.py +29 -4
  19. {traceable_agent-2.1.0b1 → traceable_agent-2.3.1}/src/traceableai/filter/traceable.py +258 -84
  20. traceable_agent-2.3.1/src/traceableai/plugins/__init__.py +1 -0
  21. traceable_agent-2.3.1/src/traceableai/plugins/traceable_control.py +112 -0
  22. {traceable_agent-2.1.0b1 → traceable_agent-2.3.1}/src/traceableai/version.py +1 -1
  23. traceable_agent-2.3.1/src/traceableai/version_format.py +26 -0
  24. traceable_agent-2.1.0b1/PKG-INFO +0 -136
  25. traceable_agent-2.1.0b1/README.md +0 -82
  26. traceable_agent-2.1.0b1/src/opentelemetry/instrumentation/anthropic/__init__.py +0 -119
  27. traceable_agent-2.1.0b1/src/opentelemetry/instrumentation/anthropic/messages_extractors.py +0 -251
  28. traceable_agent-2.1.0b1/src/opentelemetry/instrumentation/anthropic/package.py +0 -15
  29. traceable_agent-2.1.0b1/src/opentelemetry/instrumentation/anthropic/patch.py +0 -131
  30. traceable_agent-2.1.0b1/src/opentelemetry/instrumentation/anthropic/utils.py +0 -243
  31. traceable_agent-2.1.0b1/src/opentelemetry/instrumentation/anthropic/version.py +0 -15
  32. traceable_agent-2.1.0b1/src/opentelemetry/instrumentation/anthropic/wrappers.py +0 -435
  33. traceable_agent-2.1.0b1/src/opentelemetry/instrumentation/openai_v2/__init__.py +0 -168
  34. traceable_agent-2.1.0b1/src/opentelemetry/instrumentation/openai_v2/instruments.py +0 -52
  35. traceable_agent-2.1.0b1/src/opentelemetry/instrumentation/openai_v2/package.py +0 -18
  36. traceable_agent-2.1.0b1/src/opentelemetry/instrumentation/openai_v2/patch.py +0 -952
  37. traceable_agent-2.1.0b1/src/opentelemetry/instrumentation/openai_v2/response_extractors.py +0 -419
  38. traceable_agent-2.1.0b1/src/opentelemetry/instrumentation/openai_v2/response_wrappers.py +0 -467
  39. traceable_agent-2.1.0b1/src/opentelemetry/instrumentation/openai_v2/utils.py +0 -502
  40. traceable_agent-2.1.0b1/src/opentelemetry/instrumentation/openai_v2/version.py +0 -15
  41. traceable_agent-2.1.0b1/src/opentelemetry/util/genai/__init__.py +0 -13
  42. traceable_agent-2.1.0b1/src/opentelemetry/util/genai/_embedding_invocation.py +0 -123
  43. traceable_agent-2.1.0b1/src/opentelemetry/util/genai/_inference_invocation.py +0 -358
  44. traceable_agent-2.1.0b1/src/opentelemetry/util/genai/_invocation.py +0 -140
  45. traceable_agent-2.1.0b1/src/opentelemetry/util/genai/_tool_invocation.py +0 -96
  46. traceable_agent-2.1.0b1/src/opentelemetry/util/genai/_upload/__init__.py +0 -90
  47. traceable_agent-2.1.0b1/src/opentelemetry/util/genai/_upload/completion_hook.py +0 -404
  48. traceable_agent-2.1.0b1/src/opentelemetry/util/genai/_workflow_invocation.py +0 -115
  49. traceable_agent-2.1.0b1/src/opentelemetry/util/genai/completion_hook.py +0 -126
  50. traceable_agent-2.1.0b1/src/opentelemetry/util/genai/environment_variables.py +0 -71
  51. traceable_agent-2.1.0b1/src/opentelemetry/util/genai/handler.py +0 -335
  52. traceable_agent-2.1.0b1/src/opentelemetry/util/genai/instruments.py +0 -54
  53. traceable_agent-2.1.0b1/src/opentelemetry/util/genai/invocation.py +0 -47
  54. traceable_agent-2.1.0b1/src/opentelemetry/util/genai/metrics.py +0 -54
  55. traceable_agent-2.1.0b1/src/opentelemetry/util/genai/types.py +0 -255
  56. traceable_agent-2.1.0b1/src/opentelemetry/util/genai/utils.py +0 -143
  57. traceable_agent-2.1.0b1/src/opentelemetry/util/genai/version.py +0 -15
  58. traceable_agent-2.1.0b1/src/traceable_agent.egg-info/PKG-INFO +0 -136
  59. traceable_agent-2.1.0b1/src/traceable_agent.egg-info/SOURCES.txt +0 -90
  60. traceable_agent-2.1.0b1/src/traceable_agent.egg-info/entry_points.txt +0 -2
  61. traceable_agent-2.1.0b1/src/traceable_agent.egg-info/top_level.txt +0 -2
  62. traceable_agent-2.1.0b1/src/traceableai/__init__.py +0 -7
  63. traceable_agent-2.1.0b1/src/traceableai/agent.py +0 -211
  64. traceable_agent-2.1.0b1/src/traceableai/agent_init.py +0 -222
  65. traceable_agent-2.1.0b1/src/traceableai/autoinstrumentation/sitecustomize.py +0 -37
  66. traceable_agent-2.1.0b1/src/traceableai/config/__init__.py +0 -0
  67. traceable_agent-2.1.0b1/src/traceableai/config/config.py +0 -94
  68. traceable_agent-2.1.0b1/src/traceableai/config/config_pb2.py +0 -112
  69. traceable_agent-2.1.0b1/src/traceableai/config/default.py +0 -77
  70. traceable_agent-2.1.0b1/src/traceableai/config/environment.py +0 -225
  71. traceable_agent-2.1.0b1/src/traceableai/constants.py +0 -9
  72. traceable_agent-2.1.0b1/src/traceableai/env.py +0 -7
  73. traceable_agent-2.1.0b1/src/traceableai/excluded_by_attribute_span_processor.py +0 -40
  74. traceable_agent-2.1.0b1/src/traceableai/filter/registry.py +0 -51
  75. traceable_agent-2.1.0b1/src/traceableai/gen_ai/__init__.py +0 -7
  76. traceable_agent-2.1.0b1/src/traceableai/gen_ai/exceptions.py +0 -17
  77. traceable_agent-2.1.0b1/src/traceableai/instrumentation/__init__.py +0 -222
  78. traceable_agent-2.1.0b1/src/traceableai/instrumentation/aiohttp/__init__.py +0 -218
  79. traceable_agent-2.1.0b1/src/traceableai/instrumentation/anthropic/__init__.py +0 -379
  80. traceable_agent-2.1.0b1/src/traceableai/instrumentation/aws_lambda/__init__.py +0 -200
  81. traceable_agent-2.1.0b1/src/traceableai/instrumentation/botocore/__init__.py +0 -11
  82. traceable_agent-2.1.0b1/src/traceableai/instrumentation/django/__init__.py +0 -77
  83. traceable_agent-2.1.0b1/src/traceableai/instrumentation/django/django_auto_instrumentation_compat.py +0 -70
  84. traceable_agent-2.1.0b1/src/traceableai/instrumentation/fast_api/__init__.py +0 -215
  85. traceable_agent-2.1.0b1/src/traceableai/instrumentation/fast_api/fast_api_auto_instrumentation_compat.py +0 -65
  86. traceable_agent-2.1.0b1/src/traceableai/instrumentation/flask/__init__.py +0 -187
  87. traceable_agent-2.1.0b1/src/traceableai/instrumentation/genai_env.py +0 -71
  88. traceable_agent-2.1.0b1/src/traceableai/instrumentation/grpc/__init__.py +0 -266
  89. traceable_agent-2.1.0b1/src/traceableai/instrumentation/httpx/__init__.py +0 -73
  90. traceable_agent-2.1.0b1/src/traceableai/instrumentation/httpx/utils.py +0 -160
  91. traceable_agent-2.1.0b1/src/traceableai/instrumentation/instrumentation_definitions.py +0 -171
  92. traceable_agent-2.1.0b1/src/traceableai/instrumentation/litellm/__init__.py +0 -401
  93. traceable_agent-2.1.0b1/src/traceableai/instrumentation/mcp/__init__.py +0 -40
  94. traceable_agent-2.1.0b1/src/traceableai/instrumentation/mcp/gen_ai_mirror.py +0 -204
  95. traceable_agent-2.1.0b1/src/traceableai/instrumentation/mysql/__init__.py +0 -11
  96. traceable_agent-2.1.0b1/src/traceableai/instrumentation/openai/__init__.py +0 -340
  97. traceable_agent-2.1.0b1/src/traceableai/instrumentation/postgresql/__init__.py +0 -13
  98. traceable_agent-2.1.0b1/src/traceableai/instrumentation/requests/__init__.py +0 -40
  99. traceable_agent-2.1.0b1/src/traceableai/otlp_reporting.py +0 -75
  100. traceable_agent-2.1.0b1/src/traceableai/sampling_span_processor.py +0 -63
  101. traceable_agent-2.1.0b1/src/traceableai/span_attributes_processor.py +0 -19
  102. {traceable_agent-2.1.0b1 → traceable_agent-2.3.1}/MANIFEST.in +0 -0
  103. {traceable_agent-2.1.0b1 → traceable_agent-2.3.1}/pyproject.toml +0 -0
  104. {traceable_agent-2.1.0b1 → traceable_agent-2.3.1}/setup.cfg +0 -0
  105. {traceable_agent-2.1.0b1 → traceable_agent-2.3.1}/src/traceable_agent.egg-info/dependency_links.txt +0 -0
  106. {traceable_agent-2.1.0b1 → traceable_agent-2.3.1}/src/traceableai/autoinstrumentation/__init__.py +0 -0
  107. {traceable_agent-2.1.0b1 → traceable_agent-2.3.1}/src/traceableai/filter/__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
+ ```
@@ -7,35 +7,22 @@ exec(open('src/traceableai/version.py').read())
7
7
  with open("README.md", "r", encoding="utf-8") as fh:
8
8
  long_description = fh.read()
9
9
 
10
- # Bundle pre-release vendor packages that aren't yet on PyPI.
11
- # These are fetched by scripts/fetch-vendor.sh before building.
12
- # We copy them under src/ and list them explicitly (they're namespace packages
13
- # so find_packages() won't discover them automatically).
14
- # Once they're published to PyPI, remove this block and add them
15
- # as versioned dependencies in extras_require['anthropic'] instead.
16
- import shutil
10
+ # GenAI OpenTelemetry instrumentors ship in harness-sdk (see otel-python-sdk), not this wheel.
17
11
 
18
12
  _ROOT = os.path.dirname(os.path.abspath(__file__))
19
-
20
- _VENDOR_SRC = [
21
- os.path.join(_ROOT, 'temporary-vendor', 'opentelemetry-instrumentation-anthropic', 'src', 'opentelemetry'),
22
- os.path.join(_ROOT, 'temporary-vendor', 'opentelemetry-instrumentation-openai-v2', 'src', 'opentelemetry'),
23
- os.path.join(_ROOT, 'temporary-vendor', 'opentelemetry-util-genai', 'src', 'opentelemetry'),
24
- ]
25
- _VENDOR_DST = os.path.join(_ROOT, 'src', 'opentelemetry')
26
-
27
- for _src in _VENDOR_SRC:
28
- if os.path.isdir(_src):
29
- shutil.copytree(_src, _VENDOR_DST, dirs_exist_ok=True)
30
-
31
- # Collect all sub-packages with __init__.py from the merged destination
32
- # (namespace package roots like opentelemetry/ have no __init__.py and are excluded)
33
- _VENDOR_PACKAGES = []
34
- if os.path.isdir(_VENDOR_DST):
35
- for _dirpath, _dirnames, _filenames in os.walk(_VENDOR_DST):
36
- if '__init__.py' in _filenames:
37
- _rel = os.path.relpath(_dirpath, os.path.join(_ROOT, 'src'))
38
- _VENDOR_PACKAGES.append(_rel.replace(os.sep, '.'))
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
+ )
39
26
 
40
27
  setup(
41
28
  name="traceable-agent",
@@ -48,7 +35,7 @@ setup(
48
35
  "Operating System :: OS Independent"
49
36
  ],
50
37
  package_dir={"": "src"},
51
- packages=find_packages(where="src") + _VENDOR_PACKAGES,
38
+ packages=find_packages(where="src", include=["traceableai*"]),
52
39
  include_package_data=True,
53
40
  python_requires=">=3.10",
54
41
  ext_modules=[
@@ -60,6 +47,7 @@ setup(
60
47
  )
61
48
  ],
62
49
  install_requires=[
50
+ _HARNESS_SDK_DEP,
63
51
  "opentelemetry-api==1.41.1",
64
52
  "opentelemetry-exporter-otlp==1.41.1",
65
53
  "opentelemetry-instrumentation==0.62b1",
@@ -74,7 +62,6 @@ setup(
74
62
  "opentelemetry-instrumentation-httpx==0.62b1",
75
63
  "opentelemetry-instrumentation-grpc==0.62b1",
76
64
  "opentelemetry-instrumentation-django==0.62b1",
77
- "opentelemetry-instrumentation-aws-lambda==0.62b1",
78
65
  "opentelemetry-instrumentation-mcp==0.60.0",
79
66
  "opentelemetry-semantic-conventions-ai>=0.5.1,<0.6.0",
80
67
  "opentelemetry-propagator-b3==1.41.1",
@@ -94,14 +81,15 @@ setup(
94
81
  entry_points={
95
82
  'console_scripts': [
96
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',
97
88
  ],
98
89
  },
99
90
  extras_require={
100
91
  'anthropic': [
101
92
  'anthropic>=0.34.0',
102
- # opentelemetry-util-genai and opentelemetry-instrumentation-anthropic
103
- # are bundled directly (not yet on PyPI). When they are published,
104
- # add them here as versioned deps and remove the bundle logic above.
105
93
  ],
106
94
  'openai': [
107
95
  'openai>=1.40.0',