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 usingstart_galileo_span, set up the tracer provider with the Galileo span processor:
Python
Requires the OpenTelemetry extra:
pip install galileo[otel]Environment Variables
| Variable | Description |
|---|---|
GALILEO_PROJECT | Default project name for trace export |
GALILEO_LOG_STREAM | Default Log stream for trace organization |
Basic Usage
Python
Tool Spans
UseToolSpan for tool/function execution operations. This captures tool invocation details including the tool name, arguments, and results.
Python
ToolSpan is provided, the following attributes are set automatically:
| Attribute | Value | Description |
|---|---|---|
gen_ai.operation.name | "execute_tool" | Indicates a tool execution operation |
gen_ai.tool.name | Tool name | Name of the tool being executed |
gen_ai.tool.call.arguments | String | Tool input arguments |
gen_ai.tool.call.result | String | Tool output result |
gen_ai.tool.call.id | String | Unique identifier for the tool call (if provided) |
gen_ai.input.messages | JSON array | Tool input formatted as message |
gen_ai.output.messages | JSON array | Tool output formatted as message |
Retriever Spans
UseRetrieverSpan for search and retrieval operations. This automatically captures query input and document output with the correct semantic attributes.
Python
RetrieverSpan is provided, the following attributes are set automatically:
| Attribute | Value | Description |
|---|---|---|
db.operation | "search" | Indicates a search/retrieval operation |
gen_ai.input.messages | JSON array | User query formatted as input message |
gen_ai.output.messages | JSON array | Retrieved documents formatted as output |
Workflow Spans
UseWorkflowSpan for higher-level orchestration units that coordinate multiple sub-operations, such as chains, pipelines, or multi-step processes.
Python
WorkflowSpan is provided, the following attributes are set automatically:
| Attribute | Value | Description |
|---|---|---|
gen_ai.input.messages | JSON array | Workflow input formatted as user message |
gen_ai.output.messages | JSON array | Workflow output formatted as assistant message or document list |
Supported Span Types
| Span Type | Attributes Set | Description |
|---|---|---|
WorkflowSpan | gen_ai.system, gen_ai.input.messages, gen_ai.output.messages | Orchestration span for pipelines and multi-step processes |
ToolSpan | gen_ai.system, gen_ai.operation.name, gen_ai.tool.name, gen_ai.tool.call.*, gen_ai.input.messages, gen_ai.output.messages | Tool execution span with invocation details |
RetrieverSpan | gen_ai.system, db.operation, gen_ai.input.messages, gen_ai.output.messages | Retriever span with search operation details and document results |
Function Signature
Python
| Parameter | Type | Required | Description |
|---|---|---|---|
galileo_span | Span | Yes | A Galileo span object containing the span name and optional metadata |
Span object.
Execution Flow
Whenstart_galileo_span is called, the following steps occur:
- The
TracerProvideris retrieved (from the context variable or viatrace.get_tracer_provider()) - A tracer named
"galileo-tracer"is created - An OpenTelemetry span is started using the
galileo_span.name - The span is yielded for your code to execute
- 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
TracerProviderearly — Set up theGalileoSpanProcessorat application startup. - Use descriptive span names — Provide meaningful names in
Spanfor better observability. - Choose the right span type — Use
ToolSpanfor function calls,RetrieverSpanfor search operations, andWorkflowSpanfor 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.