struct-sdk 0.5.25__tar.gz → 0.5.27__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 (52) hide show
  1. struct_sdk-0.5.27/PKG-INFO +171 -0
  2. struct_sdk-0.5.27/PYPI.md +54 -0
  3. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/README.md +58 -23
  4. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/pyproject.toml +19 -6
  5. struct_sdk-0.5.27/src/struct_sdk/_fork_safe_http.py +198 -0
  6. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/_genai_content.py +62 -0
  7. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/_observations/config.py +147 -255
  8. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/_observations/health.py +155 -88
  9. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/_observations/identity.py +2 -0
  10. struct_sdk-0.5.27/src/struct_sdk/_observations/native_events.py +557 -0
  11. struct_sdk-0.5.27/src/struct_sdk/_observations/outputs.py +68 -0
  12. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/_observations/poller.py +85 -6
  13. struct_sdk-0.5.27/src/struct_sdk/_observations/routing.py +110 -0
  14. struct_sdk-0.5.27/src/struct_sdk/_observations/runtime.py +1424 -0
  15. struct_sdk-0.5.27/src/struct_sdk/_observations/self_metrics.py +143 -0
  16. struct_sdk-0.5.27/src/struct_sdk/_observations/uwsgi.py +135 -0
  17. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/anthropic.py +54 -48
  18. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/core.py +345 -48
  19. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/google_genai.py +2 -7
  20. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/langchain.py +3 -13
  21. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/litellm.py +2 -7
  22. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/llamaindex.py +4 -10
  23. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/mcp.py +3 -3
  24. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/openai.py +242 -55
  25. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/pydantic_ai.py +60 -19
  26. struct_sdk-0.5.25/PKG-INFO +0 -1069
  27. struct_sdk-0.5.25/src/struct_sdk/_fork_safe_http.py +0 -71
  28. struct_sdk-0.5.25/src/struct_sdk/_observations/export.py +0 -921
  29. struct_sdk-0.5.25/src/struct_sdk/_observations/otlp_sender.py +0 -230
  30. struct_sdk-0.5.25/src/struct_sdk/_observations/outputs.py +0 -825
  31. struct_sdk-0.5.25/src/struct_sdk/_observations/providers.py +0 -81
  32. struct_sdk-0.5.25/src/struct_sdk/_observations/runtime.py +0 -640
  33. struct_sdk-0.5.25/src/struct_sdk/_observations/self_metrics.py +0 -79
  34. struct_sdk-0.5.25/src/struct_sdk/_observations/snapshot.py +0 -671
  35. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/.gitignore +0 -0
  36. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/LICENSE +0 -0
  37. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/__init__.py +0 -0
  38. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/_auto.py +0 -0
  39. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/_container.py +0 -0
  40. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/_distro.py +0 -0
  41. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/_event_loop.py +0 -0
  42. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/_metrics.py +0 -0
  43. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/_observations/__init__.py +0 -0
  44. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/_operation_details.py +0 -0
  45. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/_pool.py +0 -0
  46. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/ag2.py +0 -0
  47. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/autogen.py +0 -0
  48. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/claude_agent.py +0 -0
  49. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/crewai.py +0 -0
  50. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/gcp.py +0 -0
  51. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/openai_agents.py +0 -0
  52. {struct_sdk-0.5.25 → struct_sdk-0.5.27}/src/struct_sdk/temporal.py +0 -0
@@ -0,0 +1,171 @@
1
+ Metadata-Version: 2.5
2
+ Name: struct-sdk
3
+ Version: 0.5.27
4
+ Summary: Python SDK for OTel auto-instrumentation and live instrumentation on Struct.
5
+ Project-URL: Homepage, https://struct.ai
6
+ Project-URL: Documentation, https://docs.struct.ai/observability/instrumentation/python
7
+ Project-URL: Issues, https://struct.ai/support
8
+ Author-email: Struct <support@struct.ai>
9
+ License: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: agent,ai,anthropic,langchain,observability,openai,opentelemetry,struct,tracing
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Topic :: System :: Monitoring
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: opentelemetry-api>=1.45.1
25
+ Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.27.0
26
+ Requires-Dist: opentelemetry-sdk>=1.27.0
27
+ Requires-Dist: struct-sdk-native==0.2.0
28
+ Requires-Dist: wrapt>=1.16.0
29
+ Provides-Extra: anthropic
30
+ Requires-Dist: anthropic>=0.30.0; extra == 'anthropic'
31
+ Provides-Extra: auto
32
+ Requires-Dist: opentelemetry-instrumentation-aio-pika; extra == 'auto'
33
+ Requires-Dist: opentelemetry-instrumentation-aiohttp-client; extra == 'auto'
34
+ Requires-Dist: opentelemetry-instrumentation-aiohttp-server; extra == 'auto'
35
+ Requires-Dist: opentelemetry-instrumentation-aiokafka; extra == 'auto'
36
+ Requires-Dist: opentelemetry-instrumentation-aiopg; extra == 'auto'
37
+ Requires-Dist: opentelemetry-instrumentation-asyncpg; extra == 'auto'
38
+ Requires-Dist: opentelemetry-instrumentation-botocore; extra == 'auto'
39
+ Requires-Dist: opentelemetry-instrumentation-cassandra; extra == 'auto'
40
+ Requires-Dist: opentelemetry-instrumentation-celery; extra == 'auto'
41
+ Requires-Dist: opentelemetry-instrumentation-confluent-kafka; extra == 'auto'
42
+ Requires-Dist: opentelemetry-instrumentation-django; extra == 'auto'
43
+ Requires-Dist: opentelemetry-instrumentation-falcon; extra == 'auto'
44
+ Requires-Dist: opentelemetry-instrumentation-fastapi; extra == 'auto'
45
+ Requires-Dist: opentelemetry-instrumentation-flask; extra == 'auto'
46
+ Requires-Dist: opentelemetry-instrumentation-grpc; extra == 'auto'
47
+ Requires-Dist: opentelemetry-instrumentation-httpx; extra == 'auto'
48
+ Requires-Dist: opentelemetry-instrumentation-jinja2; extra == 'auto'
49
+ Requires-Dist: opentelemetry-instrumentation-kafka-python; extra == 'auto'
50
+ Requires-Dist: opentelemetry-instrumentation-logging; extra == 'auto'
51
+ Requires-Dist: opentelemetry-instrumentation-mysql; extra == 'auto'
52
+ Requires-Dist: opentelemetry-instrumentation-mysqlclient; extra == 'auto'
53
+ Requires-Dist: opentelemetry-instrumentation-pika; extra == 'auto'
54
+ Requires-Dist: opentelemetry-instrumentation-psycopg; extra == 'auto'
55
+ Requires-Dist: opentelemetry-instrumentation-psycopg2; extra == 'auto'
56
+ Requires-Dist: opentelemetry-instrumentation-pymemcache; extra == 'auto'
57
+ Requires-Dist: opentelemetry-instrumentation-pymongo; extra == 'auto'
58
+ Requires-Dist: opentelemetry-instrumentation-pymssql; extra == 'auto'
59
+ Requires-Dist: opentelemetry-instrumentation-pymysql; extra == 'auto'
60
+ Requires-Dist: opentelemetry-instrumentation-pyramid; extra == 'auto'
61
+ Requires-Dist: opentelemetry-instrumentation-redis; extra == 'auto'
62
+ Requires-Dist: opentelemetry-instrumentation-requests; extra == 'auto'
63
+ Requires-Dist: opentelemetry-instrumentation-sqlalchemy; extra == 'auto'
64
+ Requires-Dist: opentelemetry-instrumentation-sqlite3; extra == 'auto'
65
+ Requires-Dist: opentelemetry-instrumentation-starlette; extra == 'auto'
66
+ Requires-Dist: opentelemetry-instrumentation-system-metrics; extra == 'auto'
67
+ Requires-Dist: opentelemetry-instrumentation-threading; extra == 'auto'
68
+ Requires-Dist: opentelemetry-instrumentation-tornado; extra == 'auto'
69
+ Requires-Dist: opentelemetry-instrumentation-tortoiseorm; extra == 'auto'
70
+ Requires-Dist: opentelemetry-instrumentation-urllib; extra == 'auto'
71
+ Requires-Dist: opentelemetry-instrumentation-urllib3; extra == 'auto'
72
+ Requires-Dist: opentelemetry-instrumentation>=0.51b0; extra == 'auto'
73
+ Requires-Dist: opentelemetry-resource-detector-containerid; extra == 'auto'
74
+ Provides-Extra: autogen
75
+ Requires-Dist: autogen-agentchat>=0.7.0; extra == 'autogen'
76
+ Requires-Dist: autogen-ext[openai]>=0.7.0; extra == 'autogen'
77
+ Provides-Extra: azure
78
+ Requires-Dist: azure-core-tracing-opentelemetry>=1.0.0b11; extra == 'azure'
79
+ Provides-Extra: claude-agent-sdk
80
+ Requires-Dist: claude-agent-sdk>=0.2.121; extra == 'claude-agent-sdk'
81
+ Requires-Dist: mcp<2,>=1.30.0; extra == 'claude-agent-sdk'
82
+ Provides-Extra: demo
83
+ Requires-Dist: langchain-anthropic>=1.4.6; extra == 'demo'
84
+ Requires-Dist: langchain-core>=1.3.3; extra == 'demo'
85
+ Requires-Dist: langchain-openai>=0.2.0; extra == 'demo'
86
+ Requires-Dist: langchain>=1.3.9; extra == 'demo'
87
+ Requires-Dist: langgraph>=0.2.0; extra == 'demo'
88
+ Requires-Dist: python-dotenv>=1.0.0; extra == 'demo'
89
+ Provides-Extra: dev
90
+ Requires-Dist: pytest-asyncio>=1.3.0; extra == 'dev'
91
+ Requires-Dist: pytest>=9.0.3; extra == 'dev'
92
+ Requires-Dist: ruff>=0.5; extra == 'dev'
93
+ Requires-Dist: ty==0.0.100; extra == 'dev'
94
+ Provides-Extra: exceptions
95
+ Requires-Dist: opentelemetry-instrumentation-exceptions; extra == 'exceptions'
96
+ Provides-Extra: google-genai
97
+ Requires-Dist: google-genai>=1.12.1; extra == 'google-genai'
98
+ Provides-Extra: langchain
99
+ Requires-Dist: langchain-core>=1.3.3; extra == 'langchain'
100
+ Provides-Extra: litellm
101
+ Requires-Dist: litellm[mcp]>=1.70.0; extra == 'litellm'
102
+ Provides-Extra: llamaindex
103
+ Requires-Dist: llama-index-core>=0.13.0; extra == 'llamaindex'
104
+ Provides-Extra: mcp
105
+ Requires-Dist: mcp>=1.28.1; extra == 'mcp'
106
+ Provides-Extra: openai
107
+ Requires-Dist: openai>=1.66.0; extra == 'openai'
108
+ Provides-Extra: openai-agents
109
+ Requires-Dist: openai-agents>=0.20.0; extra == 'openai-agents'
110
+ Provides-Extra: pydantic-ai
111
+ Requires-Dist: pydantic-ai-slim>=2.53.0; extra == 'pydantic-ai'
112
+ Provides-Extra: structlog
113
+ Requires-Dist: opentelemetry-instrumentation-structlog; extra == 'structlog'
114
+ Provides-Extra: temporal
115
+ Requires-Dist: temporalio>=1.11.0; extra == 'temporal'
116
+ Description-Content-Type: text/markdown
117
+
118
+ # Struct Python SDK
119
+
120
+ Collect logs, metrics, and traces from Python services with OpenTelemetry. Once
121
+ the SDK is running, use Struct Observations to add telemetry without editing
122
+ application code or redeploying.
123
+
124
+ ## Set up a service
125
+
126
+ ```bash
127
+ pip install "struct-sdk[auto]"
128
+ ```
129
+
130
+ Create an ingest key and store it as `STRUCT_INGEST_KEY` in your service's
131
+ environment. Initialize the SDK once at process startup, before importing
132
+ instrumented libraries.
133
+
134
+ ```python
135
+ import os
136
+ from struct_sdk import struct
137
+
138
+ struct.init(
139
+ ingest_key=os.environ["STRUCT_INGEST_KEY"],
140
+ service_name="checkout-api",
141
+ environment="production",
142
+ )
143
+ ```
144
+
145
+ The SDK supports Python 3.10 and later. [Python setup guide](https://docs.struct.ai/observability/instrumentation/python)
146
+
147
+ ## Supported libraries
148
+
149
+ The `auto` extra provides OpenTelemetry instrumentation for installed libraries.
150
+
151
+ | Area | Libraries |
152
+ | --- | --- |
153
+ | Web frameworks | Django, Falcon, FastAPI, Flask, Pyramid, Starlette, Tornado, aiohttp |
154
+ | HTTP and RPC | Requests, HTTPX, aiohttp, urllib, urllib3, gRPC |
155
+ | Databases and caches | psycopg, psycopg2, aiopg, asyncpg, MySQL Connector/Python, PyMySQL, mysqlclient, pymssql, sqlite3, PyMongo, Cassandra, Redis, pymemcache, Tortoise ORM |
156
+ | Messaging and jobs | Celery, pika, aio-pika, aiokafka, confluent-kafka, kafka-python |
157
+ | Cloud and runtime | Boto3/botocore, aiobotocore, Python logging and threading, Jinja2 |
158
+
159
+ SQLAlchemy tracing is opt-in. Additional integrations include structlog, the
160
+ Azure SDK, Google Cloud gRPC clients, and Temporal.
161
+
162
+ Supported AI integrations include Anthropic, OpenAI, Google GenAI, LiteLLM,
163
+ Pydantic AI, LangChain, LangGraph, LlamaIndex, CrewAI, AutoGen, AG2, MCP clients,
164
+ the OpenAI Agents SDK, and the Claude Agent SDK.
165
+
166
+ ## Add telemetry to a running service
167
+
168
+ Publish an Observation through the Struct CLI or ask your coding agent to set
169
+ one up. An Observation tells the running SDK where to capture events, spans,
170
+ or metrics. Live capture requires a supported native runtime on CPython 3.12
171
+ or 3.13 and a key with access to Observation configuration. [Observations guide](https://docs.struct.ai/observability/observations/overview)
@@ -0,0 +1,54 @@
1
+ # Struct Python SDK
2
+
3
+ Collect logs, metrics, and traces from Python services with OpenTelemetry. Once
4
+ the SDK is running, use Struct Observations to add telemetry without editing
5
+ application code or redeploying.
6
+
7
+ ## Set up a service
8
+
9
+ ```bash
10
+ pip install "struct-sdk[auto]"
11
+ ```
12
+
13
+ Create an ingest key and store it as `STRUCT_INGEST_KEY` in your service's
14
+ environment. Initialize the SDK once at process startup, before importing
15
+ instrumented libraries.
16
+
17
+ ```python
18
+ import os
19
+ from struct_sdk import struct
20
+
21
+ struct.init(
22
+ ingest_key=os.environ["STRUCT_INGEST_KEY"],
23
+ service_name="checkout-api",
24
+ environment="production",
25
+ )
26
+ ```
27
+
28
+ The SDK supports Python 3.10 and later. [Python setup guide](https://docs.struct.ai/observability/instrumentation/python)
29
+
30
+ ## Supported libraries
31
+
32
+ The `auto` extra provides OpenTelemetry instrumentation for installed libraries.
33
+
34
+ | Area | Libraries |
35
+ | --- | --- |
36
+ | Web frameworks | Django, Falcon, FastAPI, Flask, Pyramid, Starlette, Tornado, aiohttp |
37
+ | HTTP and RPC | Requests, HTTPX, aiohttp, urllib, urllib3, gRPC |
38
+ | Databases and caches | psycopg, psycopg2, aiopg, asyncpg, MySQL Connector/Python, PyMySQL, mysqlclient, pymssql, sqlite3, PyMongo, Cassandra, Redis, pymemcache, Tortoise ORM |
39
+ | Messaging and jobs | Celery, pika, aio-pika, aiokafka, confluent-kafka, kafka-python |
40
+ | Cloud and runtime | Boto3/botocore, aiobotocore, Python logging and threading, Jinja2 |
41
+
42
+ SQLAlchemy tracing is opt-in. Additional integrations include structlog, the
43
+ Azure SDK, Google Cloud gRPC clients, and Temporal.
44
+
45
+ Supported AI integrations include Anthropic, OpenAI, Google GenAI, LiteLLM,
46
+ Pydantic AI, LangChain, LangGraph, LlamaIndex, CrewAI, AutoGen, AG2, MCP clients,
47
+ the OpenAI Agents SDK, and the Claude Agent SDK.
48
+
49
+ ## Add telemetry to a running service
50
+
51
+ Publish an Observation through the Struct CLI or ask your coding agent to set
52
+ one up. An Observation tells the running SDK where to capture events, spans,
53
+ or metrics. Live capture requires a supported native runtime on CPython 3.12
54
+ or 3.13 and a key with access to Observation configuration. [Observations guide](https://docs.struct.ai/observability/observations/overview)
@@ -1,20 +1,56 @@
1
- # struct-sdk
1
+ # Struct Python SDK
2
2
 
3
- OpenTelemetry instrumentation for AI agents in Python. Captures spans,
4
- token usage, and message content from the Anthropic SDK, the OpenAI SDK
5
- (Responses API), google-genai (Gemini), LiteLLM, pydantic-ai, the OpenAI Agents SDK, MCP clients, the Claude Agent SDK,
6
- LangChain / LangGraph, LlamaIndex, CrewAI, Microsoft AutoGen, and AG2, and exports them to [struct.ai](https://struct.ai) for observability.
7
-
8
- A TypeScript version is available as
9
- [`@struct-ai/sdk`](https://www.npmjs.com/package/@struct-ai/sdk). Both
10
- SDKs produce structurally identical traces, so a single agent system can
11
- mix languages without a fragmented view.
3
+ Collect logs, metrics, and traces from your Python services. Once the SDK is
4
+ running, publish **Observations** to add telemetry without editing application
5
+ code or redeploying. For example, capture the order ID and payment provider
6
+ when checkout fails.
12
7
 
13
8
  ## Install
14
9
 
15
10
  ```bash
16
- pip install struct-sdk
17
- # optional — the SDK auto-instruments these if present
11
+ pip install "struct-sdk[auto]"
12
+ ```
13
+
14
+ The SDK requires Python 3.10 or later. Observations require a supported
15
+ CPython 3.12 or 3.13 build with the native runtime.
16
+
17
+ ## Quickstart
18
+
19
+ Create an ingest key and set it as `STRUCT_INGEST_KEY` in your service's
20
+ environment. Call `struct.init()` once at process startup, before importing
21
+ the libraries you want to instrument.
22
+
23
+ ```python
24
+ import os
25
+ from struct_sdk import struct
26
+
27
+ struct.init(
28
+ ingest_key=os.environ["STRUCT_INGEST_KEY"],
29
+ service_name="checkout-api",
30
+ environment="production",
31
+ )
32
+ ```
33
+
34
+ The setup guide covers ingest keys, automatic instrumentation, and checking
35
+ which signals reached Struct. [Python setup guide](https://docs.struct.ai/observability/instrumentation/python)
36
+
37
+ ## Add telemetry to a running service
38
+
39
+ An Observation specifies which function to watch, when to capture, and which
40
+ values to send as a structured event, span, or metric. Ask your coding agent
41
+ to publish an Observation or use the Struct CLI. After the running SDK picks
42
+ up the configuration, it captures data on subsequent calls to the function.
43
+
44
+ Use a signed ingest key with access to the service and environment to read
45
+ Observation configuration. [Observations guide](https://docs.struct.ai/observability/observations/overview)
46
+
47
+ ## AI agent tracing
48
+
49
+ The SDK also uses OpenTelemetry to trace agent runs, model calls, and tool
50
+ calls, with token usage for supported providers. Install the libraries your
51
+ application uses.
52
+
53
+ ```bash
18
54
  pip install anthropic
19
55
  pip install openai
20
56
  pip install pydantic-ai-slim
@@ -27,13 +63,8 @@ pip install langchain-core langgraph
27
63
  pip install llama-index-core llama-index-llms-openai # or the provider integration you use
28
64
  ```
29
65
 
30
- Requires Python 3.10+.
31
-
32
- ## Quickstart
33
-
34
- Get an ingest key from
35
- [app.struct.ai/settings?tab=ingest-keys](https://app.struct.ai/settings?tab=ingest-keys),
36
- then call `struct.init()` once at startup and wrap your agent loop:
66
+ Use `struct.agent()` and `struct.tool()` to define agent and tool boundaries
67
+ when using an LLM client directly.
37
68
 
38
69
  ```python
39
70
  import os
@@ -62,12 +93,15 @@ async with struct.agent(name="checkout"):
62
93
  result = await search(query="...")
63
94
  ```
64
95
 
96
+ For JavaScript and TypeScript services, see
97
+ [`@struct-ai/sdk`](https://www.npmjs.com/package/@struct-ai/sdk).
98
+
65
99
  ## What gets traced
66
100
 
67
101
  | Library | Span type | Notes |
68
102
  |---|---|---|
69
103
  | `anthropic` | `chat {model}` | Cache-token accounting; streaming chats with tool-use reconstruction. Bedrock and Vertex variants supported if installed. |
70
- | `openai` (Responses and Chat Completions) | `chat {model}` | `responses.create` and `chat.completions.create` on sync and async clients, streaming or not, including the `.stream()` helpers (Azure and OpenAI-compatible clients such as vLLM, Groq, DeepSeek and xAI included). Raw `create(stream=True)` spans end exactly once on exhaustion, `close()`, `with` exit, error, cancellation or garbage collection; every loop over a stream shares one iteration (LiteLLM starts one per chunk), so a `break` ends the span when it releases the stream. Helper streams that exit early end when the helper is released. Chat Completions streamed usage is recorded when you pass `stream_options={"include_usage": True}`; Responses records terminal usage without that option. The SDK never changes your request. Cached-token accounting from the usage details. Message-content capture at parity with the Anthropic integration: in event modes, one `gen_ai.client.inference.operation.details` record per call (one output message per choice; for a stream, written when the stream ends); in span modes, `gen_ai.input.messages` / `gen_ai.output.messages` on the span. Reasoning items are skipped (`encrypted_content` is never emitted). `chat.completions.parse()` and `responses.parse()` calls are not traced. |
104
+ | `openai` (Responses and Chat Completions) | `chat {model}` | `responses.create` and `chat.completions.create` on sync and async clients, streaming or not, including the `.stream()` helpers (Azure and OpenAI-compatible clients such as vLLM, Groq, DeepSeek and xAI included). Raw `create(stream=True)` spans end exactly once on exhaustion, `close()`, `with` exit, error, cancellation or garbage collection; every loop over a stream shares one iteration (LiteLLM starts one per chunk), so a `break` ends the span when it releases the stream. Helper streams that exit early end when the helper is released. Chat Completions streamed usage is recorded when you pass `stream_options={"include_usage": True}`; Responses records terminal usage without that option. The SDK never changes your request. Cached-token accounting from the usage details. Message-content capture at parity with the Anthropic integration: in event modes, one `gen_ai.client.inference.operation.details` record per call (one output message per choice; for a stream, written when the stream ends); in span modes, `gen_ai.input.messages` / `gen_ai.output.messages` on the span. Reasoning items are skipped (`encrypted_content` is never emitted). Non-streaming `chat.completions.parse()` and the older `beta.chat.completions.parse()` entry point are traced on sync and async clients, including Azure. `responses.parse()` is not traced. |
71
105
  | `pydantic_ai` | `invoke_agent {agent}`, `chat {model}`, `execute_tool {tool}` | pydantic-ai's own instrumentation, turned on with the tracer provider Struct's GenAI spans use. See [pydantic-ai](#pydantic-ai). |
72
106
  | `agents` (OpenAI Agents SDK) | `invoke_agent {workflow}`, `invoke_agent {agent}`, `chat {model}`, `execute_tool {tool}` | A `TracingProcessor` added next to the host's: every run, agent, model call (Responses, Chat Completions and LiteLLM models, streamed or not), function tool and handoff. See [OpenAI Agents SDK](#openai-agents-sdk). |
73
107
  | `mcp` (`ClientSession.call_tool`) | `tools/call {tool}` | One CLIENT span per MCP tool call (`gen_ai.operation.name = execute_tool`), with the trace context sent in `params._meta`. See [MCP](#mcp). |
@@ -77,7 +111,7 @@ async with struct.agent(name="checkout"):
77
111
  | `crewai` (1.15.13+) | `invoke_agent`, `chat`, `execute_tool` | Crew kickoffs and agent executions, model calls (native providers or LiteLLM) and tool calls, from CrewAI's event bus. The provider SDK span under a CrewAI model call is suppressed. See [CrewAI](#crewai). |
78
112
  | `autogen_ext` (AutoGen 0.7+) | `chat {model}` | AutoGen traces its own agents and tools; Struct adds a `chat` span for each non-streaming call through the OpenAI-family clients (`OpenAIChatCompletionClient`, Azure, OpenAI-compatible endpoints). In owned full-app mode, Struct also stamps the `struct.agent()` session on AutoGen's spans. AutoGen's Anthropic client is covered by the `anthropic` integration. See [AutoGen](#autogen). |
79
113
  | `autogen` (AG2 0.x) | `chat {model}`, `execute_tool {name}` | Every `OpenAIWrapper.create` model call and `ConversableAgent` tool execution. AG2's own instrumentation, when you turn it on, owns those calls instead. See [AG2](#ag2). |
80
- | `claude_agent_sdk` | `agent`, `chat`, `execute_tool` | Telemetry comes from Claude Code itself in the subprocess; ingest credentials are propagated to it via `ClaudeAgentOptions`. Subagents inherit the configuration. |
114
+ | `claude_agent_sdk` | Claude Code's own `claude_code.*` spans | Telemetry comes from Claude Code itself in the subprocess; ingest credentials are propagated to it via `ClaudeAgentOptions`. Subagents inherit the configuration. Struct stores these spans, logs and metrics as Claude Code emits them: they keep their `claude_code.*` names and carry no `gen_ai.*` attributes. |
81
115
  | `langchain_core` `BaseChatModel` | `chat {model}` | When the underlying provider SDK is also instrumented (e.g. `ChatAnthropic` + `anthropic`), the provider's span is suppressed, so there is a single span. |
82
116
  | `langchain_core` `BaseTool` | `execute_tool {name}` | `tool_call_id` extracted from the LangChain ToolCall when present. |
83
117
  | `langchain_core` `BaseRetriever` | `retrieval {name}` | |
@@ -113,8 +147,9 @@ struct.init(ingest_key="pk-...", service_name="claude-agent")
113
147
 
114
148
  from claude_agent_sdk import ClaudeAgentOptions, query
115
149
  # Telemetry is generated by Claude Code itself in the subprocess and
116
- # exported directly via OTLP. struct.init() configures the ingest
117
- # credentials on ClaudeAgentOptions; subagents inherit them automatically.
150
+ # exported directly via OTLP under Claude Code's own `claude_code.*` names.
151
+ # struct.init() configures the ingest credentials on ClaudeAgentOptions;
152
+ # subagents inherit them automatically.
118
153
  ```
119
154
 
120
155
  #### pydantic-ai
@@ -4,9 +4,9 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "struct-sdk"
7
- version = "0.5.25"
8
- description = "Struct agent observability SDK — auto-instruments AI agent frameworks with OpenTelemetry"
9
- readme = "README.md"
7
+ version = "0.5.27"
8
+ description = "Python SDK for OTel auto-instrumentation and live instrumentation on Struct."
9
+ readme = "PYPI.md"
10
10
  requires-python = ">=3.10"
11
11
  license = { text = "Apache-2.0" }
12
12
  authors = [{ name = "Struct", email = "support@struct.ai" }]
@@ -33,12 +33,12 @@ dependencies = [
33
33
  "wrapt>=1.16.0",
34
34
  # Native capture runtime. Always installs: platforms without a native build
35
35
  # get its pure py3-none-any wheel, which reports the capability unavailable.
36
- "struct-sdk-native>=0.1.13,<0.2",
36
+ "struct-sdk-native==0.2.0",
37
37
  ]
38
38
 
39
39
  [project.urls]
40
40
  Homepage = "https://struct.ai"
41
- Documentation = "https://struct.ai/docs"
41
+ Documentation = "https://docs.struct.ai/observability/instrumentation/python"
42
42
  Issues = "https://struct.ai/support"
43
43
 
44
44
  [project.entry-points.opentelemetry_distro]
@@ -255,7 +255,19 @@ openai2 = [
255
255
  struct-sdk-native = { path = "../struct-sdk-native", editable = true }
256
256
 
257
257
  [tool.uv]
258
- conflicts = [[{ group = "dev" }, { group = "openai2" }]]
258
+ # The litellm extra needs openai<3 (current litellm releases pin it), like the
259
+ # openai2 group, so it cannot share the dev environment's openai 3. Without this the
260
+ # lock resolves dev + litellm to an old, vulnerable litellm that still
261
+ # accepted openai 3 (CVE-2026-37004, CVE-2026-42208, CVE-2026-49468).
262
+ conflicts = [
263
+ [{ group = "dev" }, { group = "openai2" }],
264
+ [{ group = "dev" }, { extra = "litellm" }],
265
+ ]
266
+ # Lock development environments on Python 3.11+ only; CI runs every suite on
267
+ # 3.12. Published metadata still allows 3.10. Pillow 13, the first release
268
+ # with the fixes for its 2026 CVEs, needs 3.11, so a 3.10 lock entry
269
+ # could only hold vulnerable Pillow 12.
270
+ environments = ["python_full_version >= '3.11'"]
259
271
  override-dependencies = [
260
272
  "cryptography>=50.0.0",
261
273
  "langgraph>=1.2.0,<1.3.0",
@@ -286,6 +298,7 @@ packages = ["src/struct_sdk"]
286
298
  include = [
287
299
  "src/struct_sdk/**/*.py",
288
300
  "README.md",
301
+ "PYPI.md",
289
302
  "LICENSE",
290
303
  "pyproject.toml",
291
304
  ]
@@ -0,0 +1,198 @@
1
+ """HTTP sessions for the SDK's own requests, which a forked child can keep using and exit with.
2
+
3
+ Background threads send through these sessions, and each request holds its connection pool's locks
4
+ for a moment. When the host forks during that moment, the child's copies of those locks stay held
5
+ for good, since the thread that held them doesn't exist there. urllib3 takes them again to close a
6
+ pool, when the pool is collected and at exit, so the child would hang on its way out. The child
7
+ would also inherit the parent's open connections, and its next request could write to a socket
8
+ the parent is still using.
9
+
10
+ So after a fork, the child gives each session a fresh cookie jar and its pools fresh locks, then
11
+ discards the pools, closing the idle connections in them. Only the child's copies of those sockets
12
+ close; that sends nothing, so the parent's connections carry on. A connection a thread was using at
13
+ the fork isn't in a pool, so the child leaves it open and never uses it. The session itself stays
14
+ usable, and the child's next request opens a connection of its own.
15
+
16
+ On macOS, ``requests`` also reads the system proxy settings for every request, through Apple's
17
+ SystemConfiguration framework, which a process forked without exec can't use safely: the call can
18
+ hang or the process be killed. So a forked child there never makes it for the requests that resolve
19
+ their settings through `environment_settings` (the Observations poller, export branch and Rust
20
+ delivery's routing): it gives them what the process resolved for that URL before the fork, or
21
+ failing that the environment's proxy variables alone.
22
+ """
23
+
24
+ from __future__ import annotations
25
+
26
+ import logging
27
+ import os
28
+ import sys
29
+ import threading
30
+ import urllib.request
31
+ import weakref
32
+ from typing import Any, Callable, cast
33
+ from urllib.parse import urlsplit
34
+
35
+ import requests
36
+ import requests.cookies
37
+ import requests.utils
38
+ from requests.sessions import merge_setting
39
+
40
+ logger = logging.getLogger("struct_sdk")
41
+
42
+ # Sessions belong to requests, not to us, so they're tracked here rather than marked.
43
+ _sessions: weakref.WeakSet[requests.Session] = weakref.WeakSet()
44
+
45
+ # The proxies `requests` resolved for each origin (scheme, host, port) the SDK sends to, as of its
46
+ # last request before any fork: what a forked child on macOS reuses. Proxies depend only on the
47
+ # origin, so artifact downloads under one host share an entry; bounded all the same, oldest
48
+ # entry evicted first, and an evicted origin falls back to the proxy variables alone.
49
+ _resolved_proxies: dict[tuple[str, str, int | None], dict[str, str]] = {}
50
+ _MAX_RESOLVED = 64
51
+
52
+
53
+ def _origin(url: str) -> tuple[str, str, int | None]:
54
+ parsed = urlsplit(url)
55
+ return parsed.scheme, (parsed.hostname or ""), parsed.port
56
+
57
+
58
+ # Set in a child after a fork: this process may not use the system proxy settings on macOS.
59
+ _forked = False
60
+
61
+
62
+ def _environment_proxies(url: str) -> dict[str, str]:
63
+ """The proxy variables alone, as ``requests`` reads them, without the system settings.
64
+
65
+ ``requests`` reads ``NO_PROXY`` twice, with different precedence: its own check takes
66
+ ``no_proxy`` unless that is empty, then ``NO_PROXY``; urllib's environment fallback takes
67
+ ``no_proxy`` whenever it is set, so an empty one turns the fallback off."""
68
+ proxies = urllib.request.getproxies_environment()
69
+ environment_no_proxy = proxies.pop("no", None)
70
+ no_proxy = os.environ.get("no_proxy") or os.environ.get("NO_PROXY")
71
+ return {} if _bypassed(url, no_proxy, environment_no_proxy or "") else proxies
72
+
73
+
74
+ # urllib's environment-only matching, which reads no system setting. Typeshed leaves it out.
75
+ _proxy_bypass_environment: Callable[[str, dict[str, str]], bool] = cast(
76
+ Any, urllib.request
77
+ ).proxy_bypass_environment
78
+
79
+
80
+ def _bypassed(
81
+ url: str, no_proxy: str | None, environment_no_proxy: str | None = None
82
+ ) -> bool:
83
+ """Whether ``NO_PROXY`` exempts ``url``, as ``requests`` decides without the system settings
84
+ (``should_bypass_proxies``). First its own matching: an IPv4 host against address and CIDR
85
+ entries only; any other host by plain suffix, with or without its port. Then the environment
86
+ matching urllib applies once proxy variables are set: ``*`` as the whole value bypasses every
87
+ host; otherwise a name matches itself and its subdomains, case-insensitively, a leading dot
88
+ optional.
89
+ ``environment_no_proxy`` is the value that fallback reads (urllib's ``no`` entry); left out,
90
+ it reads ``no_proxy`` too, as when ``requests`` is handed one."""
91
+ parsed = urlsplit(url)
92
+ host = parsed.hostname
93
+ if host is None:
94
+ return True
95
+ if environment_no_proxy is None:
96
+ environment_no_proxy = no_proxy
97
+ if no_proxy and _requests_bypass(parsed, host, no_proxy):
98
+ return True
99
+ if not environment_no_proxy:
100
+ return False
101
+ return bool(_proxy_bypass_environment(host, {"no": environment_no_proxy}))
102
+
103
+
104
+ def _requests_bypass(parsed: Any, host: str, no_proxy: str) -> bool:
105
+ """``requests``' own ``NO_PROXY`` check, before it consults urllib."""
106
+ entries = [entry for entry in no_proxy.replace(" ", "").split(",") if entry]
107
+ if requests.utils.is_ipv4_address(host):
108
+ for entry in entries:
109
+ if requests.utils.is_valid_cidr(entry):
110
+ if requests.utils.address_in_network(host, entry):
111
+ return True
112
+ elif host == entry:
113
+ return True
114
+ else:
115
+ with_port = f"{host}:{parsed.port}" if parsed.port else host
116
+ if any(host.endswith(entry) or with_port.endswith(entry) for entry in entries):
117
+ return True
118
+ return False
119
+
120
+
121
+ def environment_settings(
122
+ session: requests.Session, url: str, stream: Any
123
+ ) -> dict[str, Any]:
124
+ """Proxies and CA bundle from the environment for ``url``, as ``requests`` resolves them for
125
+ ``session`` (``merge_environment_settings``), except in a forked child on macOS, which never
126
+ reads the system proxy settings: it reuses the proxies resolved for ``url`` before the fork, or
127
+ takes the proxy variables alone."""
128
+ if not (_forked and sys.platform == "darwin"):
129
+ settings = session.merge_environment_settings(url, {}, stream, None, None)
130
+ origin = _origin(url)
131
+ _resolved_proxies.pop(origin, None)
132
+ while len(_resolved_proxies) >= _MAX_RESOLVED:
133
+ del _resolved_proxies[next(iter(_resolved_proxies))]
134
+ _resolved_proxies[origin] = dict(settings["proxies"])
135
+ return settings
136
+ known = _resolved_proxies.get(_origin(url))
137
+ proxies = dict(known) if known is not None else _environment_proxies(url)
138
+ verify = (
139
+ os.environ.get("REQUESTS_CA_BUNDLE") or os.environ.get("CURL_CA_BUNDLE") or None
140
+ )
141
+ if not session.trust_env:
142
+ proxies, verify = {}, None
143
+ return {
144
+ "proxies": merge_setting(proxies, session.proxies),
145
+ "stream": merge_setting(stream, session.stream),
146
+ "verify": merge_setting(verify, session.verify),
147
+ "cert": merge_setting(None, session.cert),
148
+ }
149
+
150
+
151
+ def fork_safe_session() -> requests.Session:
152
+ """A new session that a forked child releases cleanly. Every session the SDK owns uses this."""
153
+ session = requests.Session()
154
+ _sessions.add(session)
155
+ return session
156
+
157
+
158
+ def _release(session: requests.Session) -> None:
159
+ """Give a session fresh locks, then discard its pools and close the idle connections in them."""
160
+ try:
161
+ # Every response passes through the cookie jar under its lock. Struct sends no cookies, so a
162
+ # fresh jar loses nothing.
163
+ session.cookies = requests.cookies.RequestsCookieJar()
164
+ for adapter in session.adapters.values():
165
+ managers = [
166
+ getattr(adapter, "poolmanager", None),
167
+ *getattr(adapter, "proxy_manager", {}).values(),
168
+ ]
169
+ for manager in managers:
170
+ pools = getattr(manager, "pools", None)
171
+ if pools is None:
172
+ continue
173
+ pools.lock = threading.RLock()
174
+ for key in pools.keys():
175
+ connections = getattr(pools[key], "pool", None)
176
+ if connections is not None:
177
+ connections.mutex = threading.Lock()
178
+ connections.not_empty = threading.Condition(connections.mutex)
179
+ connections.not_full = threading.Condition(connections.mutex)
180
+ connections.all_tasks_done = threading.Condition(
181
+ connections.mutex
182
+ )
183
+ session.close()
184
+ except Exception: # noqa: BLE001 - this runs inside the host's fork
185
+ logger.debug(
186
+ "Struct SDK could not release an HTTP session after fork", exc_info=True
187
+ )
188
+
189
+
190
+ def _release_after_fork() -> None:
191
+ global _forked
192
+ _forked = True
193
+ for session in list(_sessions):
194
+ _release(session)
195
+
196
+
197
+ if hasattr(os, "register_at_fork"):
198
+ os.register_at_fork(after_in_child=_release_after_fork)