threadify-sdk 0.3.1__tar.gz → 0.4.0__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.
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/CHANGELOG.md +21 -0
- {threadify_sdk-0.3.1/threadify_sdk.egg-info → threadify_sdk-0.4.0}/PKG-INFO +83 -62
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/README.md +82 -60
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/pyproject.toml +1 -2
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/tests/test_connection.py +1 -1
- threadify_sdk-0.4.0/tests/test_otel_correlation.py +273 -0
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/tests/test_parity.py +1 -1
- threadify_sdk-0.4.0/tests/test_thread_key.py +200 -0
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/threadify/__init__.py +3 -5
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/threadify/client.py +0 -10
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/threadify/connection.py +75 -3
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/threadify/models.py +13 -1
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/threadify/otel_exporter.py +203 -46
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/threadify/thread.py +5 -1
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0/threadify_sdk.egg-info}/PKG-INFO +83 -62
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/threadify_sdk.egg-info/SOURCES.txt +2 -2
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/threadify_sdk.egg-info/requires.txt +0 -1
- threadify_sdk-0.3.1/tests/test_management.py +0 -115
- threadify_sdk-0.3.1/threadify/management.py +0 -134
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/LICENSE +0 -0
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/MANIFEST.in +0 -0
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/setup.cfg +0 -0
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/tests/test_client.py +0 -0
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/tests/test_data_retriever.py +0 -0
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/tests/test_models.py +0 -0
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/tests/test_notification.py +0 -0
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/tests/test_step.py +0 -0
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/tests/test_thread.py +0 -0
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/threadify/data_retriever.py +0 -0
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/threadify/notification.py +0 -0
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/threadify/step.py +0 -0
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/threadify/waiting.py +0 -0
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/threadify_sdk.egg-info/dependency_links.txt +0 -0
- {threadify_sdk-0.3.1 → threadify_sdk-0.4.0}/threadify_sdk.egg-info/top_level.txt +0 -0
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.4.0] - 2026-09-23
|
|
4
|
+
|
|
5
|
+
### Breaking changes
|
|
6
|
+
|
|
7
|
+
- Remove `Threadify.entity_profiles`, `EntityProfileManager`, `ManagementAPIError`
|
|
8
|
+
and `profile_slug`. Create profile types and named profiles with `threadify-cli`;
|
|
9
|
+
configure metrics in the Engine UI. Tracing and reference-based profile
|
|
10
|
+
generation are unchanged. Remove the unused PyYAML dependency.
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add `connection.thread(thread_key, label=, contract=, refs=, tags=)` to
|
|
15
|
+
atomically create or resume a thread using a durable application identifier,
|
|
16
|
+
with a new `ThreadOptions` type for the create/resume options.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- Use `threadify.thread_key` throughout the OpenTelemetry exporter and OTLP
|
|
21
|
+
ingestion for trace correlation, replacing the previous external-reference
|
|
22
|
+
correlation attribute.
|
|
23
|
+
|
|
3
24
|
## [0.2.0](https://github.com/creativeJoe007/ThreadifyEngine/compare/threadify-sdk-python-v0.1.0...threadify-sdk-python-v0.2.0) (2026-02-19)
|
|
4
25
|
|
|
5
26
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: threadify-sdk
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Python SDK for Threadify — Service-delivery intelligence. Track every customer request from start to finish across every system, team, and partner. Visit: https://threadify.dev
|
|
5
5
|
Author-email: Threadify Team <team@threadify.dev>
|
|
6
6
|
License: MIT
|
|
@@ -19,7 +19,6 @@ Description-Content-Type: text/markdown
|
|
|
19
19
|
License-File: LICENSE
|
|
20
20
|
Requires-Dist: websockets>=12.0
|
|
21
21
|
Requires-Dist: httpx>=0.27.0
|
|
22
|
-
Requires-Dist: PyYAML>=6.0
|
|
23
22
|
Provides-Extra: otel
|
|
24
23
|
Requires-Dist: opentelemetry-sdk>=1.20; extra == "otel"
|
|
25
24
|
Provides-Extra: dev
|
|
@@ -67,12 +66,13 @@ async def main():
|
|
|
67
66
|
return
|
|
68
67
|
|
|
69
68
|
try:
|
|
70
|
-
thread = await conn.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
thread = await conn.thread("order:ORD-123", {
|
|
70
|
+
"label": "Order ORD-123",
|
|
71
|
+
"contract": "order_processing",
|
|
72
|
+
"role": "customer",
|
|
73
|
+
"refs": {"order_id": "ORD-123"},
|
|
74
|
+
"tags": ["priority"],
|
|
75
|
+
})
|
|
76
76
|
|
|
77
77
|
await thread.add_refs({"crm_id": "CRM-456"})
|
|
78
78
|
|
|
@@ -94,54 +94,30 @@ if __name__ == "__main__":
|
|
|
94
94
|
|
|
95
95
|
For self-hosting, pass `engine_url="https://threadify.example.com"`. WebSocket and GraphQL paths are derived from that base, including reverse-proxy prefixes. Explicit `ws_url` and `graphql_url` remain available for split deployments.
|
|
96
96
|
|
|
97
|
-
## Entity
|
|
98
|
-
|
|
99
|
-
The management client sends a complete desired declaration to Threadify. The
|
|
100
|
-
server performs metric reconciliation by name; SDK callers do not send database
|
|
101
|
-
metric IDs or calculate deletions.
|
|
102
|
-
|
|
103
|
-
```python
|
|
104
|
-
profiles = Threadify.entity_profiles(
|
|
105
|
-
"your-service-api-key",
|
|
106
|
-
web_api_url="https://web.threadify.dev/api",
|
|
107
|
-
)
|
|
108
|
-
|
|
109
|
-
declaration = {
|
|
110
|
-
"name": "Customer",
|
|
111
|
-
"description": "Customer delivery intelligence",
|
|
112
|
-
"type": ["customer_id", "customer_email"],
|
|
113
|
-
"metrics": [
|
|
114
|
-
{
|
|
115
|
-
"name": "Delivery success rate",
|
|
116
|
-
"template_id": "delivery_success_rate",
|
|
117
|
-
"parameters": {"window": "30d"},
|
|
118
|
-
}
|
|
119
|
-
],
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
plan = await profiles.apply(declaration, dry_run=True)
|
|
123
|
-
result = await profiles.apply(declaration)
|
|
124
|
-
await profiles.rename("Customer", "Account") # explicit identity change
|
|
125
|
-
await profiles.close()
|
|
126
|
-
```
|
|
97
|
+
## Entity profiles
|
|
127
98
|
|
|
128
|
-
|
|
99
|
+
Track a customer's activity across workflows by setting up a profile type with
|
|
100
|
+
the [Threadify CLI](https://docs.threadify.dev/cli):
|
|
129
101
|
|
|
130
102
|
```yaml
|
|
131
|
-
#
|
|
132
|
-
name:
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
- customer_id
|
|
136
|
-
- customer_email
|
|
137
|
-
metrics: []
|
|
103
|
+
# customers.yaml
|
|
104
|
+
name: Customers
|
|
105
|
+
type: [customer_id]
|
|
106
|
+
description: Customer workflows
|
|
138
107
|
```
|
|
139
108
|
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
|
|
109
|
+
```sh
|
|
110
|
+
threadify-cli config set api-url https://threadify.example.com
|
|
111
|
+
threadify-cli login
|
|
112
|
+
threadify-cli profile-types create --file customers.yaml
|
|
113
|
+
threadify-cli profiles create --type-id TYPE_ID --ref-value CUST-001 --name 'Jane Doe'
|
|
143
114
|
```
|
|
144
115
|
|
|
116
|
+
Use the returned profile type ID for `TYPE_ID`. Include `customer_id` in your
|
|
117
|
+
thread references to connect each workflow to its customer. Threadify can also
|
|
118
|
+
create profiles as matching activity arrives. Open **Entity Profiles** in the
|
|
119
|
+
dashboard to explore that history and configure metrics.
|
|
120
|
+
|
|
145
121
|
## Configuration
|
|
146
122
|
|
|
147
123
|
### Connect options
|
|
@@ -190,22 +166,46 @@ thread = await conn.join(
|
|
|
190
166
|
)
|
|
191
167
|
```
|
|
192
168
|
|
|
193
|
-
###
|
|
169
|
+
### Create or resume a thread
|
|
194
170
|
|
|
195
|
-
`
|
|
171
|
+
`await connection.thread(thread_key, options=None)` atomically creates or resumes
|
|
172
|
+
an application-owned key within the tenant. Use a session, order, or process ID
|
|
173
|
+
that your application already knows; you do not need to persist Threadify's
|
|
174
|
+
internal `thread_id` between requests.
|
|
196
175
|
|
|
197
176
|
```python
|
|
198
|
-
thread = await conn.
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
refs
|
|
202
|
-
tags
|
|
203
|
-
)
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
thread = await conn.
|
|
177
|
+
thread = await conn.thread("agent-session:123", {
|
|
178
|
+
"label": "Agent session",
|
|
179
|
+
"contract": "agent_contract",
|
|
180
|
+
"refs": {"customer_id": "123"},
|
|
181
|
+
"tags": ["priority"],
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
# A later request or another worker uses the same key without repeating options.
|
|
185
|
+
thread = await conn.thread("agent-session:123")
|
|
186
|
+
await thread.step("tool_call").add_context({"tool": "search"}).success()
|
|
207
187
|
```
|
|
208
188
|
|
|
189
|
+
The optional dictionary accepts `label`, `contract`, `refs`, `tags`,
|
|
190
|
+
`service_name`, and `role`. `ThreadOptions` is exported for type annotations.
|
|
191
|
+
Labels, contracts, service names, and roles must be non-empty strings when
|
|
192
|
+
supplied; refs map non-empty string keys to string values, and tags are a list
|
|
193
|
+
of non-empty strings.
|
|
194
|
+
|
|
195
|
+
Options are creation defaults. Resuming loads the stored label, refs, tags,
|
|
196
|
+
contract name, and pinned contract version into the returned handle. Repeating
|
|
197
|
+
an existing contract is allowed; supplying a conflicting contract fails without
|
|
198
|
+
changing the thread. Use `await thread.add_refs({...})` to change references
|
|
199
|
+
explicitly. Metadata is available as `thread.thread_key`, `thread.label`,
|
|
200
|
+
`thread.contract_name`, `thread.contract_version`, `thread.refs`, and `thread.tags`.
|
|
201
|
+
|
|
202
|
+
Keys are trimmed, case-sensitive strings of at most 1024 UTF-8 bytes. Concurrent
|
|
203
|
+
calls with the same key resolve to one thread. A key-only call on an unknown key
|
|
204
|
+
creates a free-form thread, so initialize contracted sessions before collectors
|
|
205
|
+
or other workers report activity. Closed, completed, and cancelled threads reject
|
|
206
|
+
acquisition and further writes; use a new key for a new process. `join()` remains
|
|
207
|
+
available for internal IDs and invitation tokens.
|
|
208
|
+
|
|
209
209
|
## Subscriptions
|
|
210
210
|
|
|
211
211
|
Preferred API:
|
|
@@ -245,7 +245,15 @@ This SDK follows [Semantic Versioning](https://semver.org/) and [Conventional Co
|
|
|
245
245
|
|
|
246
246
|
## OpenTelemetry Integration
|
|
247
247
|
|
|
248
|
-
The Python SDK includes the OpenTelemetry SpanExporter in the core package.
|
|
248
|
+
The Python SDK includes the OpenTelemetry SpanExporter in the core package. Use
|
|
249
|
+
`BatchSpanProcessor`: synchronous `export()` waits for Engine acknowledgements
|
|
250
|
+
on its worker thread and returns failure if any span fails or the deadline expires.
|
|
251
|
+
It continues attempting unrelated spans in a failed batch and does not complete
|
|
252
|
+
sessions from that batch. Calling synchronous export on the connection event
|
|
253
|
+
loop is rejected to avoid a deadlock. Before closing that loop or the connection,
|
|
254
|
+
run `await asyncio.to_thread(provider.shutdown)` to drain queued spans. Use
|
|
255
|
+
`await asyncio.to_thread(provider.force_flush)` for an explicit flush.
|
|
256
|
+
|
|
249
257
|
|
|
250
258
|
```python
|
|
251
259
|
from opentelemetry import trace
|
|
@@ -267,8 +275,21 @@ exporter = conn.create_span_exporter(options={
|
|
|
267
275
|
provider = TracerProvider()
|
|
268
276
|
provider.add_span_processor(BatchSpanProcessor(exporter))
|
|
269
277
|
trace.set_tracer_provider(provider)
|
|
278
|
+
|
|
279
|
+
# Initialize before exporting spans when this session has a contract.
|
|
280
|
+
await conn.thread("agent-session:123", {"contract": "agent_contract"})
|
|
281
|
+
tracer = trace.get_tracer("agent")
|
|
282
|
+
with tracer.start_as_current_span("tool_call", attributes={
|
|
283
|
+
"threadify.thread_key": "agent-session:123",
|
|
284
|
+
}):
|
|
285
|
+
pass # Perform the instrumented operation.
|
|
270
286
|
```
|
|
271
287
|
|
|
288
|
+
The exporter resolves `threadify.thread_key` using the same create-or-resume
|
|
289
|
+
operation as `connection.thread()`. Omit the contract on later spans; the stored
|
|
290
|
+
contract version is loaded automatically. Shared root spans keep the session open.
|
|
291
|
+
See [OTel correlation](OTEL_CORRELATION.md) for identity precedence and completion.
|
|
292
|
+
|
|
272
293
|
**Filter patterns:**
|
|
273
294
|
|
|
274
295
|
- `"invoke_llm"` — exact match
|
|
@@ -297,7 +318,7 @@ from threadify import Threadify, WaitOptions, ThreadifyError
|
|
|
297
318
|
|
|
298
319
|
connection = await Threadify.connect(api_key, engine_url="https://threadify.example.com", service_name="payments")
|
|
299
320
|
threads = await connection.get_threads_by_ref({"order_id": "ORD-1001"}, status="active", limit=25)
|
|
300
|
-
thread = await connection.
|
|
321
|
+
thread = await connection.thread("order:ORD-1001")
|
|
301
322
|
grant = await thread.wait_for("charge", WaitOptions(timeout=15))
|
|
302
323
|
# Execute the permitted business operation here.
|
|
303
324
|
result = await thread.step("charge").add_context({"amount": 42}).success("charged", wait_for=True, timeout=15)
|
|
@@ -36,12 +36,13 @@ async def main():
|
|
|
36
36
|
return
|
|
37
37
|
|
|
38
38
|
try:
|
|
39
|
-
thread = await conn.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
thread = await conn.thread("order:ORD-123", {
|
|
40
|
+
"label": "Order ORD-123",
|
|
41
|
+
"contract": "order_processing",
|
|
42
|
+
"role": "customer",
|
|
43
|
+
"refs": {"order_id": "ORD-123"},
|
|
44
|
+
"tags": ["priority"],
|
|
45
|
+
})
|
|
45
46
|
|
|
46
47
|
await thread.add_refs({"crm_id": "CRM-456"})
|
|
47
48
|
|
|
@@ -63,54 +64,30 @@ if __name__ == "__main__":
|
|
|
63
64
|
|
|
64
65
|
For self-hosting, pass `engine_url="https://threadify.example.com"`. WebSocket and GraphQL paths are derived from that base, including reverse-proxy prefixes. Explicit `ws_url` and `graphql_url` remain available for split deployments.
|
|
65
66
|
|
|
66
|
-
## Entity
|
|
67
|
-
|
|
68
|
-
The management client sends a complete desired declaration to Threadify. The
|
|
69
|
-
server performs metric reconciliation by name; SDK callers do not send database
|
|
70
|
-
metric IDs or calculate deletions.
|
|
71
|
-
|
|
72
|
-
```python
|
|
73
|
-
profiles = Threadify.entity_profiles(
|
|
74
|
-
"your-service-api-key",
|
|
75
|
-
web_api_url="https://web.threadify.dev/api",
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
declaration = {
|
|
79
|
-
"name": "Customer",
|
|
80
|
-
"description": "Customer delivery intelligence",
|
|
81
|
-
"type": ["customer_id", "customer_email"],
|
|
82
|
-
"metrics": [
|
|
83
|
-
{
|
|
84
|
-
"name": "Delivery success rate",
|
|
85
|
-
"template_id": "delivery_success_rate",
|
|
86
|
-
"parameters": {"window": "30d"},
|
|
87
|
-
}
|
|
88
|
-
],
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
plan = await profiles.apply(declaration, dry_run=True)
|
|
92
|
-
result = await profiles.apply(declaration)
|
|
93
|
-
await profiles.rename("Customer", "Account") # explicit identity change
|
|
94
|
-
await profiles.close()
|
|
95
|
-
```
|
|
67
|
+
## Entity profiles
|
|
96
68
|
|
|
97
|
-
|
|
69
|
+
Track a customer's activity across workflows by setting up a profile type with
|
|
70
|
+
the [Threadify CLI](https://docs.threadify.dev/cli):
|
|
98
71
|
|
|
99
72
|
```yaml
|
|
100
|
-
#
|
|
101
|
-
name:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
- customer_id
|
|
105
|
-
- customer_email
|
|
106
|
-
metrics: []
|
|
73
|
+
# customers.yaml
|
|
74
|
+
name: Customers
|
|
75
|
+
type: [customer_id]
|
|
76
|
+
description: Customer workflows
|
|
107
77
|
```
|
|
108
78
|
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
|
|
79
|
+
```sh
|
|
80
|
+
threadify-cli config set api-url https://threadify.example.com
|
|
81
|
+
threadify-cli login
|
|
82
|
+
threadify-cli profile-types create --file customers.yaml
|
|
83
|
+
threadify-cli profiles create --type-id TYPE_ID --ref-value CUST-001 --name 'Jane Doe'
|
|
112
84
|
```
|
|
113
85
|
|
|
86
|
+
Use the returned profile type ID for `TYPE_ID`. Include `customer_id` in your
|
|
87
|
+
thread references to connect each workflow to its customer. Threadify can also
|
|
88
|
+
create profiles as matching activity arrives. Open **Entity Profiles** in the
|
|
89
|
+
dashboard to explore that history and configure metrics.
|
|
90
|
+
|
|
114
91
|
## Configuration
|
|
115
92
|
|
|
116
93
|
### Connect options
|
|
@@ -159,22 +136,46 @@ thread = await conn.join(
|
|
|
159
136
|
)
|
|
160
137
|
```
|
|
161
138
|
|
|
162
|
-
###
|
|
139
|
+
### Create or resume a thread
|
|
163
140
|
|
|
164
|
-
`
|
|
141
|
+
`await connection.thread(thread_key, options=None)` atomically creates or resumes
|
|
142
|
+
an application-owned key within the tenant. Use a session, order, or process ID
|
|
143
|
+
that your application already knows; you do not need to persist Threadify's
|
|
144
|
+
internal `thread_id` between requests.
|
|
165
145
|
|
|
166
146
|
```python
|
|
167
|
-
thread = await conn.
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
refs
|
|
171
|
-
tags
|
|
172
|
-
)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
thread = await conn.
|
|
147
|
+
thread = await conn.thread("agent-session:123", {
|
|
148
|
+
"label": "Agent session",
|
|
149
|
+
"contract": "agent_contract",
|
|
150
|
+
"refs": {"customer_id": "123"},
|
|
151
|
+
"tags": ["priority"],
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
# A later request or another worker uses the same key without repeating options.
|
|
155
|
+
thread = await conn.thread("agent-session:123")
|
|
156
|
+
await thread.step("tool_call").add_context({"tool": "search"}).success()
|
|
176
157
|
```
|
|
177
158
|
|
|
159
|
+
The optional dictionary accepts `label`, `contract`, `refs`, `tags`,
|
|
160
|
+
`service_name`, and `role`. `ThreadOptions` is exported for type annotations.
|
|
161
|
+
Labels, contracts, service names, and roles must be non-empty strings when
|
|
162
|
+
supplied; refs map non-empty string keys to string values, and tags are a list
|
|
163
|
+
of non-empty strings.
|
|
164
|
+
|
|
165
|
+
Options are creation defaults. Resuming loads the stored label, refs, tags,
|
|
166
|
+
contract name, and pinned contract version into the returned handle. Repeating
|
|
167
|
+
an existing contract is allowed; supplying a conflicting contract fails without
|
|
168
|
+
changing the thread. Use `await thread.add_refs({...})` to change references
|
|
169
|
+
explicitly. Metadata is available as `thread.thread_key`, `thread.label`,
|
|
170
|
+
`thread.contract_name`, `thread.contract_version`, `thread.refs`, and `thread.tags`.
|
|
171
|
+
|
|
172
|
+
Keys are trimmed, case-sensitive strings of at most 1024 UTF-8 bytes. Concurrent
|
|
173
|
+
calls with the same key resolve to one thread. A key-only call on an unknown key
|
|
174
|
+
creates a free-form thread, so initialize contracted sessions before collectors
|
|
175
|
+
or other workers report activity. Closed, completed, and cancelled threads reject
|
|
176
|
+
acquisition and further writes; use a new key for a new process. `join()` remains
|
|
177
|
+
available for internal IDs and invitation tokens.
|
|
178
|
+
|
|
178
179
|
## Subscriptions
|
|
179
180
|
|
|
180
181
|
Preferred API:
|
|
@@ -214,7 +215,15 @@ This SDK follows [Semantic Versioning](https://semver.org/) and [Conventional Co
|
|
|
214
215
|
|
|
215
216
|
## OpenTelemetry Integration
|
|
216
217
|
|
|
217
|
-
The Python SDK includes the OpenTelemetry SpanExporter in the core package.
|
|
218
|
+
The Python SDK includes the OpenTelemetry SpanExporter in the core package. Use
|
|
219
|
+
`BatchSpanProcessor`: synchronous `export()` waits for Engine acknowledgements
|
|
220
|
+
on its worker thread and returns failure if any span fails or the deadline expires.
|
|
221
|
+
It continues attempting unrelated spans in a failed batch and does not complete
|
|
222
|
+
sessions from that batch. Calling synchronous export on the connection event
|
|
223
|
+
loop is rejected to avoid a deadlock. Before closing that loop or the connection,
|
|
224
|
+
run `await asyncio.to_thread(provider.shutdown)` to drain queued spans. Use
|
|
225
|
+
`await asyncio.to_thread(provider.force_flush)` for an explicit flush.
|
|
226
|
+
|
|
218
227
|
|
|
219
228
|
```python
|
|
220
229
|
from opentelemetry import trace
|
|
@@ -236,8 +245,21 @@ exporter = conn.create_span_exporter(options={
|
|
|
236
245
|
provider = TracerProvider()
|
|
237
246
|
provider.add_span_processor(BatchSpanProcessor(exporter))
|
|
238
247
|
trace.set_tracer_provider(provider)
|
|
248
|
+
|
|
249
|
+
# Initialize before exporting spans when this session has a contract.
|
|
250
|
+
await conn.thread("agent-session:123", {"contract": "agent_contract"})
|
|
251
|
+
tracer = trace.get_tracer("agent")
|
|
252
|
+
with tracer.start_as_current_span("tool_call", attributes={
|
|
253
|
+
"threadify.thread_key": "agent-session:123",
|
|
254
|
+
}):
|
|
255
|
+
pass # Perform the instrumented operation.
|
|
239
256
|
```
|
|
240
257
|
|
|
258
|
+
The exporter resolves `threadify.thread_key` using the same create-or-resume
|
|
259
|
+
operation as `connection.thread()`. Omit the contract on later spans; the stored
|
|
260
|
+
contract version is loaded automatically. Shared root spans keep the session open.
|
|
261
|
+
See [OTel correlation](OTEL_CORRELATION.md) for identity precedence and completion.
|
|
262
|
+
|
|
241
263
|
**Filter patterns:**
|
|
242
264
|
|
|
243
265
|
- `"invoke_llm"` — exact match
|
|
@@ -266,7 +288,7 @@ from threadify import Threadify, WaitOptions, ThreadifyError
|
|
|
266
288
|
|
|
267
289
|
connection = await Threadify.connect(api_key, engine_url="https://threadify.example.com", service_name="payments")
|
|
268
290
|
threads = await connection.get_threads_by_ref({"order_id": "ORD-1001"}, status="active", limit=25)
|
|
269
|
-
thread = await connection.
|
|
291
|
+
thread = await connection.thread("order:ORD-1001")
|
|
270
292
|
grant = await thread.wait_for("charge", WaitOptions(timeout=15))
|
|
271
293
|
# Execute the permitted business operation here.
|
|
272
294
|
result = await thread.step("charge").add_context({"amount": 42}).success("charged", wait_for=True, timeout=15)
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "threadify-sdk"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.4.0"
|
|
8
8
|
description = "Python SDK for Threadify — Service-delivery intelligence. Track every customer request from start to finish across every system, team, and partner. Visit: https://threadify.dev"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -28,7 +28,6 @@ classifiers = [
|
|
|
28
28
|
dependencies = [
|
|
29
29
|
"websockets>=12.0",
|
|
30
30
|
"httpx>=0.27.0",
|
|
31
|
-
"PyYAML>=6.0",
|
|
32
31
|
]
|
|
33
32
|
|
|
34
33
|
[project.optional-dependencies]
|