File tree Expand file tree Collapse file tree 4 files changed +37
-11
lines changed Expand file tree Collapse file tree 4 files changed +37
-11
lines changed Original file line number Diff line number Diff line change 92
92
handoff_span ,
93
93
mcp_tools_span ,
94
94
set_trace_processors ,
95
+ set_trace_provider ,
95
96
set_tracing_disabled ,
96
97
set_tracing_export_api_key ,
97
98
speech_group_span ,
@@ -221,6 +222,7 @@ def enable_verbose_stdout_logging():
221
222
"guardrail_span" ,
222
223
"handoff_span" ,
223
224
"set_trace_processors" ,
225
+ "set_trace_provider" ,
224
226
"set_tracing_disabled" ,
225
227
"speech_group_span" ,
226
228
"transcription_span" ,
Original file line number Diff line number Diff line change 18
18
)
19
19
from .processor_interface import TracingProcessor
20
20
from .processors import default_exporter , default_processor
21
- from .setup import GLOBAL_TRACE_PROVIDER
21
+ from .setup import GLOBAL_TRACE_PROVIDER , set_trace_provider
22
22
from .span_data import (
23
23
AgentSpanData ,
24
24
CustomSpanData ,
49
49
"handoff_span" ,
50
50
"response_span" ,
51
51
"set_trace_processors" ,
52
+ "set_trace_provider" ,
52
53
"set_tracing_disabled" ,
53
54
"trace" ,
54
55
"Trace" ,
Original file line number Diff line number Diff line change 2
2
3
3
import os
4
4
import threading
5
+ import uuid
6
+ from datetime import datetime , timezone
5
7
from typing import Any
6
8
7
9
from ..logger import logger
@@ -118,6 +120,22 @@ def set_disabled(self, disabled: bool) -> None:
118
120
"""
119
121
self ._disabled = disabled
120
122
123
+ def time_iso (self ) -> str :
124
+ """Return the current time in ISO 8601 format."""
125
+ return datetime .now (timezone .utc ).isoformat ()
126
+
127
+ def gen_trace_id (self ) -> str :
128
+ """Generate a new trace ID."""
129
+ return f"trace_{ uuid .uuid4 ().hex } "
130
+
131
+ def gen_span_id (self ) -> str :
132
+ """Generate a new span ID."""
133
+ return f"span_{ uuid .uuid4 ().hex [:24 ]} "
134
+
135
+ def gen_group_id (self ) -> str :
136
+ """Generate a new group ID."""
137
+ return f"group_{ uuid .uuid4 ().hex [:24 ]} "
138
+
121
139
def create_trace (
122
140
self ,
123
141
name : str ,
@@ -212,3 +230,9 @@ def shutdown(self) -> None:
212
230
213
231
214
232
GLOBAL_TRACE_PROVIDER = TraceProvider ()
233
+
234
+
235
+ def set_trace_provider (provider : TraceProvider ) -> None :
236
+ """Set the global trace provider used by tracing utilities."""
237
+ global GLOBAL_TRACE_PROVIDER
238
+ GLOBAL_TRACE_PROVIDER = provider
Original file line number Diff line number Diff line change 1
- import uuid
2
- from datetime import datetime , timezone
1
+ from .setup import GLOBAL_TRACE_PROVIDER
3
2
4
3
5
4
def time_iso () -> str :
6
- """Returns the current time in ISO 8601 format."""
7
- return datetime . now ( timezone . utc ). isoformat ()
5
+ """Return the current time in ISO 8601 format."""
6
+ return GLOBAL_TRACE_PROVIDER . time_iso ()
8
7
9
8
10
9
def gen_trace_id () -> str :
11
- """Generates a new trace ID."""
12
- return f"trace_ { uuid . uuid4 (). hex } "
10
+ """Generate a new trace ID."""
11
+ return GLOBAL_TRACE_PROVIDER . gen_trace_id ()
13
12
14
13
15
14
def gen_span_id () -> str :
16
- """Generates a new span ID."""
17
- return f"span_ { uuid . uuid4 (). hex [: 24 ] } "
15
+ """Generate a new span ID."""
16
+ return GLOBAL_TRACE_PROVIDER . gen_span_id ()
18
17
19
18
20
19
def gen_group_id () -> str :
21
- """Generates a new group ID."""
22
- return f"group_ { uuid . uuid4 (). hex [: 24 ] } "
20
+ """Generate a new group ID."""
21
+ return GLOBAL_TRACE_PROVIDER . gen_group_id ()
You can’t perform that action at this time.
0 commit comments