Skip to main content

Send data to Zerobus Ingest via Grafana Alloy

info

The token handling comes from the otelcol.auth.oauth2 component in Grafana Alloy. For the OTLP exporter, see otelcol.exporter.otlp.

Maintained by: Grafana Labs, in the grafana/alloy repository.

Your application sends plain OTLP to Grafana Alloy on the same host. Alloy's otelcol.auth.oauth2 component gets an OAuth token from a service principal, replaces the token when it expires, and exports each signal to its own table in Zerobus Ingest. The application needs no token code, and you don't need to run a message bus between the application and the lakehouse.

When to use Alloy​

Choose Alloy when any of these apply. Otherwise, send OTLP directly with a static token, as the configure page describes.

  • Your service runs for longer than one hour, so a static token would expire during the run.
  • Your team already runs Grafana Alloy and wants to add Zerobus Ingest as an OTLP destination with a configuration change.
  • You send traces, logs, and metrics, and want one configuration for all three.

How it works​

The configuration has one OTLP receiver on 127.0.0.1:4317, one batch processor, and three exporters, one each for traces, logs, and metrics. Each exporter has its own otelcol.auth.oauth2 component, because the token is scoped to the table that exporter writes to. The x-databricks-zerobus-table-name header names the target table, and each request targets a single table. The component replaces the token when it expires, or earlier if you set expiry_buffer, so a long-running Alloy keeps exporting past the token's lifetime.

Zerobus Ingest can deliver a record more than one time when the client retries records that aren't acknowledged, so a retry can duplicate a row.

Alloy retries exports that fail with a retryable error. An authentication failure isn't retried, so Alloy drops that data. Its in-memory buffers can also lose accepted data (see Troubleshooting).

Requirements​

  • A workspace with Unity Catalog in a supported region. The three tables must meet the Zerobus Ingest table requirements.
  • A service principal with an OAuth secret and the grants in Step 1. See Create a service principal and grant permissions.
  • Databricks Runtime 17.3 or above to create and query these tables, because the Step 1 table definitions turn on variant shredding, which needs 17.3. To query the tables from Databricks Runtime 15.3 to 17.2, create them on a runtime below 17.3 and omit the optional shredding properties. See Use variant shredding.
  • Grafana Alloy, installed from the Alloy install guide, with the otelcol.auth.oauth2 component.
  • An application that exports OTLP over gRPC.
  • Python 3 with pip in the application's environment, for the Step 5 commands.

Step 1: Create the three tables and grant access​

Replace <catalog>.<schema>.<prefix> with your catalog, schema, and table prefix. If readers on Databricks Runtime 15.3 to 17.2 need to query the three tables, create them on a cluster instead, as the reader requirement in Requirements describes. Otherwise, run the statements in Create target tables in Databricks SQL. Zerobus Ingest supports only ASCII letters, digits, and underscores in table and column names, so use only those in <prefix>. See Protobuf schema.

Grant the service principal access. Replace <service-principal-uuid> with its application ID:

SQL
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>`;
GRANT MODIFY, SELECT ON TABLE <catalog>.<schema>.<prefix>_otel_logs TO `<service-principal-uuid>`;
GRANT MODIFY, SELECT ON TABLE <catalog>.<schema>.<prefix>_otel_metrics TO `<service-principal-uuid>`;

Step 2: Install Alloy​

Install Grafana Alloy with the install guide for your platform. Check the installed version:

Bash
alloy --version

Step 3: Create the Alloy configuration​

Set these variables in the environment where you start Alloy:

Variable

Value

DATABRICKS_CLIENT_ID

The service principal's application ID (<service-principal-uuid>)

DATABRICKS_CLIENT_SECRET

The service principal's OAuth secret

WORKSPACE_URL

Your workspace URL with https:// (https://<workspace-url>)

WORKSPACE_ID

Your workspace ID (<workspace-id>)

ZEROBUS_ENDPOINT

Your Zerobus Ingest endpoint host, without https:// or the port

CATALOG, SCHEMA, TABLE_PREFIX

Your catalog, schema, and table prefix (<catalog>, <schema>, <prefix>)

Variable

Value

DATABRICKS_CLIENT_ID

The service principal's application ID (<service-principal-uuid>)

DATABRICKS_CLIENT_SECRET

The service principal's OAuth secret

WORKSPACE_URL

Your workspace URL with https:// (https://<workspace-url>)

WORKSPACE_ID

Your workspace ID (<workspace-id>)

ZEROBUS_ENDPOINT

Your Zerobus Ingest endpoint host, without https:// or the port

CATALOG, SCHEMA, TABLE_PREFIX

Your catalog, schema, and table prefix (<catalog>, <schema>, <prefix>)

WORKSPACE_URL includes https:// on this page, and the token URL in Step 3 uses it as written. The configure page's WORKSPACE_URL has no scheme, so don't copy that value into this page's configuration. For that page, see Configure OpenTelemetry (OTLP) clients.

To find your values, see Get your workspace URL and Zerobus Ingest endpoint.

Your endpoint host is <workspace-id>.zerobus.<region>.gcp.databricks.com.

Save this as config.alloy. It follows the gRPC configuration on the configure page, written in Alloy's configuration syntax. The file reads its values from the environment with sys.env(), so the same file works in every cloud. The receiver listens on 127.0.0.1 only, so only applications on the same host can send to it. The receiver has no authentication, so don't bind it to a wider address. It accepts gRPC messages up to 10 MiB (max_recv_msg_size, instead of the 4 MiB default), the same as the record size limit. The batch processor counts records, not bytes, so it can combine requests into one export larger than 10 MiB. The steps assume a host install. In a container, 127.0.0.1 is the container's own loopback, and that setup isn't covered here.

Alloy
// Grafana Alloy: OTLP in on loopback, token refresh by otelcol.auth.oauth2, OTLP/gRPC out to Zerobus Ingest.
// One oauth2 extension and one exporter per signal, because each token is scoped to one table.
// Values come from the environment (sys.env), so no secret is written in this file.

otelcol.receiver.otlp "default" {
grpc {
endpoint = "127.0.0.1:4317"
// 10 MiB matches the Zerobus Ingest record size limit (10,485,760 bytes). The default is 4 MiB.
max_recv_msg_size = "10MiB"
}

output {
traces = [otelcol.processor.batch.default.input]
logs = [otelcol.processor.batch.default.input]
metrics = [otelcol.processor.batch.default.input]
}
}

otelcol.processor.batch "default" {
output {
traces = [otelcol.exporter.otlp.spans.input]
logs = [otelcol.exporter.otlp.logs.input]
metrics = [otelcol.exporter.otlp.metrics.input]
}
}

otelcol.auth.oauth2 "spans" {
client_id = sys.env("DATABRICKS_CLIENT_ID")
client_secret = sys.env("DATABRICKS_CLIENT_SECRET")
token_url = sys.env("WORKSPACE_URL") + "/oidc/v1/token"
scopes = ["all-apis"]

endpoint_params = {
"resource" = ["api://databricks/workspaces/" + sys.env("WORKSPACE_ID") + "/zerobusDirectWriteApi"],
"authorization_details" = [
"[{\"type\":\"unity_catalog_privileges\",\"privileges\":[\"USE CATALOG\"],\"object_type\":\"CATALOG\",\"object_full_path\":\"" + sys.env("CATALOG") + "\"}," +
"{\"type\":\"unity_catalog_privileges\",\"privileges\":[\"USE SCHEMA\"],\"object_type\":\"SCHEMA\",\"object_full_path\":\"" + sys.env("CATALOG") + "." + sys.env("SCHEMA") + "\"}," +
"{\"type\":\"unity_catalog_privileges\",\"privileges\":[\"SELECT\",\"MODIFY\"],\"object_type\":\"TABLE\",\"object_full_path\":\"" + sys.env("CATALOG") + "." + sys.env("SCHEMA") + "." + sys.env("TABLE_PREFIX") + "_otel_spans\"}]",
],
}
}

otelcol.auth.oauth2 "logs" {
client_id = sys.env("DATABRICKS_CLIENT_ID")
client_secret = sys.env("DATABRICKS_CLIENT_SECRET")
token_url = sys.env("WORKSPACE_URL") + "/oidc/v1/token"
scopes = ["all-apis"]

endpoint_params = {
"resource" = ["api://databricks/workspaces/" + sys.env("WORKSPACE_ID") + "/zerobusDirectWriteApi"],
"authorization_details" = [
"[{\"type\":\"unity_catalog_privileges\",\"privileges\":[\"USE CATALOG\"],\"object_type\":\"CATALOG\",\"object_full_path\":\"" + sys.env("CATALOG") + "\"}," +
"{\"type\":\"unity_catalog_privileges\",\"privileges\":[\"USE SCHEMA\"],\"object_type\":\"SCHEMA\",\"object_full_path\":\"" + sys.env("CATALOG") + "." + sys.env("SCHEMA") + "\"}," +
"{\"type\":\"unity_catalog_privileges\",\"privileges\":[\"SELECT\",\"MODIFY\"],\"object_type\":\"TABLE\",\"object_full_path\":\"" + sys.env("CATALOG") + "." + sys.env("SCHEMA") + "." + sys.env("TABLE_PREFIX") + "_otel_logs\"}]",
],
}
}

otelcol.auth.oauth2 "metrics" {
client_id = sys.env("DATABRICKS_CLIENT_ID")
client_secret = sys.env("DATABRICKS_CLIENT_SECRET")
token_url = sys.env("WORKSPACE_URL") + "/oidc/v1/token"
scopes = ["all-apis"]

endpoint_params = {
"resource" = ["api://databricks/workspaces/" + sys.env("WORKSPACE_ID") + "/zerobusDirectWriteApi"],
"authorization_details" = [
"[{\"type\":\"unity_catalog_privileges\",\"privileges\":[\"USE CATALOG\"],\"object_type\":\"CATALOG\",\"object_full_path\":\"" + sys.env("CATALOG") + "\"}," +
"{\"type\":\"unity_catalog_privileges\",\"privileges\":[\"USE SCHEMA\"],\"object_type\":\"SCHEMA\",\"object_full_path\":\"" + sys.env("CATALOG") + "." + sys.env("SCHEMA") + "\"}," +
"{\"type\":\"unity_catalog_privileges\",\"privileges\":[\"SELECT\",\"MODIFY\"],\"object_type\":\"TABLE\",\"object_full_path\":\"" + sys.env("CATALOG") + "." + sys.env("SCHEMA") + "." + sys.env("TABLE_PREFIX") + "_otel_metrics\"}]",
],
}
}

otelcol.exporter.otlp "spans" {
client {
endpoint = sys.env("ZEROBUS_ENDPOINT") + ":443"
auth = otelcol.auth.oauth2.spans.handler
headers = {
"x-databricks-zerobus-table-name" = sys.env("CATALOG") + "." + sys.env("SCHEMA") + "." + sys.env("TABLE_PREFIX") + "_otel_spans",
}
}
}

otelcol.exporter.otlp "logs" {
client {
endpoint = sys.env("ZEROBUS_ENDPOINT") + ":443"
auth = otelcol.auth.oauth2.logs.handler
headers = {
"x-databricks-zerobus-table-name" = sys.env("CATALOG") + "." + sys.env("SCHEMA") + "." + sys.env("TABLE_PREFIX") + "_otel_logs",
}
}
}

otelcol.exporter.otlp "metrics" {
client {
endpoint = sys.env("ZEROBUS_ENDPOINT") + ":443"
auth = otelcol.auth.oauth2.metrics.handler
headers = {
"x-databricks-zerobus-table-name" = sys.env("CATALOG") + "." + sys.env("SCHEMA") + "." + sys.env("TABLE_PREFIX") + "_otel_metrics",
}
}
}

Step 4: Start Alloy​

Run Alloy with the configuration file:

Bash
alloy run config.alloy

When Alloy starts, its log shows Starting GRPC server with endpoint=127.0.0.1:4317. The Alloy UI listens on http://127.0.0.1:12345 by default. If Alloy already runs on this host, see Alloy already runs on this host instead of starting a second instance.

Alloy already runs on this host​

Don't start a second instance with alloy run. Merge the components in config.alloy into the existing configuration, then reload it, for example with an HTTP POST to its /-/reload endpoint, as described in the alloy run reference.

A reload doesn't change the environment that Alloy started with, and sys.env reads that environment. To add the variables to a running Alloy, set them in its service environment and restart Alloy. With systemd, put them in an EnvironmentFile that only root or the Alloy service user can read (mode 0600).

Don't put DATABRICKS_CLIENT_SECRET on an Environment= line in the unit file, because any local user can read unit files and systemctl show output. See the note on secrets under Environment=.

Step 5: Point your application at Alloy​

For a Python application, install the application's own dependencies first, then the OpenTelemetry distribution, the OTLP gRPC exporter, and the logging instrumentation. Run the bootstrap command, which installs instrumentation libraries for the packages in the environment, such as the FastAPI and requests instrumentations. Then run the application with the zero-code command. The example runs a FastAPI application with uvicorn, so the application's dependencies are fastapi and uvicorn:

Bash
pip install opentelemetry-distro opentelemetry-exporter-otlp-proto-grpc opentelemetry-instrumentation-logging
opentelemetry-bootstrap -a install
OTEL_SERVICE_NAME=<service-name> \
OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4317 \
OTEL_EXPORTER_OTLP_PROTOCOL=grpc \
OTEL_TRACES_EXPORTER=otlp \
OTEL_METRICS_EXPORTER=otlp \
OTEL_LOGS_EXPORTER=otlp \
opentelemetry-instrument uvicorn app:app --host 127.0.0.1 --port 8000

Before you run the command, unset any OTEL_EXPORTER_OTLP_* variables that the environment already sets for the endpoint, protocol, or TLS, in particular OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, OTEL_EXPORTER_OTLP_LOGS_ENDPOINT, and their _PROTOCOL and _INSECURE variants. A signal-specific variable takes precedence over the generic OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_PROTOCOL, and OTEL_EXPORTER_OTLP_INSECURE variables (OpenTelemetry exporter specification).

Records written with the standard logging module export through opentelemetry-instrumentation-logging, which the pip install command in this step installs, and its handler is enabled by default. pip install doesn't upgrade a package that's already installed, so in an environment that already has the logging package, run pip install -U opentelemetry-instrumentation-logging before you start the application. The example exports the application's log records. Uvicorn's uvicorn and uvicorn.access loggers don't propagate to the root logger by default, so their records, including access logs, aren't exported unless you configure them to propagate. Other languages use their own OpenTelemetry SDK exporter with the same endpoint and protocol.

Step 6: Query the tables​

After you send traces, the spans query returns one row per span, with service_name set to the value of OTEL_SERVICE_NAME.

SQL
SELECT time, service_name, name, kind FROM <catalog>.<schema>.<prefix>_otel_spans ORDER BY time DESC LIMIT 10;
SELECT time, severity_text, to_json(body) AS body FROM <catalog>.<schema>.<prefix>_otel_logs ORDER BY time DESC LIMIT 10;
SELECT time, name, metric_type FROM <catalog>.<schema>.<prefix>_otel_metrics ORDER BY time DESC LIMIT 10;

Troubleshooting​

Symptom

Cause

Fix

Telemetry is missing after Alloy restarts

Alloy holds accepted data in memory, in the batch processor and the exporter queues. Data that hasn't been exported yet is lost if Alloy stops or crashes, and data the application sends while Alloy is down isn't received.

Expect a gap for the time Alloy is down, and check whether the application's SDK logged export failures. To keep the exporter queue across restarts, set storage on its sending_queue (see otelcol.exporter.otlp). The batch processor has no persistent storage, so only the exporter queue can keep data across a restart.

Data is dropped during a long outage or after the queue fills

The exporter's retry_on_failure gives up after max_elapsed_time, which defaults to 5m. Its sending_queue holds queue_size batches, which defaults to 1,000 per exporter. Behavior during an outage depends on the deployment.

Tune max_elapsed_time and queue_size in otelcol.exporter.otlp for your outage window and memory budget, and add an otelcol.processor.memory_limiter. Choose values for your deployment.

Exports fail or stall while the token endpoint is down or slow

A token request that fails reaches the exporter as Unauthenticated, which Alloy doesn't retry. That covers a refused request, such as one with a wrong DATABRICKS_CLIENT_SECRET, and a token endpoint that is down or times out. otelcol.auth.oauth2 sets no token request timeout by default, because its timeout argument defaults to 0s.

Set timeout on the otelcol.auth.oauth2 component to a value you have verified, and size max_elapsed_time and queue_size for your outage window. The example doesn't set a value. A timeout bounds the wait but doesn't make a token failure retryable, so that export's data is dropped.

Alloy logs Exporting failed. Dropping data. with Unauthenticated and invalid_client

The token request was refused, as with a wrong DATABRICKS_CLIENT_SECRET. Alloy drops the data and doesn't retry it.

Check that DATABRICKS_CLIENT_ID and DATABRICKS_CLIENT_SECRET are the service principal's ID and current secret, and that WORKSPACE_URL is https://<workspace-url>.

The application's SDK logs Failed to export or connection refused

Alloy isn't reachable on 127.0.0.1:4317.

Check that Alloy is running and that the receiver endpoint matches OTEL_EXPORTER_OTLP_ENDPOINT.

Telemetry from the application doesn't reach Alloy, or the SDK tries TLS against the plaintext endpoint

A signal-specific OTEL_EXPORTER_OTLP_* variable from the environment takes precedence over the generic one in Step 5.

Unset the variables that Step 5 lists, then start the application again.

One metric point is missing from a batch, and Alloy logs no error

A point with a timestamp of 0 is dropped, and the other points in the same request land.

Check the timestamps at the source.

Python log records are missing, or Uvicorn access logs are missing

The opentelemetry-instrumentation-logging package isn't installed, or the uvicorn and uvicorn.access loggers don't propagate to the root logger by default.

Install or upgrade the package as in Step 5. To export Uvicorn's logs, configure those loggers to propagate. That isn't covered here.

A config change doesn't take effect after a reload

A reload re-reads config.alloy but not the environment that Alloy started with, and sys.env reads that environment.

Follow Alloy already runs on this host.

Symptom

Cause

Fix

Telemetry is missing after Alloy restarts

Alloy holds accepted data in memory, in the batch processor and the exporter queues. Data that hasn't been exported yet is lost if Alloy stops or crashes, and data the application sends while Alloy is down isn't received.

Expect a gap for the time Alloy is down, and check whether the application's SDK logged export failures. To keep the exporter queue across restarts, set storage on its sending_queue (see otelcol.exporter.otlp). The batch processor has no persistent storage, so only the exporter queue can keep data across a restart.

Data is dropped during a long outage or after the queue fills

The exporter's retry_on_failure gives up after max_elapsed_time, which defaults to 5m. Its sending_queue holds queue_size batches, which defaults to 1,000 per exporter. Behavior during an outage depends on the deployment.

Tune max_elapsed_time and queue_size in otelcol.exporter.otlp for your outage window and memory budget, and add an otelcol.processor.memory_limiter. Choose values for your deployment.

Exports fail or stall while the token endpoint is down or slow

A token request that fails reaches the exporter as Unauthenticated, which Alloy doesn't retry. That covers a refused request, such as one with a wrong DATABRICKS_CLIENT_SECRET, and a token endpoint that is down or times out. otelcol.auth.oauth2 sets no token request timeout by default, because its timeout argument defaults to 0s.

Set timeout on the otelcol.auth.oauth2 component to a value you have verified, and size max_elapsed_time and queue_size for your outage window. The example doesn't set a value. A timeout bounds the wait but doesn't make a token failure retryable, so that export's data is dropped.

Alloy logs Exporting failed. Dropping data. with Unauthenticated and invalid_client

The token request was refused, as with a wrong DATABRICKS_CLIENT_SECRET. Alloy drops the data and doesn't retry it.

Check that DATABRICKS_CLIENT_ID and DATABRICKS_CLIENT_SECRET are the service principal's ID and current secret, and that WORKSPACE_URL is https://<workspace-url>.

The application's SDK logs Failed to export or connection refused

Alloy isn't reachable on 127.0.0.1:4317.

Check that Alloy is running and that the receiver endpoint matches OTEL_EXPORTER_OTLP_ENDPOINT.

Telemetry from the application doesn't reach Alloy, or the SDK tries TLS against the plaintext endpoint

A signal-specific OTEL_EXPORTER_OTLP_* variable from the environment takes precedence over the generic one in Step 5.

Unset the variables that Step 5 lists, then start the application again.

One metric point is missing from a batch, and Alloy logs no error

A point with a timestamp of 0 is dropped, and the other points in the same request land.

Check the timestamps at the source.

Python log records are missing, or Uvicorn access logs are missing

The opentelemetry-instrumentation-logging package isn't installed, or the uvicorn and uvicorn.access loggers don't propagate to the root logger by default.

Install or upgrade the package as in Step 5. To export Uvicorn's logs, configure those loggers to propagate. That isn't covered here.

A config change doesn't take effect after a reload

A reload re-reads config.alloy but not the environment that Alloy started with, and sys.env reads that environment.

Follow Alloy already runs on this host.

Additional resources​