Send LlamaIndex traces to Zerobus Ingest
The LlamaIndex observability guide documents LlamaIndex's OpenTelemetry package. This page covers the path through the OpenTelemetry Collector. For the endpoints, the table requirements, and the column reference, see Send data to Zerobus Ingest via the OpenTelemetry Collector.
Maintained by: the LlamaIndex open-source project, in the run-llama/llama_index repository.
Your LlamaIndex app sends its spans over OpenTelemetry Protocol (OTLP) to a Collector on the same host. The Collector's oauth2client extension gets an OAuth token from a Databricks service principal, refreshes it before it expires, and writes the spans to a Zerobus Ingest table. The app needs no token code, and you don't need to run a message bus between the app and the lakehouse.
When to use this path
Use the OpenTelemetry Collector path when any of the following apply:
- Your app runs longer than one hour, so a static token would expire during the run.
- You want the app to send OTLP without credentials, and the Databricks service principal's secret to live in one place.
- You trace LlamaIndex queries and want the span tree in a Delta table.
Otherwise, configure the OpenTelemetry SDK to send OTLP directly. See Configure OpenTelemetry (OTLP) clients to send data to Unity Catalog.
LlamaIndex's OpenTelemetry package emits spans only. This page covers one table, <catalog>.<schema>.<prefix>_otel_spans.
How it works
The LlamaIndex package turns each LlamaIndex operation into a span, such as a query or a large language model (LLM) call. For a query engine from index.as_query_engine() in llama-index-core 0.14.26, each query is one trace: its root span is RetrieverQueryEngine.query, and the other spans are its descendants. The app's OTLP/HTTP exporter sends the spans to the Collector, which batches them.
The spans' payload is in the events column. In llama-index-observability-otel 0.8.0, the attributes column is empty, and each event carries its own data. The LLM event (LLMCompletionStartEvent) holds the prompt, including the retrieved text. If your prompts or documents contain sensitive data, that data goes to the table.
The Collector holds spans in memory until it exports them. If the Collector stops before it exports them, you lose those spans. Zerobus Ingest's delivery guarantee doesn't cover spans that haven't reached it. See How it works.
Requirements
Before you start, make sure you have the following:
- A workspace in a region that supports Zerobus Ingest. See Availability.
- A managed Delta table that meets the Table requirements. The table definition in Create the spans table and grant access meets them.
- A Databricks Runtime version with variant shredding support, to create the table. The table definition turns on variant shredding. See Use variant shredding to optimize performance for the minimum version.
- A Databricks service principal with an OAuth secret that has
all-apisaccess, which is the default, and the Workspace access entitlement. An OAuth token can't exceed its secret's scopes, so a secret with narrower scopes can't get theall-apistoken that the Collector requests. Scopes can't change after a secret is created, so generate a new secret if the existing one is narrower. See Scoped OAuth secrets and Configure authentication. - The Databricks service principal needs
USE CATALOGon the catalog,USE SCHEMAon the schema, andMODIFYandSELECTon the spans table. - Access to run SQL in Databricks SQL, with permission to create tables in the schema and to grant privileges on them.
- The OpenTelemetry Collector Contrib distribution, v0.165.0. The
oauth2clientextension is in Contrib, not in the core distribution. - Python 3.11 and above with
pip, for the app. - A LlamaIndex app with its own LLM and embedding models configured. The steps on this page only add tracing.
Set up LlamaIndex tracing
To send LlamaIndex traces to Zerobus Ingest, create the spans table, set up the Collector, and point your app at it.
Create the spans table and grant access
Replace <catalog>.<schema>.<prefix> with your catalog, schema, and table prefix, and run the statement in Databricks SQL.
CREATE TABLE <catalog>.<schema>.<prefix>_otel_spans (
record_id STRING,
time TIMESTAMP,
date DATE,
service_name STRING,
trace_id STRING,
span_id STRING,
trace_state STRING,
parent_span_id STRING,
flags INT,
name STRING,
kind STRING,
start_time_unix_nano LONG,
end_time_unix_nano LONG,
attributes VARIANT,
dropped_attributes_count INT,
events ARRAY<STRUCT<
time_unix_nano: LONG,
name: STRING,
attributes: VARIANT,
dropped_attributes_count: INT
>>,
dropped_events_count INT,
links ARRAY<STRUCT<
trace_id: STRING,
span_id: STRING,
trace_state: STRING,
attributes: VARIANT,
dropped_attributes_count: INT,
flags: INT
>>,
dropped_links_count INT,
status STRUCT<
message: STRING,
code: STRING
>,
resource STRUCT<
attributes: VARIANT,
dropped_attributes_count: INT
>,
resource_schema_url STRING,
instrumentation_scope STRUCT<
name: STRING,
version: STRING,
attributes: VARIANT,
dropped_attributes_count: INT
>,
span_schema_url STRING
) USING DELTA
CLUSTER BY (time, service_name, trace_id)
TBLPROPERTIES (
'otel.schemaVersion' = 'v2',
'delta.checkpointPolicy' = 'classic',
'delta.enableVariantShredding' = 'true', -- optional
'delta.feature.variantShredding' = 'supported', -- optional
'delta.feature.variantType' = 'supported' -- optional
);
Grant the Databricks service principal access. Replace <service-principal-uuid> with its application ID:
GRANT USE CATALOG ON CATALOG <catalog> TO `<service-principal-uuid>`;
GRANT USE SCHEMA ON SCHEMA <catalog>.<schema> TO `<service-principal-uuid>`;
GRANT MODIFY, SELECT ON TABLE <catalog>.<schema>.<prefix>_otel_spans TO `<service-principal-uuid>`;
Install LlamaIndex and the OTLP exporter
Install the pinned versions of the LlamaIndex OpenTelemetry package and the OTLP/HTTP exporter in the app's environment:
pip install llama-index-observability-otel==0.8.0 opentelemetry-exporter-otlp-proto-http==1.45.2
This command doesn't install or change llama-index-core, because the tracing package doesn't depend on it. If your app doesn't have llama-index-core yet, install version 0.14.26 with pip install llama-index-core==0.14.26.
Install the Collector Contrib
Download the Contrib v0.165.0 archive for your platform from the OpenTelemetry Collector releases page, along with the .sha256 file published next to it. Before you extract the archive, compare its SHA-256 hash with the hash in that file. Then extract the archive and check that the binary has the oauth2client extension:
tar -xzf otelcol-contrib_0.165.0_linux_amd64.tar.gz
./otelcol-contrib --version
./otelcol-contrib components | grep oauth2client
Create the Collector configuration
Save this configuration as config.yaml. It has one OTLP receiver for the app, one batch processor, and one traces pipeline to the spans table.
extensions:
oauth2client/spans:
client_id: ${env:DATABRICKS_CLIENT_ID}
client_secret: ${env:DATABRICKS_CLIENT_SECRET}
token_url: ${env:DATABRICKS_WORKSPACE_URL}/oidc/v1/token
scopes: ['all-apis']
endpoint_params:
resource: 'api://databricks/workspaces/${env:WORKSPACE_ID}/zerobusDirectWriteApi'
authorization_details:
- '[{"type":"unity_catalog_privileges","privileges":["USE CATALOG"],"object_type":"CATALOG","object_full_path":"${env:CATALOG}"},{"type":"unity_catalog_privileges","privileges":["USE SCHEMA"],"object_type":"SCHEMA","object_full_path":"${env:CATALOG}.${env:SCHEMA}"},{"type":"unity_catalog_privileges","privileges":["SELECT","MODIFY"],"object_type":"TABLE","object_full_path":"${env:CATALOG}.${env:SCHEMA}.${env:TABLE_PREFIX}_otel_spans"}]'
exporters:
otlp/spans:
endpoint: ${env:ZEROBUS_ENDPOINT}:443
auth:
authenticator: oauth2client/spans
headers:
x-databricks-zerobus-table-name: '${env:CATALOG}.${env:SCHEMA}.${env:TABLE_PREFIX}_otel_spans'
receivers:
otlp:
protocols:
grpc:
endpoint: 127.0.0.1:4317
http:
endpoint: 127.0.0.1:4318
processors:
batch:
timeout: 5s
send_batch_size: 10
service:
extensions: [oauth2client/spans]
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [otlp/spans]
The OTLP receiver has no authentication, so keep it on 127.0.0.1. Then only applications on the same host can send to it. A receiver that other hosts must reach needs TLS and an authenticator on the otlp receiver, plus a network policy that limits access to ports 4317 and 4318.
Set these variables in the shell where you start the Collector:
Variable | Value |
|---|---|
| The Databricks service principal's application ID |
| The Databricks service principal's OAuth secret |
| Your workspace URL, |
| Your workspace ID, |
| Your Zerobus Ingest endpoint host, without |
| The catalog, schema, and table prefix from Create the spans table and grant access |
Your Zerobus Ingest endpoint host is <workspace-id>.zerobus.<region>.gcp.databricks.com.
Start the Collector
Start the Collector with the configuration from Create the Collector configuration:
./otelcol-contrib --config=config.yaml
The log ends with Everything is ready. Begin running and processing data. The Collector also logs "otlp" alias is deprecated; use "otlp_grpc" instead. The configuration runs with that warning.
Point the app at the Collector
Set the span exporter to the Collector's OTLP/HTTP endpoint. Without an exporter, LlamaIndex's OpenTelemetry package writes spans to the console and sends nothing to the Collector.
from llama_index.observability.otel import LlamaIndexOpenTelemetry
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
instrumentor = LlamaIndexOpenTelemetry(
service_name_or_resource="my-rag-app",
span_exporter=OTLPSpanExporter(endpoint="http://127.0.0.1:4318/v1/traces"),
)
instrumentor.start_registering()
# Build your index and query engine as usual. Every LlamaIndex call after
# start_registering() produces spans.
Call start_registering() one time, before you build the index or run any query.
Run the app and query the table
Run your app, then query the spans table. Rows can take a minute or two to appear:
SELECT name, count(*) AS spans, count(DISTINCT trace_id) AS traces
FROM <catalog>.<schema>.<prefix>_otel_spans
WHERE service_name = 'my-rag-app'
GROUP BY name
ORDER BY spans DESC;
For a query engine from index.as_query_engine() in llama-index-core 0.14.26, each LlamaIndex query produces one RetrieverQueryEngine.query root span. Its descendant spans include VectorIndexRetriever.retrieve and the embedding and LLM calls.
Troubleshooting
Symptom | Cause | Fix |
|---|---|---|
No rows in the spans table, and the Collector logs a permission error | The Databricks service principal is missing one of the grants. | Run the grant statements in Create the spans table and grant access. |
The app logs | The Collector was unreachable for longer than the app's exporter retries. The spans in the batch that failed are dropped. | Keep the Collector running while the app runs. Restart the Collector between runs, not during one. |
The Collector logs | The Collector's export call to the Zerobus Ingest endpoint didn't finish within the exporter's timeout. | The Collector retries the batch. If the error repeats, check that the host can reach the Zerobus Ingest endpoint on port |
The Collector returns HTTP | A span in the request has a trace ID or span ID with the wrong length. In an OTLP/HTTP JSON request, one bad span rejects the whole request, so the valid spans in it aren't stored. | Check any code that sends spans yourself. The LlamaIndex spans in Point the app at the Collector have valid IDs. |