44from typing import TYPE_CHECKING , Any
55
66from ..logger import logger
7- from .setup import GLOBAL_TRACE_PROVIDER
7+ from .setup import get_trace_provider
88from .span_data import (
99 AgentSpanData ,
1010 CustomSpanData ,
@@ -56,13 +56,13 @@ def trace(
5656 Returns:
5757 The newly created trace object.
5858 """
59- current_trace = GLOBAL_TRACE_PROVIDER .get_current_trace ()
59+ current_trace = get_trace_provider () .get_current_trace ()
6060 if current_trace :
6161 logger .warning (
6262 "Trace already exists. Creating a new trace, but this is probably a mistake."
6363 )
6464
65- return GLOBAL_TRACE_PROVIDER .create_trace (
65+ return get_trace_provider () .create_trace (
6666 name = workflow_name ,
6767 trace_id = trace_id ,
6868 group_id = group_id ,
@@ -73,12 +73,12 @@ def trace(
7373
7474def get_current_trace () -> Trace | None :
7575 """Returns the currently active trace, if present."""
76- return GLOBAL_TRACE_PROVIDER .get_current_trace ()
76+ return get_trace_provider () .get_current_trace ()
7777
7878
7979def get_current_span () -> Span [Any ] | None :
8080 """Returns the currently active span, if present."""
81- return GLOBAL_TRACE_PROVIDER .get_current_span ()
81+ return get_trace_provider () .get_current_span ()
8282
8383
8484def agent_span (
@@ -108,7 +108,7 @@ def agent_span(
108108 Returns:
109109 The newly created agent span.
110110 """
111- return GLOBAL_TRACE_PROVIDER .create_span (
111+ return get_trace_provider () .create_span (
112112 span_data = AgentSpanData (name = name , handoffs = handoffs , tools = tools , output_type = output_type ),
113113 span_id = span_id ,
114114 parent = parent ,
@@ -141,7 +141,7 @@ def function_span(
141141 Returns:
142142 The newly created function span.
143143 """
144- return GLOBAL_TRACE_PROVIDER .create_span (
144+ return get_trace_provider () .create_span (
145145 span_data = FunctionSpanData (name = name , input = input , output = output ),
146146 span_id = span_id ,
147147 parent = parent ,
@@ -183,7 +183,7 @@ def generation_span(
183183 Returns:
184184 The newly created generation span.
185185 """
186- return GLOBAL_TRACE_PROVIDER .create_span (
186+ return get_trace_provider () .create_span (
187187 span_data = GenerationSpanData (
188188 input = input ,
189189 output = output ,
@@ -215,7 +215,7 @@ def response_span(
215215 trace/span as the parent.
216216 disabled: If True, we will return a Span but the Span will not be recorded.
217217 """
218- return GLOBAL_TRACE_PROVIDER .create_span (
218+ return get_trace_provider () .create_span (
219219 span_data = ResponseSpanData (response = response ),
220220 span_id = span_id ,
221221 parent = parent ,
@@ -246,7 +246,7 @@ def handoff_span(
246246 Returns:
247247 The newly created handoff span.
248248 """
249- return GLOBAL_TRACE_PROVIDER .create_span (
249+ return get_trace_provider () .create_span (
250250 span_data = HandoffSpanData (from_agent = from_agent , to_agent = to_agent ),
251251 span_id = span_id ,
252252 parent = parent ,
@@ -278,7 +278,7 @@ def custom_span(
278278 Returns:
279279 The newly created custom span.
280280 """
281- return GLOBAL_TRACE_PROVIDER .create_span (
281+ return get_trace_provider () .create_span (
282282 span_data = CustomSpanData (name = name , data = data or {}),
283283 span_id = span_id ,
284284 parent = parent ,
@@ -306,7 +306,7 @@ def guardrail_span(
306306 trace/span as the parent.
307307 disabled: If True, we will return a Span but the Span will not be recorded.
308308 """
309- return GLOBAL_TRACE_PROVIDER .create_span (
309+ return get_trace_provider () .create_span (
310310 span_data = GuardrailSpanData (name = name , triggered = triggered ),
311311 span_id = span_id ,
312312 parent = parent ,
@@ -344,7 +344,7 @@ def transcription_span(
344344 Returns:
345345 The newly created speech-to-text span.
346346 """
347- return GLOBAL_TRACE_PROVIDER .create_span (
347+ return get_trace_provider () .create_span (
348348 span_data = TranscriptionSpanData (
349349 input = input ,
350350 input_format = input_format ,
@@ -386,7 +386,7 @@ def speech_span(
386386 trace/span as the parent.
387387 disabled: If True, we will return a Span but the Span will not be recorded.
388388 """
389- return GLOBAL_TRACE_PROVIDER .create_span (
389+ return get_trace_provider () .create_span (
390390 span_data = SpeechSpanData (
391391 model = model ,
392392 input = input ,
@@ -419,7 +419,7 @@ def speech_group_span(
419419 trace/span as the parent.
420420 disabled: If True, we will return a Span but the Span will not be recorded.
421421 """
422- return GLOBAL_TRACE_PROVIDER .create_span (
422+ return get_trace_provider () .create_span (
423423 span_data = SpeechGroupSpanData (input = input ),
424424 span_id = span_id ,
425425 parent = parent ,
@@ -447,7 +447,7 @@ def mcp_tools_span(
447447 trace/span as the parent.
448448 disabled: If True, we will return a Span but the Span will not be recorded.
449449 """
450- return GLOBAL_TRACE_PROVIDER .create_span (
450+ return get_trace_provider () .create_span (
451451 span_data = MCPListToolsSpanData (server = server , result = result ),
452452 span_id = span_id ,
453453 parent = parent ,
0 commit comments