paid-python 0.0.5a39__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 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.signal import _signal
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 = "https://collector.agentpaid.io:4318/v1/traces") -> None:
87
+ def initialize_tracing(self, collector_endpoint: str = DEFAULT_COLLECTOR_ENDPOINT) -> None:
94
88
  """
95
- Initializes tracing for the Paid client.
96
- Call this method before using tracing features to ensure proper setup.
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
- Returns
99
- -------
100
- None
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
- _initialize_tracing(token, collector_endpoint=collector_endpoint)
117
+ initialize_tracing_(token, collector_endpoint=collector_endpoint)
104
118
 
105
119
  def generate_tracing_token(self) -> int:
106
120
  """
107
- This will generate and return a tracing token but it will not set it
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
- def generate_and_set_tracing_token(self) -> int:
114
- """
115
- *Advanced feature*
116
- In cases when you can't share the same Paid.trace() context with
117
- code that you want to track together (complex concurrency logic,
118
- or disjoint workflows, or work is separated between processes),
119
- then you can manually generate a tracing token with generate_and_set_traceing_token()
120
- and share it with the other parts of your application or service using set_tracing_token().
121
-
122
- This function returns tracing token and attaches it to all consequent
123
- Paid.trace() tracing contexts. So all the costs and signals that share this
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
- return generate_and_set_tracing_token()
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
- *Advanced feature*
136
- In cases when you can't share the same Paid.trace() context with
137
- code that you want to track together (complex concurrency logic,
138
- or disjoint workflows, or work is separated between processes),
139
- then you can manually generate a tracing token with generate_and_set_traceing_token()
140
- and share it with the other parts of your application or service using set_tracing_token().
141
-
142
- Sets tracing token. Provided token should come from generate_and_set_tracing_token().
143
- Once set, the consequent traces will be related to each other.
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
- Unsets the token previously set by generate_and_set_tracing_token()
151
- or by set_tracing_token(token). Does nothing if the token was never set.
152
- When tracing token is unset, traces are unique for a single Paid.trace() context.
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
- unset_tracing_token()
155
-
156
- def capture(
157
- self,
158
- external_customer_id: str,
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
- Traces the execution of the provided function.
231
+ Deprecated: Use the @paid_tracing decorator or context manager instead.
180
232
 
181
- Parameters
182
- ----------
183
- external_customer_id : str
184
- The external customer ID to associate with the trace.
185
- fn : typing.Callable[[], T]
186
- The function to be traced.
187
- external_agent_id : typing.Optional[str], optional
188
- The external agent ID to associate with the trace, by default None.
189
- tracing_token : typing.Optional[int], optional
190
- The tracing token for distributed tracing, by default None.
191
- metadata : typing.Optional[typing.Dict[str, typing.Any]], optional
192
- Additional metadata to associate with the trace, by default None.
193
- args : typing.Optional[typing.Tuple], optional
194
- Positional arguments to pass to the function, by default None.
195
- kwargs : typing.Optional[typing.Dict], optional
196
- Keyword arguments to pass to the function, by default None.
197
-
198
- Returns
199
- -------
200
- T
201
- The result of the traced function.
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
- return _trace_sync(
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
- Sends Paid signal. Needs to be called as part of callback to Paid.trace().
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
- Parameters
226
- ----------
227
- event_name : str
228
- The name of the signal.
229
- data : typing.Optional[typing.Dict[str, typing.Any]], optional
230
- Additional data to include with the signal event.
231
- enable_cost_tracing : bool, optional
232
- Whether to associate this signal with cost traces from the current Paid.trace() context.
233
- Defaults to False.
234
-
235
- Usage
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
- _signal(event_name=event_name, enable_cost_tracing=enable_cost_tracing, data=data)
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 = "https://collector.agentpaid.io:4318/v1/traces") -> None:
365
+ def initialize_tracing(self, collector_endpoint: str = DEFAULT_COLLECTOR_ENDPOINT) -> None:
320
366
  """
321
- Initializes tracing for the AsyncPaid client.
322
- Call this method before using tracing features to ensure proper setup.
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
- Returns
325
- -------
326
- None
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
- _initialize_tracing(token, collector_endpoint=collector_endpoint)
397
+ initialize_tracing_(token, collector_endpoint=collector_endpoint)
330
398
 
331
399
  def generate_tracing_token(self) -> int:
332
400
  """
333
- This will generate and return a tracing token but it will not set it
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
- def generate_and_set_tracing_token(self) -> int:
340
- """
341
- *Advanced feature*
342
- In cases when you can't share the same Paid.trace() or @paid_tracing() context with
343
- code that you want to track together (complex concurrency logic,
344
- or disjoint workflows, or work is separated between processes),
345
- then you can manually generate a tracing token with generate_and_set_traceing_token()
346
- and share it with the other parts of your application or service using set_tracing_token().
347
-
348
- This function returns tracing token and attaches it to all consequent
349
- Paid.trace() or @paid_tracing() tracing contexts. So all the costs and signals that share this
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
- return generate_and_set_tracing_token()
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
- *Advanced feature*
362
- In cases when you can't share the same Paid.trace() or @paid_tracing() context with
363
- code that you want to track together (complex concurrency logic,
364
- or disjoint workflows, or work is separated between processes),
365
- then you can manually generate a tracing token with generate_and_set_traceing_token()
366
- and share it with the other parts of your application or service using set_tracing_token().
367
-
368
- Sets tracing token. Provided token should come from generate_and_set_tracing_token().
369
- Once set, the consequent traces will be related to each other.
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
- Unsets the token previously set by generate_and_set_tracing_token()
377
- or by set_tracing_token(token). Does nothing if the token was never set.
378
- When tracing token is unset, traces are unique for a single Paid.trace() or @paid_tracing() context.
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
- unset_tracing_token()
381
-
382
- async def capture(
383
- self,
384
- external_customer_id: str,
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
- Traces the execution of the provided function asynchronously.
511
+ Deprecated: Use the @paid_tracing decorator or context manager instead.
406
512
 
407
- Parameters
408
- ----------
409
- external_customer_id : str
410
- The external customer ID to associate with the trace.
411
- fn : typing.Callable[[], typing.Awaitable[T]]
412
- The async function to be traced.
413
- external_agent_id : typing.Optional[str], optional
414
- The external agent ID to associate with the trace, by default None.
415
- tracing_token : typing.Optional[int], optional
416
- The tracing token for distributed tracing, by default None.
417
- metadata : typing.Optional[typing.Dict[str, typing.Any]], optional
418
- Additional metadata to associate with the trace, by default None.
419
- args : typing.Optional[typing.Tuple], optional
420
- Positional arguments to pass to the function, by default None.
421
- kwargs : typing.Optional[typing.Dict], optional
422
- Keyword arguments to pass to the function, by default None.
423
-
424
- Returns
425
- -------
426
- T
427
- The result of the traced function.
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
- return await _trace_async(
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
- Sends Paid signal. Needs to be called as part of callback to Paid.trace().
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
- Parameters
452
- ----------
453
- event_name : str
454
- The name of the signal.
455
- data : typing.Optional[typing.Dict[str, typing.Any]], optional
456
- Additional data to include with the signal event.
457
- enable_cost_tracing : bool, optional
458
- Whether to associate this signal with cost traces from the current Paid.trace() context.
459
- Defaults to False.
460
-
461
- Usage
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
- _signal(event_name=event_name, enable_cost_tracing=enable_cost_tracing, data=data)
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: