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
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 |
Supported Span Types
| Span Type | Attributes Set | Description |
|---|---|---|
WorkflowSpan | gen_ai.system | Base span with Galileo system identifier |
RetrieverSpan | gen_ai.system, db.operation, gen_ai.input.messages, gen_ai.output.messages | Retriever span with search operation details and document results |
Additional span types (LLM spans, Tool spans, Agent spans) will be added in future releases to provide richer semantic attributes for different operation types.
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. - Use
RetrieverSpanfor search operations — This captures document context with the correct semantic attributes. - Add custom attributes — Use the yielded span to add operation-specific attributes.
- Set
RetrieverSpanoutput 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.