4
4
from typing import TYPE_CHECKING , Any
5
5
6
6
from ..logger import logger
7
- from .setup import GLOBAL_TRACE_PROVIDER
7
+ from .setup import get_trace_provider
8
8
from .span_data import (
9
9
AgentSpanData ,
10
10
CustomSpanData ,
@@ -56,13 +56,13 @@ def trace(
56
56
Returns:
57
57
The newly created trace object.
58
58
"""
59
- current_trace = GLOBAL_TRACE_PROVIDER .get_current_trace ()
59
+ current_trace = get_trace_provider () .get_current_trace ()
60
60
if current_trace :
61
61
logger .warning (
62
62
"Trace already exists. Creating a new trace, but this is probably a mistake."
63
63
)
64
64
65
- return GLOBAL_TRACE_PROVIDER .create_trace (
65
+ return get_trace_provider () .create_trace (
66
66
name = workflow_name ,
67
67
trace_id = trace_id ,
68
68
group_id = group_id ,
@@ -73,12 +73,12 @@ def trace(
73
73
74
74
def get_current_trace () -> Trace | None :
75
75
"""Returns the currently active trace, if present."""
76
- return GLOBAL_TRACE_PROVIDER .get_current_trace ()
76
+ return get_trace_provider () .get_current_trace ()
77
77
78
78
79
79
def get_current_span () -> Span [Any ] | None :
80
80
"""Returns the currently active span, if present."""
81
- return GLOBAL_TRACE_PROVIDER .get_current_span ()
81
+ return get_trace_provider () .get_current_span ()
82
82
83
83
84
84
def agent_span (
@@ -108,7 +108,7 @@ def agent_span(
108
108
Returns:
109
109
The newly created agent span.
110
110
"""
111
- return GLOBAL_TRACE_PROVIDER .create_span (
111
+ return get_trace_provider () .create_span (
112
112
span_data = AgentSpanData (name = name , handoffs = handoffs , tools = tools , output_type = output_type ),
113
113
span_id = span_id ,
114
114
parent = parent ,
@@ -141,7 +141,7 @@ def function_span(
141
141
Returns:
142
142
The newly created function span.
143
143
"""
144
- return GLOBAL_TRACE_PROVIDER .create_span (
144
+ return get_trace_provider () .create_span (
145
145
span_data = FunctionSpanData (name = name , input = input , output = output ),
146
146
span_id = span_id ,
147
147
parent = parent ,
@@ -183,7 +183,7 @@ def generation_span(
183
183
Returns:
184
184
The newly created generation span.
185
185
"""
186
- return GLOBAL_TRACE_PROVIDER .create_span (
186
+ return get_trace_provider () .create_span (
187
187
span_data = GenerationSpanData (
188
188
input = input ,
189
189
output = output ,
@@ -215,7 +215,7 @@ def response_span(
215
215
trace/span as the parent.
216
216
disabled: If True, we will return a Span but the Span will not be recorded.
217
217
"""
218
- return GLOBAL_TRACE_PROVIDER .create_span (
218
+ return get_trace_provider () .create_span (
219
219
span_data = ResponseSpanData (response = response ),
220
220
span_id = span_id ,
221
221
parent = parent ,
@@ -246,7 +246,7 @@ def handoff_span(
246
246
Returns:
247
247
The newly created handoff span.
248
248
"""
249
- return GLOBAL_TRACE_PROVIDER .create_span (
249
+ return get_trace_provider () .create_span (
250
250
span_data = HandoffSpanData (from_agent = from_agent , to_agent = to_agent ),
251
251
span_id = span_id ,
252
252
parent = parent ,
@@ -278,7 +278,7 @@ def custom_span(
278
278
Returns:
279
279
The newly created custom span.
280
280
"""
281
- return GLOBAL_TRACE_PROVIDER .create_span (
281
+ return get_trace_provider () .create_span (
282
282
span_data = CustomSpanData (name = name , data = data or {}),
283
283
span_id = span_id ,
284
284
parent = parent ,
@@ -306,7 +306,7 @@ def guardrail_span(
306
306
trace/span as the parent.
307
307
disabled: If True, we will return a Span but the Span will not be recorded.
308
308
"""
309
- return GLOBAL_TRACE_PROVIDER .create_span (
309
+ return get_trace_provider () .create_span (
310
310
span_data = GuardrailSpanData (name = name , triggered = triggered ),
311
311
span_id = span_id ,
312
312
parent = parent ,
@@ -344,7 +344,7 @@ def transcription_span(
344
344
Returns:
345
345
The newly created speech-to-text span.
346
346
"""
347
- return GLOBAL_TRACE_PROVIDER .create_span (
347
+ return get_trace_provider () .create_span (
348
348
span_data = TranscriptionSpanData (
349
349
input = input ,
350
350
input_format = input_format ,
@@ -386,7 +386,7 @@ def speech_span(
386
386
trace/span as the parent.
387
387
disabled: If True, we will return a Span but the Span will not be recorded.
388
388
"""
389
- return GLOBAL_TRACE_PROVIDER .create_span (
389
+ return get_trace_provider () .create_span (
390
390
span_data = SpeechSpanData (
391
391
model = model ,
392
392
input = input ,
@@ -419,7 +419,7 @@ def speech_group_span(
419
419
trace/span as the parent.
420
420
disabled: If True, we will return a Span but the Span will not be recorded.
421
421
"""
422
- return GLOBAL_TRACE_PROVIDER .create_span (
422
+ return get_trace_provider () .create_span (
423
423
span_data = SpeechGroupSpanData (input = input ),
424
424
span_id = span_id ,
425
425
parent = parent ,
@@ -447,7 +447,7 @@ def mcp_tools_span(
447
447
trace/span as the parent.
448
448
disabled: If True, we will return a Span but the Span will not be recorded.
449
449
"""
450
- return GLOBAL_TRACE_PROVIDER .create_span (
450
+ return get_trace_provider () .create_span (
451
451
span_data = MCPListToolsSpanData (server = server , result = result ),
452
452
span_id = span_id ,
453
453
parent = parent ,
0 commit comments