paid-python 0.0.5a40__py3-none-any.whl → 0.1.0__py3-none-any.whl
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.
- paid/client.py +339 -233
- paid/logger.py +21 -0
- paid/tracing/__init__.py +4 -4
- paid/tracing/autoinstrumentation.py +6 -3
- paid/tracing/context_manager.py +243 -0
- paid/tracing/distributed_tracing.py +113 -0
- paid/tracing/signal.py +58 -28
- paid/tracing/tracing.py +103 -439
- paid/tracing/wrappers/anthropic/anthropicWrapper.py +11 -72
- paid/tracing/wrappers/bedrock/bedrockWrapper.py +3 -32
- paid/tracing/wrappers/gemini/geminiWrapper.py +10 -46
- paid/tracing/wrappers/langchain/paidLangChainCallback.py +3 -38
- paid/tracing/wrappers/llamaindex/llamaIndexWrapper.py +4 -38
- paid/tracing/wrappers/mistral/mistralWrapper.py +7 -118
- paid/tracing/wrappers/openai/openAiWrapper.py +56 -323
- paid/tracing/wrappers/openai_agents/openaiAgentsHook.py +8 -76
- {paid_python-0.0.5a40.dist-info → paid_python-0.1.0.dist-info}/METADATA +39 -192
- {paid_python-0.0.5a40.dist-info → paid_python-0.1.0.dist-info}/RECORD +20 -17
- {paid_python-0.0.5a40.dist-info → paid_python-0.1.0.dist-info}/LICENSE +0 -0
- {paid_python-0.0.5a40.dist-info → paid_python-0.1.0.dist-info}/WHEEL +0 -0
paid/client.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
-
|
|
3
2
|
import typing
|
|
3
|
+
import warnings
|
|
4
4
|
|
|
5
5
|
import httpx
|
|
6
6
|
from .agents.client import AgentsClient, AsyncAgentsClient
|
|
@@ -9,16 +9,18 @@ from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
|
9
9
|
from .customers.client import AsyncCustomersClient, CustomersClient
|
|
10
10
|
from .environment import PaidEnvironment
|
|
11
11
|
from .orders.client import AsyncOrdersClient, OrdersClient
|
|
12
|
-
from .tracing.
|
|
13
|
-
from .tracing.tracing import (
|
|
14
|
-
_initialize_tracing,
|
|
15
|
-
_trace_async,
|
|
16
|
-
_trace_sync,
|
|
17
|
-
generate_and_set_tracing_token,
|
|
12
|
+
from .tracing.distributed_tracing import (
|
|
18
13
|
generate_tracing_token,
|
|
19
14
|
set_tracing_token,
|
|
20
15
|
unset_tracing_token,
|
|
21
16
|
)
|
|
17
|
+
from .tracing.signal import signal
|
|
18
|
+
from .tracing.tracing import (
|
|
19
|
+
DEFAULT_COLLECTOR_ENDPOINT,
|
|
20
|
+
initialize_tracing_,
|
|
21
|
+
trace_async_,
|
|
22
|
+
trace_sync_,
|
|
23
|
+
)
|
|
22
24
|
from .usage.client import AsyncUsageClient, UsageClient
|
|
23
25
|
|
|
24
26
|
T = typing.TypeVar("T")
|
|
@@ -35,20 +37,12 @@ class Paid:
|
|
|
35
37
|
|
|
36
38
|
environment : PaidEnvironment
|
|
37
39
|
The environment to use for requests from the client. from .environment import PaidEnvironment
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
40
|
Defaults to PaidEnvironment.PRODUCTION
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
41
|
token : typing.Union[str, typing.Callable[[], str]]
|
|
46
42
|
timeout : typing.Optional[float]
|
|
47
43
|
The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
|
|
48
|
-
|
|
49
44
|
follow_redirects : typing.Optional[bool]
|
|
50
45
|
Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
|
|
51
|
-
|
|
52
46
|
httpx_client : typing.Optional[httpx.Client]
|
|
53
47
|
The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
|
|
54
48
|
|
|
@@ -90,80 +84,138 @@ class Paid:
|
|
|
90
84
|
self.orders = OrdersClient(client_wrapper=self._client_wrapper)
|
|
91
85
|
self.usage = UsageClient(client_wrapper=self._client_wrapper)
|
|
92
86
|
|
|
93
|
-
def initialize_tracing(self, collector_endpoint: str =
|
|
87
|
+
def initialize_tracing(self, collector_endpoint: str = DEFAULT_COLLECTOR_ENDPOINT) -> None:
|
|
94
88
|
"""
|
|
95
|
-
|
|
96
|
-
|
|
89
|
+
Deprecated: Use the @paid_tracing decorator or context manager instead.
|
|
90
|
+
|
|
91
|
+
This method is deprecated and will be removed in a future version.
|
|
92
|
+
The @paid_tracing decorator automatically initializes tracing as needed.
|
|
97
93
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
Instead of:
|
|
95
|
+
client.initialize_tracing()
|
|
96
|
+
client.trace(external_customer_id="...", fn=lambda: ...)
|
|
97
|
+
|
|
98
|
+
Use:
|
|
99
|
+
from paid.tracing import paid_tracing
|
|
100
|
+
|
|
101
|
+
@paid_tracing(external_customer_id="...", external_agent_id="...")
|
|
102
|
+
def my_function():
|
|
103
|
+
...
|
|
104
|
+
|
|
105
|
+
Or as a context manager:
|
|
106
|
+
with paid_tracing(external_customer_id="..."):
|
|
107
|
+
result = agent_workflow()
|
|
101
108
|
"""
|
|
109
|
+
warnings.warn(
|
|
110
|
+
"Paid.initialize_tracing() is deprecated and will be removed in a future version. "
|
|
111
|
+
"Use @paid_tracing decorator/context manager directly, which auto-initializes tracing. "
|
|
112
|
+
"See documentation: https://docs.paid.ai/documentation/getting-started/integrate-signals-and-cost-tracking-to-your-codebase",
|
|
113
|
+
DeprecationWarning,
|
|
114
|
+
stacklevel=2,
|
|
115
|
+
)
|
|
102
116
|
token = self._client_wrapper._get_token()
|
|
103
|
-
|
|
117
|
+
initialize_tracing_(token, collector_endpoint=collector_endpoint)
|
|
104
118
|
|
|
105
119
|
def generate_tracing_token(self) -> int:
|
|
106
120
|
"""
|
|
107
|
-
|
|
108
|
-
for the tracing context. Needed when you only want to store or send a tracing token
|
|
109
|
-
somewhere else.
|
|
110
|
-
"""
|
|
111
|
-
return generate_tracing_token()
|
|
121
|
+
Deprecated: Import and use generate_tracing_token() directly from paid.tracing.
|
|
112
122
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
tracing context are associated with each other.
|
|
125
|
-
|
|
126
|
-
To stop associating the traces one can either call
|
|
127
|
-
generate_and_set_tracing_token() once again or call unset_tracing_token().
|
|
128
|
-
The former is suitable if you still want to trace but in a fresh
|
|
129
|
-
context, and the latter will go back to unique traces per Paid.trace().
|
|
123
|
+
This method is deprecated and will be removed in a future version.
|
|
124
|
+
Use the standalone function instead.
|
|
125
|
+
|
|
126
|
+
Instead of:
|
|
127
|
+
from paid import Paid
|
|
128
|
+
client = Paid(token="...")
|
|
129
|
+
token = client.generate_tracing_token()
|
|
130
|
+
|
|
131
|
+
Use:
|
|
132
|
+
from paid.tracing import generate_tracing_token
|
|
133
|
+
token = generate_tracing_token()
|
|
130
134
|
"""
|
|
131
|
-
|
|
135
|
+
warnings.warn(
|
|
136
|
+
"Paid.generate_tracing_token() is deprecated and will be removed in a future version. "
|
|
137
|
+
"Import and use generate_tracing_token() directly from paid.tracing instead.",
|
|
138
|
+
DeprecationWarning,
|
|
139
|
+
stacklevel=2,
|
|
140
|
+
)
|
|
141
|
+
return generate_tracing_token()
|
|
132
142
|
|
|
133
143
|
def set_tracing_token(self, token: int):
|
|
134
144
|
"""
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
+
Deprecated: Pass tracing_token directly to @paid_tracing() decorator instead.
|
|
146
|
+
|
|
147
|
+
This method is deprecated and will be removed in a future version.
|
|
148
|
+
Use the tracing_token parameter in @paid_tracing() to link traces across processes.
|
|
149
|
+
|
|
150
|
+
Instead of:
|
|
151
|
+
from paid import Paid
|
|
152
|
+
client = Paid(token="...")
|
|
153
|
+
token = load_from_storage("workflow_123")
|
|
154
|
+
client.set_tracing_token(token)
|
|
155
|
+
@paid_tracing(external_customer_id="cust_123", external_agent_id="agent_456")
|
|
156
|
+
def process_workflow():
|
|
157
|
+
...
|
|
158
|
+
client.unset_tracing_token()
|
|
159
|
+
|
|
160
|
+
Use:
|
|
161
|
+
from paid.tracing import paid_tracing
|
|
162
|
+
token = load_from_storage("workflow_123")
|
|
163
|
+
|
|
164
|
+
@paid_tracing(
|
|
165
|
+
external_customer_id="cust_123",
|
|
166
|
+
external_agent_id="agent_456",
|
|
167
|
+
tracing_token=token
|
|
168
|
+
)
|
|
169
|
+
def process_workflow():
|
|
170
|
+
...
|
|
145
171
|
|
|
172
|
+
Parameters
|
|
173
|
+
----------
|
|
174
|
+
token : int
|
|
175
|
+
A tracing token to use for the next traces.
|
|
176
|
+
"""
|
|
177
|
+
warnings.warn(
|
|
178
|
+
"Paid.set_tracing_token() is deprecated and will be removed in a future version. "
|
|
179
|
+
"Pass tracing_token directly to @paid_tracing(tracing_token=...) decorator instead.",
|
|
180
|
+
DeprecationWarning,
|
|
181
|
+
stacklevel=2,
|
|
182
|
+
)
|
|
146
183
|
set_tracing_token(token)
|
|
147
184
|
|
|
148
185
|
def unset_tracing_token(self):
|
|
149
186
|
"""
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
187
|
+
Deprecated: No longer needed. Use tracing_token parameter in @paid_tracing() instead.
|
|
188
|
+
|
|
189
|
+
This method is deprecated and will be removed in a future version.
|
|
190
|
+
Since tracing_token is now passed directly to @paid_tracing(), there's no need
|
|
191
|
+
to manually set/unset tokens in the context.
|
|
192
|
+
|
|
193
|
+
Old pattern (no longer recommended):
|
|
194
|
+
from paid import Paid
|
|
195
|
+
client = Paid(token="...")
|
|
196
|
+
client.set_tracing_token(token)
|
|
197
|
+
@paid_tracing(external_customer_id="cust_123", external_agent_id="agent_456")
|
|
198
|
+
def my_function():
|
|
199
|
+
...
|
|
200
|
+
client.unset_tracing_token()
|
|
201
|
+
|
|
202
|
+
New pattern (recommended):
|
|
203
|
+
from paid.tracing import paid_tracing
|
|
204
|
+
@paid_tracing(
|
|
205
|
+
external_customer_id="cust_123",
|
|
206
|
+
external_agent_id="agent_456",
|
|
207
|
+
tracing_token=token
|
|
208
|
+
)
|
|
209
|
+
def my_function():
|
|
210
|
+
...
|
|
153
211
|
"""
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
fn: typing.Callable[[], T],
|
|
160
|
-
args: typing.Optional[typing.Tuple] = None,
|
|
161
|
-
kwargs: typing.Optional[typing.Dict] = None,
|
|
162
|
-
) -> T:
|
|
163
|
-
print("capture() is deprecated. Please rename it to trace() to remove this message.")
|
|
164
|
-
return _trace_sync(
|
|
165
|
-
external_customer_id=external_customer_id, fn=fn, external_agent_id=None, args=args, kwargs=kwargs
|
|
212
|
+
warnings.warn(
|
|
213
|
+
"Paid.unset_tracing_token() is deprecated and will be removed in a future version. "
|
|
214
|
+
"Use tracing_token parameter in @paid_tracing(tracing_token=...) decorator instead.",
|
|
215
|
+
DeprecationWarning,
|
|
216
|
+
stacklevel=2,
|
|
166
217
|
)
|
|
218
|
+
unset_tracing_token()
|
|
167
219
|
|
|
168
220
|
def trace(
|
|
169
221
|
self,
|
|
@@ -176,31 +228,40 @@ class Paid:
|
|
|
176
228
|
kwargs: typing.Optional[typing.Dict] = None,
|
|
177
229
|
) -> T:
|
|
178
230
|
"""
|
|
179
|
-
|
|
231
|
+
Deprecated: Use the @paid_tracing decorator or context manager instead.
|
|
180
232
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
233
|
+
This method is deprecated and will be removed in a future version.
|
|
234
|
+
The callback-based tracing via Paid.trace() is being replaced with the more
|
|
235
|
+
Pythonic @paid_tracing decorator and context manager.
|
|
236
|
+
|
|
237
|
+
Instead of:
|
|
238
|
+
result = client.trace(
|
|
239
|
+
external_customer_id="cust_123",
|
|
240
|
+
fn=lambda: agent_workflow(),
|
|
241
|
+
external_agent_id="agent_456"
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
Use the decorator:
|
|
245
|
+
from paid.tracing import paid_tracing
|
|
246
|
+
|
|
247
|
+
@paid_tracing(external_customer_id="cust_123", external_agent_id="agent_456")
|
|
248
|
+
def agent_workflow():
|
|
249
|
+
...
|
|
250
|
+
|
|
251
|
+
result = agent_workflow()
|
|
252
|
+
|
|
253
|
+
Or use the context manager:
|
|
254
|
+
with paid_tracing(external_customer_id="cust_123", external_agent_id="agent_456"):
|
|
255
|
+
result = agent_workflow()
|
|
202
256
|
"""
|
|
203
|
-
|
|
257
|
+
warnings.warn(
|
|
258
|
+
"Paid.trace() is deprecated and will be removed in a future version. "
|
|
259
|
+
"Use the @paid_tracing decorator or context manager instead. "
|
|
260
|
+
"See documentation: https://docs.paid.ai/documentation/getting-started/integrate-signals-and-cost-tracking-to-your-codebase",
|
|
261
|
+
DeprecationWarning,
|
|
262
|
+
stacklevel=2,
|
|
263
|
+
)
|
|
264
|
+
return trace_sync_(
|
|
204
265
|
external_customer_id=external_customer_id,
|
|
205
266
|
fn=fn,
|
|
206
267
|
external_agent_id=external_agent_id,
|
|
@@ -218,36 +279,27 @@ class Paid:
|
|
|
218
279
|
enable_cost_tracing: bool = False,
|
|
219
280
|
) -> None:
|
|
220
281
|
"""
|
|
221
|
-
|
|
222
|
-
When enable_cost_tracing flag is on, signal is associated
|
|
223
|
-
with cost traces from the same Paid.trace() context.
|
|
282
|
+
Deprecated: Import and use signal() directly from paid.tracing.
|
|
224
283
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
-----
|
|
237
|
-
signal("event_name")
|
|
238
|
-
signal("event_name", data={"key": "value"})
|
|
239
|
-
signal("event_name", enable_cost_tracing=True)
|
|
240
|
-
signal("event_name", enable_cost_tracing=True, data={"key": "value"})
|
|
241
|
-
|
|
242
|
-
Notes
|
|
243
|
-
-----
|
|
244
|
-
When enable_cost_tracing is on, the signal will be associated with cost
|
|
245
|
-
traces within the same Paid.trace() context.
|
|
246
|
-
It is advised to only make one call to this function
|
|
247
|
-
with enable_cost_tracing per Paid.trace() context.
|
|
248
|
-
Otherwise, there will be multiple signals that refer to the same costs.
|
|
284
|
+
This method is deprecated and will be removed in a future version.
|
|
285
|
+
Use the standalone function instead.
|
|
286
|
+
|
|
287
|
+
Instead of:
|
|
288
|
+
from paid import Paid
|
|
289
|
+
client = Paid(token="...")
|
|
290
|
+
client.signal("event_name", data={...})
|
|
291
|
+
|
|
292
|
+
Use:
|
|
293
|
+
from paid.tracing import signal
|
|
294
|
+
signal("event_name", data={...})
|
|
249
295
|
"""
|
|
250
|
-
|
|
296
|
+
warnings.warn(
|
|
297
|
+
"Paid.signal() is deprecated and will be removed in a future version. "
|
|
298
|
+
"Import and use signal() directly from paid.tracing instead.",
|
|
299
|
+
DeprecationWarning,
|
|
300
|
+
stacklevel=2,
|
|
301
|
+
)
|
|
302
|
+
signal(event_name=event_name, enable_cost_tracing=enable_cost_tracing, data=data)
|
|
251
303
|
|
|
252
304
|
|
|
253
305
|
class AsyncPaid:
|
|
@@ -261,13 +313,7 @@ class AsyncPaid:
|
|
|
261
313
|
|
|
262
314
|
environment : PaidEnvironment
|
|
263
315
|
The environment to use for requests from the client. from .environment import PaidEnvironment
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
316
|
Defaults to PaidEnvironment.PRODUCTION
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
317
|
token : typing.Union[str, typing.Callable[[], str]]
|
|
272
318
|
timeout : typing.Optional[float]
|
|
273
319
|
The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
|
|
@@ -316,80 +362,140 @@ class AsyncPaid:
|
|
|
316
362
|
self.orders = AsyncOrdersClient(client_wrapper=self._client_wrapper)
|
|
317
363
|
self.usage = AsyncUsageClient(client_wrapper=self._client_wrapper)
|
|
318
364
|
|
|
319
|
-
def initialize_tracing(self, collector_endpoint: str =
|
|
365
|
+
def initialize_tracing(self, collector_endpoint: str = DEFAULT_COLLECTOR_ENDPOINT) -> None:
|
|
320
366
|
"""
|
|
321
|
-
|
|
322
|
-
|
|
367
|
+
Deprecated: Use the @paid_tracing decorator or context manager instead.
|
|
368
|
+
|
|
369
|
+
This method is deprecated and will be removed in a future version.
|
|
370
|
+
The @paid_tracing decorator automatically initializes tracing as needed.
|
|
371
|
+
|
|
372
|
+
Instead of:
|
|
373
|
+
client.initialize_tracing()
|
|
374
|
+
await client.trace(external_customer_id="...", fn=async_func)
|
|
375
|
+
|
|
376
|
+
Use:
|
|
377
|
+
from paid.tracing import paid_tracing
|
|
378
|
+
|
|
379
|
+
@paid_tracing(external_customer_id="...", external_agent_id="...")
|
|
380
|
+
async def my_async_function():
|
|
381
|
+
...
|
|
323
382
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
383
|
+
await my_async_function()
|
|
384
|
+
|
|
385
|
+
Or as an async context manager:
|
|
386
|
+
async with paid_tracing(external_customer_id="..."):
|
|
387
|
+
result = await async_operation()
|
|
327
388
|
"""
|
|
389
|
+
warnings.warn(
|
|
390
|
+
"AsyncPaid.initialize_tracing() is deprecated and will be removed in a future version. "
|
|
391
|
+
"Use @paid_tracing decorator/context manager directly, which auto-initializes tracing. "
|
|
392
|
+
"See documentation: https://docs.paid.ai/documentation/getting-started/integrate-signals-and-cost-tracking-to-your-codebase",
|
|
393
|
+
DeprecationWarning,
|
|
394
|
+
stacklevel=2,
|
|
395
|
+
)
|
|
328
396
|
token = self._client_wrapper._get_token()
|
|
329
|
-
|
|
397
|
+
initialize_tracing_(token, collector_endpoint=collector_endpoint)
|
|
330
398
|
|
|
331
399
|
def generate_tracing_token(self) -> int:
|
|
332
400
|
"""
|
|
333
|
-
|
|
334
|
-
for the tracing context. Needed when you only want to store or send a tracing token
|
|
335
|
-
somewhere else.
|
|
336
|
-
"""
|
|
337
|
-
return generate_tracing_token()
|
|
401
|
+
Deprecated: Import and use generate_tracing_token() directly from paid.tracing.
|
|
338
402
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
tracing context are associated with each other.
|
|
351
|
-
|
|
352
|
-
To stop associating the traces one can either call
|
|
353
|
-
generate_and_set_tracing_token() once again or call unset_tracing_token().
|
|
354
|
-
The former is suitable if you still want to trace but in a fresh
|
|
355
|
-
context, and the latter will go back to unique traces per Paid.trace() or @paid_tracing().
|
|
403
|
+
This method is deprecated and will be removed in a future version.
|
|
404
|
+
Use the standalone function instead.
|
|
405
|
+
|
|
406
|
+
Instead of:
|
|
407
|
+
from paid import AsyncPaid
|
|
408
|
+
client = AsyncPaid(token="...")
|
|
409
|
+
token = client.generate_tracing_token()
|
|
410
|
+
|
|
411
|
+
Use:
|
|
412
|
+
from paid.tracing import generate_tracing_token
|
|
413
|
+
token = generate_tracing_token()
|
|
356
414
|
"""
|
|
357
|
-
|
|
415
|
+
warnings.warn(
|
|
416
|
+
"AsyncPaid.generate_tracing_token() is deprecated and will be removed in a future version. "
|
|
417
|
+
"Import and use generate_tracing_token() directly from paid.tracing instead.",
|
|
418
|
+
DeprecationWarning,
|
|
419
|
+
stacklevel=2,
|
|
420
|
+
)
|
|
421
|
+
return generate_tracing_token()
|
|
358
422
|
|
|
359
423
|
def set_tracing_token(self, token: int):
|
|
360
424
|
"""
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
425
|
+
Deprecated: Pass tracing_token directly to @paid_tracing() decorator instead.
|
|
426
|
+
|
|
427
|
+
This method is deprecated and will be removed in a future version.
|
|
428
|
+
Use the tracing_token parameter in @paid_tracing() to link traces across processes.
|
|
429
|
+
|
|
430
|
+
Instead of:
|
|
431
|
+
from paid import AsyncPaid
|
|
432
|
+
client = AsyncPaid(token="...")
|
|
433
|
+
token = load_from_storage("workflow_123")
|
|
434
|
+
client.set_tracing_token(token)
|
|
435
|
+
@paid_tracing(external_customer_id="cust_123", external_agent_id="agent_456")
|
|
436
|
+
async def process_workflow():
|
|
437
|
+
...
|
|
438
|
+
client.unset_tracing_token()
|
|
439
|
+
|
|
440
|
+
Use:
|
|
441
|
+
from paid.tracing import paid_tracing
|
|
442
|
+
token = load_from_storage("workflow_123")
|
|
443
|
+
|
|
444
|
+
@paid_tracing(
|
|
445
|
+
external_customer_id="cust_123",
|
|
446
|
+
external_agent_id="agent_456",
|
|
447
|
+
tracing_token=token
|
|
448
|
+
)
|
|
449
|
+
async def process_workflow():
|
|
450
|
+
...
|
|
371
451
|
|
|
452
|
+
Parameters
|
|
453
|
+
----------
|
|
454
|
+
token : int
|
|
455
|
+
A tracing token to use for the next traces.
|
|
456
|
+
"""
|
|
457
|
+
warnings.warn(
|
|
458
|
+
"AsyncPaid.set_tracing_token() is deprecated and will be removed in a future version. "
|
|
459
|
+
"Pass tracing_token directly to @paid_tracing(tracing_token=...) decorator instead.",
|
|
460
|
+
DeprecationWarning,
|
|
461
|
+
stacklevel=2,
|
|
462
|
+
)
|
|
372
463
|
set_tracing_token(token)
|
|
373
464
|
|
|
374
465
|
def unset_tracing_token(self):
|
|
375
466
|
"""
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
467
|
+
Deprecated: No longer needed. Use tracing_token parameter in @paid_tracing() instead.
|
|
468
|
+
|
|
469
|
+
This method is deprecated and will be removed in a future version.
|
|
470
|
+
Since tracing_token is now passed directly to @paid_tracing(), there's no need
|
|
471
|
+
to manually set/unset tokens in the context.
|
|
472
|
+
|
|
473
|
+
Old pattern (no longer recommended):
|
|
474
|
+
from paid import AsyncPaid
|
|
475
|
+
client = AsyncPaid(token="...")
|
|
476
|
+
client.set_tracing_token(token)
|
|
477
|
+
@paid_tracing(external_customer_id="cust_123", external_agent_id="agent_456")
|
|
478
|
+
async def my_function():
|
|
479
|
+
...
|
|
480
|
+
client.unset_tracing_token()
|
|
481
|
+
|
|
482
|
+
New pattern (recommended):
|
|
483
|
+
from paid.tracing import paid_tracing
|
|
484
|
+
@paid_tracing(
|
|
485
|
+
external_customer_id="cust_123",
|
|
486
|
+
external_agent_id="agent_456",
|
|
487
|
+
tracing_token=token
|
|
488
|
+
)
|
|
489
|
+
async def my_function():
|
|
490
|
+
...
|
|
379
491
|
"""
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
fn: typing.Callable[[], typing.Awaitable[T]],
|
|
386
|
-
args: typing.Optional[typing.Tuple] = None,
|
|
387
|
-
kwargs: typing.Optional[typing.Dict] = None,
|
|
388
|
-
) -> typing.Union[T, typing.Awaitable[T]]:
|
|
389
|
-
print("capture() is deprecated. Please rename it to trace() to remove this message.")
|
|
390
|
-
return await _trace_async(
|
|
391
|
-
external_customer_id=external_customer_id, fn=fn, external_agent_id=None, args=args, kwargs=kwargs
|
|
492
|
+
warnings.warn(
|
|
493
|
+
"AsyncPaid.unset_tracing_token() is deprecated and will be removed in a future version. "
|
|
494
|
+
"Use tracing_token parameter in @paid_tracing(tracing_token=...) decorator instead.",
|
|
495
|
+
DeprecationWarning,
|
|
496
|
+
stacklevel=2,
|
|
392
497
|
)
|
|
498
|
+
unset_tracing_token()
|
|
393
499
|
|
|
394
500
|
async def trace(
|
|
395
501
|
self,
|
|
@@ -402,31 +508,40 @@ class AsyncPaid:
|
|
|
402
508
|
kwargs: typing.Optional[typing.Dict] = None,
|
|
403
509
|
) -> typing.Union[T, typing.Awaitable[T]]:
|
|
404
510
|
"""
|
|
405
|
-
|
|
511
|
+
Deprecated: Use the @paid_tracing decorator or context manager instead.
|
|
406
512
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
513
|
+
This method is deprecated and will be removed in a future version.
|
|
514
|
+
The callback-based tracing via AsyncPaid.trace() is being replaced with the more
|
|
515
|
+
Pythonic @paid_tracing decorator and context manager.
|
|
516
|
+
|
|
517
|
+
Instead of:
|
|
518
|
+
result = await client.trace(
|
|
519
|
+
external_customer_id="cust_123",
|
|
520
|
+
fn=agent_workflow,
|
|
521
|
+
external_agent_id="agent_456"
|
|
522
|
+
)
|
|
523
|
+
|
|
524
|
+
Use the decorator:
|
|
525
|
+
from paid.tracing import paid_tracing
|
|
526
|
+
|
|
527
|
+
@paid_tracing(external_customer_id="cust_123", external_agent_id="agent_456")
|
|
528
|
+
async def agent_workflow():
|
|
529
|
+
...
|
|
530
|
+
|
|
531
|
+
result = await agent_workflow()
|
|
532
|
+
|
|
533
|
+
Or use the async context manager:
|
|
534
|
+
async with paid_tracing(external_customer_id="cust_123", external_agent_id="agent_456"):
|
|
535
|
+
result = await agent_workflow()
|
|
428
536
|
"""
|
|
429
|
-
|
|
537
|
+
warnings.warn(
|
|
538
|
+
"AsyncPaid.trace() is deprecated and will be removed in a future version. "
|
|
539
|
+
"Use the @paid_tracing decorator or context manager instead. "
|
|
540
|
+
"See documentation: https://docs.paid.ai/documentation/getting-started/integrate-signals-and-cost-tracking-to-your-codebase",
|
|
541
|
+
DeprecationWarning,
|
|
542
|
+
stacklevel=2,
|
|
543
|
+
)
|
|
544
|
+
return await trace_async_(
|
|
430
545
|
external_customer_id=external_customer_id,
|
|
431
546
|
fn=fn,
|
|
432
547
|
external_agent_id=external_agent_id,
|
|
@@ -444,36 +559,27 @@ class AsyncPaid:
|
|
|
444
559
|
enable_cost_tracing: bool = False,
|
|
445
560
|
) -> None:
|
|
446
561
|
"""
|
|
447
|
-
|
|
448
|
-
When enable_cost_tracing flag is on, signal is associated
|
|
449
|
-
with cost traces from the same Paid.trace() context.
|
|
562
|
+
Deprecated: Import and use signal() directly from paid.tracing.
|
|
450
563
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
-----
|
|
463
|
-
signal("event_name")
|
|
464
|
-
signal("event_name", data={"key": "value"})
|
|
465
|
-
signal("event_name", enable_cost_tracing=True)
|
|
466
|
-
signal("event_name", enable_cost_tracing=True, data={"key": "value"})
|
|
467
|
-
|
|
468
|
-
Notes
|
|
469
|
-
-----
|
|
470
|
-
When enable_cost_tracing is on, the signal will be associated with cost
|
|
471
|
-
traces within the same Paid.trace() context.
|
|
472
|
-
It is advised to only make one call to this function
|
|
473
|
-
with enable_cost_tracing per Paid.trace() context.
|
|
474
|
-
Otherwise, there will be multiple signals that refer to the same costs.
|
|
564
|
+
This method is deprecated and will be removed in a future version.
|
|
565
|
+
Use the standalone function instead.
|
|
566
|
+
|
|
567
|
+
Instead of:
|
|
568
|
+
from paid import AsyncPaid
|
|
569
|
+
client = AsyncPaid(token="...")
|
|
570
|
+
client.signal("event_name", data={...})
|
|
571
|
+
|
|
572
|
+
Use:
|
|
573
|
+
from paid.tracing import signal
|
|
574
|
+
signal("event_name", data={...})
|
|
475
575
|
"""
|
|
476
|
-
|
|
576
|
+
warnings.warn(
|
|
577
|
+
"AsyncPaid.signal() is deprecated and will be removed in a future version. "
|
|
578
|
+
"Import and use signal() directly from paid.tracing instead.",
|
|
579
|
+
DeprecationWarning,
|
|
580
|
+
stacklevel=2,
|
|
581
|
+
)
|
|
582
|
+
signal(event_name=event_name, enable_cost_tracing=enable_cost_tracing, data=data)
|
|
477
583
|
|
|
478
584
|
|
|
479
585
|
def _get_base_url(*, base_url: typing.Optional[str] = None, environment: PaidEnvironment) -> str:
|