forked from openai/openai-agents-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
123 lines (111 loc) · 3.01 KB
/
__init__.py
File metadata and controls
123 lines (111 loc) · 3.01 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from .config import TracingConfig
from .context import TraceCtxManager
from .create import (
agent_span,
custom_span,
function_span,
generation_span,
get_current_span,
get_current_trace,
guardrail_span,
handoff_span,
mcp_tools_span,
response_span,
speech_group_span,
speech_span,
trace,
transcription_span,
)
from .processor_interface import TracingProcessor
from .processors import default_exporter
from .provider import TraceProvider
from .setup import get_trace_provider, set_trace_provider
from .span_data import (
AgentSpanData,
CustomSpanData,
FunctionSpanData,
GenerationSpanData,
GuardrailSpanData,
HandoffSpanData,
MCPListToolsSpanData,
ResponseSpanData,
SpanData,
SpeechGroupSpanData,
SpeechSpanData,
TranscriptionSpanData,
)
from .spans import Span, SpanError
from .traces import Trace
from .util import gen_span_id, gen_trace_id
__all__ = [
"add_trace_processor",
"agent_span",
"flush_traces",
"custom_span",
"function_span",
"generation_span",
"get_current_span",
"get_current_trace",
"get_trace_provider",
"guardrail_span",
"handoff_span",
"response_span",
"set_trace_processors",
"set_trace_provider",
"set_tracing_disabled",
"TracingConfig",
"TraceCtxManager",
"trace",
"Trace",
"SpanError",
"Span",
"SpanData",
"AgentSpanData",
"CustomSpanData",
"FunctionSpanData",
"GenerationSpanData",
"GuardrailSpanData",
"HandoffSpanData",
"MCPListToolsSpanData",
"ResponseSpanData",
"SpeechGroupSpanData",
"SpeechSpanData",
"TranscriptionSpanData",
"TracingProcessor",
"TraceProvider",
"gen_trace_id",
"gen_span_id",
"speech_group_span",
"speech_span",
"transcription_span",
"mcp_tools_span",
]
def add_trace_processor(span_processor: TracingProcessor) -> None:
"""
Adds a new trace processor. This processor will receive all traces/spans.
"""
get_trace_provider().register_processor(span_processor)
def set_trace_processors(processors: list[TracingProcessor]) -> None:
"""
Set the list of trace processors. This will replace the current list of processors.
"""
get_trace_provider().set_processors(processors)
def set_tracing_disabled(disabled: bool) -> None:
"""
Set whether tracing is globally disabled.
"""
get_trace_provider().set_disabled(disabled)
def set_tracing_export_api_key(api_key: str) -> None:
"""
Set the OpenAI API key for the backend exporter.
"""
default_exporter().set_api_key(api_key)
def flush_traces() -> None:
"""Force an immediate flush of all buffered traces and spans.
Call this at the end of each task in long-running worker processes
(Celery, FastAPI background tasks, RQ, etc.) to ensure traces are
exported to the backend rather than remaining buffered indefinitely.
"""
provider = get_trace_provider()
if hasattr(provider, "force_flush"):
provider.force_flush()