MCPcopy
hub / github.com/openai/openai-agents-python / custom_span

Function custom_span

src/agents/tracing/create.py:293–322  ·  view source on GitHub ↗

Create a new custom span, to which you can add your own metadata. The span will not be started automatically, you should either do `with custom_span() ...` or call `span.start()` + `span.finish()` manually. Args: name: The name of the custom span. data: Arbitrary structu

(
    name: str,
    data: dict[str, Any] | None = None,
    span_id: str | None = None,
    parent: Trace | Span[Any] | None = None,
    disabled: bool = False,
)

Source from the content-addressed store, hash-verified

291
292
293def custom_span(
294 name: str,
295 data: dict[str, Any] | None = None,
296 span_id: str | None = None,
297 parent: Trace | Span[Any] | None = None,
298 disabled: bool = False,
299) -> Span[CustomSpanData]:
300 """Create a new custom span, to which you can add your own metadata. The span will not be
301 started automatically, you should either do `with custom_span() ...` or call
302 `span.start()` + `span.finish()` manually.
303
304 Args:
305 name: The name of the custom span.
306 data: Arbitrary structured data to associate with the span.
307 span_id: The ID of the span. Optional. If not provided, we will generate an ID. We
308 recommend using `util.gen_span_id()` to generate a span ID, to guarantee that IDs are
309 correctly formatted.
310 parent: The parent span or trace. If not provided, we will automatically use the current
311 trace/span as the parent.
312 disabled: If True, we will return a Span but the Span will not be recorded.
313
314 Returns:
315 The newly created custom span.
316 """
317 return get_trace_provider().create_span(
318 span_data=CustomSpanData(name=name, data=data or {}),
319 span_id=span_id,
320 parent=parent,
321 disabled=disabled,
322 )
323
324
325def guardrail_span(

Calls 3

get_trace_providerFunction · 0.85
CustomSpanDataClass · 0.85
create_spanMethod · 0.45