Get the Current Span/Context and Tracer

Sometimes it's helpful to access whatever the current span is at a point in time so that you can enrich it with more information.

from opentelemetry import trace

current_span = trace.get_current_span()
# enrich 'current_span' with some information

Get Current Tracer

The tracer in OTEL can be used to create spans.

The following is used to get the tracer:

tracer = trace.get_tracer(__name__)

# Start a new span for the tool function handling
with tracer.start_as_current_span("HandleFunctionCall", attributes={
    SpanAttributes.OPENINFERENCE_SPAN_KIND: OpenInferenceSpanKindValues.TOOL.value,
    ToolCallAttributes.TOOL_CALL_FUNCTION_NAME: function_call_name,
    ToolCallAttributes.TOOL_CALL_FUNCTION_ARGUMENTS_JSON: str(arguments),
    SpanAttributes.INPUT_VALUE: function_call_name
})

The

Last updated

Copyright © 2023 Arize AI, Inc