Skip to main content
The start_galileo_span function provides a context manager for creating OpenTelemetry spans that are automatically enriched with Galileo-specific attributes. This enables seamless observability for custom spans within your application while maintaining compatibility with the broader OpenTelemetry ecosystem.

Prerequisites

Before using start_galileo_span, set up the tracer provider with the Galileo span processor:
Python
Requires the OpenTelemetry extra: pip install galileo[otel]

Environment Variables

Basic Usage

Python

Tool Spans

Use ToolSpan for tool/function execution operations. This captures tool invocation details including the tool name, arguments, and results.
Python
When a ToolSpan is provided, the following attributes are set automatically:

Retriever Spans

Use RetrieverSpan for search and retrieval operations. This automatically captures query input and document output with the correct semantic attributes.
Python
When a RetrieverSpan is provided, the following attributes are set automatically:

Workflow Spans

Use WorkflowSpan for higher-level orchestration units that coordinate multiple sub-operations, such as chains, pipelines, or multi-step processes.
Python
When a WorkflowSpan is provided, the following attributes are set automatically:

Supported Span Types

Function Signature

Python
Returns: A context manager yielding an OpenTelemetry Span object.

Execution Flow

When start_galileo_span is called, the following steps occur:
  1. The TracerProvider is retrieved (from the context variable or via trace.get_tracer_provider())
  2. A tracer named "galileo-tracer" is created
  3. An OpenTelemetry span is started using the galileo_span.name
  4. The span is yielded for your code to execute
  5. On exit, Galileo-specific attributes are set (e.g., gen_ai.system = "galileo-otel" and any span-type-specific attributes)

Complete Example

Python

Best Practices

  • Initialize TracerProvider early — Set up the GalileoSpanProcessor at application startup.
  • Use descriptive span names — Provide meaningful names in Span for better observability.
  • Choose the right span type — Use ToolSpan for function calls, RetrieverSpan for search operations, and WorkflowSpan for orchestration.
  • Add custom attributes — Use the yielded span to add operation-specific attributes.
  • Set span output before exiting — The output must be set before the context manager exits for proper attribute capture.
  • Nested spans are supported — Child spans inherit the parent context automatically through OpenTelemetry’s context propagation.