-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtracer.py
More file actions
75 lines (60 loc) · 2.04 KB
/
tracer.py
File metadata and controls
75 lines (60 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from __future__ import annotations
from agentex import Agentex, AsyncAgentex
from agentex.lib.core.tracing.trace import Trace, AsyncTrace
from agentex.lib.core.tracing.span_queue import AsyncSpanQueue
from agentex.lib.core.tracing.tracing_processor_manager import (
get_sync_tracing_processors,
get_async_tracing_processors,
)
class Tracer:
"""
Tracer is the main entry point for tracing in Agentex.
It manages the client connection and creates traces.
"""
def __init__(self, client: Agentex):
"""
Initialize a new sync tracer with the provided client.
Args:
client: Agentex client instance used for API communication.
"""
self.client = client
def trace(self, trace_id: str | None = None) -> Trace:
"""
Create a new trace with the given trace ID.
Args:
trace_id: The trace ID to use.
Returns:
A new Trace instance.
"""
return Trace(
processors=get_sync_tracing_processors(),
client=self.client,
trace_id=trace_id,
)
class AsyncTracer:
"""
AsyncTracer is the async version of Tracer.
It manages the async client connection and creates async traces.
"""
def __init__(self, client: AsyncAgentex):
"""
Initialize a new async tracer with the provided client.
Args:
client: AsyncAgentex client instance used for API communication.
"""
self.client = client
def trace(self, trace_id: str | None = None, span_queue: AsyncSpanQueue | None = None) -> AsyncTrace:
"""
Create a new trace with the given trace ID.
Args:
trace_id: The trace ID to use.
span_queue: Optional span queue for background processing.
Returns:
A new AsyncTrace instance.
"""
return AsyncTrace(
processors=get_async_tracing_processors(),
client=self.client,
trace_id=trace_id,
span_queue=span_queue,
)