---
title: Configure telemetry for Databricks Apps
description: Send Databricks app traces, logs, and metrics to Unity Catalog tables over OpenTelemetry. Covers setup, instrumentation, queries, limits, and pricing.
canonical_url: https://docs.databricks.com/gcp/en/dev-tools/databricks-apps/observability
---

# Configure telemetry for Databricks Apps

Databricks Apps telemetry collects traces, logs, and metrics and persists them to Unity Catalog tables using the OpenTelemetry (OTel) protocol. After you enable app telemetry, Databricks automatically captures system logs and usage events such as user login and direct API requests. You can also add custom instrumentation using the OpenTelemetry SDK for your framework.

## <a id="otel-requirements" />Requirements

* Your workspace must be in a supported region: `asia-northeast1`, `asia-south1`, `asia-southeast1`, `us-east1`, `us-east4`, `us-west1`, `us-central1`, `europe-west2`, `europe-west3`.

- To create new telemetry target tables in Unity Catalog, you need `CREATE TABLE` on the schema, and one of the following:
  * `CAN MANAGE` permissions on the target catalog and schema.
  * The app's [service principal](https://docs.databricks.com/gcp/en/dev-tools/databricks-apps/auth.md#app-authorization) has `USE CATALOG` on the target catalog, and `USE SCHEMA`, `SELECT`, and `MODIFY` on the target schema. The new tables inherit these privileges.
- To write to existing telemetry target tables in Unity Catalog, you need `SELECT` and `MODIFY` on the target tables, and one of the following:
  * `CAN MANAGE` permissions on the target catalog and schema.
  * All account users have `USE CATALOG`, `USE SCHEMA`, `SELECT`, and `MODIFY` on the target tables.
  * The app's service principal has `USE CATALOG` on the target catalog, `USE SCHEMA` on the target schema, and `SELECT` and `MODIFY` on the target tables.
- Target tables must be managed Delta tables in the same region as your workspace.
- Databricks recommends enabling [predictive optimization](https://docs.databricks.com/gcp/en/optimizations/predictive-optimization.md) on the telemetry target tables for better query performance.

## <a id="enable-otel" />Enable app telemetry

To turn on telemetry for an app, configure a catalog and schema for the telemetry tables in the app settings.

### UI

1. Open the app details page in your Databricks workspace.
2. On the **Settings** tab, locate the **App telemetry** configuration section and click **Add**.
3. Enter or browse to select a catalog and schema. Databricks writes telemetry data to three tables in the selected location: `otel_metrics`, `otel_spans`, and `otel_logs`.
4. (Optional) Specify a table prefix so that tables are named `<prefix>_otel_metrics`, `<prefix>_otel_spans`, and `<prefix>_otel_logs`. Databricks appends to existing tables or creates them if they don't exist.
5. Click **Save**.
6. Redeploy the app so that telemetry starts flowing to Unity Catalog.

### CLI

1. Configure telemetry using the `databricks apps update` command, specifying the full catalog, schema, and table names. To match the table names that the UI creates, use the same `<prefix>_` on all three tables, or omit it to use the default names:

   ```bash
   databricks apps update <app-name> --json '{
     "telemetry_export_destinations": [
       {
         "unity_catalog": {
           "logs_table": "<catalog>.<schema>.<prefix>_otel_logs",
           "metrics_table": "<catalog>.<schema>.<prefix>_otel_metrics",
           "traces_table": "<catalog>.<schema>.<prefix>_otel_spans"
         }
       }
     ]
   }'
   ```

2. Redeploy the app so that telemetry starts flowing to Unity Catalog:

   ```bash
   databricks apps deploy <app-name>
   ```

## <a id="verify-telemetry" />Verify telemetry data

The `otel_logs` table is populated automatically after redeployment. The `otel_spans` and `otel_metrics` tables are only populated after you [add custom instrumentation](https://docs.databricks.com/gcp/en/dev-tools/databricks-apps/observability.md#custom-instrumentation) to your app.

After you redeploy the app:

1. Visit the app URL to generate activity.
2. Wait a few seconds for the initial batch of data to appear.
3. Run the following query in Databricks SQL to confirm data is flowing:

   ```sql
   SELECT * FROM <catalog>.<schema>.otel_logs
   LIMIT 10;
   ```

## <a id="query-telemetry" />Query telemetry data

Useful columns for filtering and correlating telemetry data include `time`, `service_name`, `trace_id`, `span_id`, and `attributes`. The `attributes` column is a map that contains event-specific metadata such as `event.name`.

To view the full schema of any telemetry table, run:

```sql
DESCRIBE TABLE <catalog>.<schema>.otel_logs;
```

The following example queries for error-level logs from the last hour, which is useful for debugging app issues:

```sql
SELECT time, body
FROM <catalog>.<schema>.otel_logs
WHERE service_name = '<app-name>'
  AND severity_text = "ERROR"
  AND time >= current_timestamp() - INTERVAL 1 HOUR
ORDER BY time DESC
LIMIT 100;
```

### <a id="query-system-events" />Query system events

Databricks automatically captures system events in the `otel_logs` table, such as usage events for user logins and direct API requests. Query these events by filtering on the `event.name` attribute.

The following example retrieves the 100 most recent usage events for an application:

```sql
SELECT time, attributes
FROM <catalog>.<schema>.otel_logs
WHERE service_name = '<app-name>'
  AND attributes:["event.name"]::string = 'app.auth'
ORDER BY time DESC
LIMIT 100;
```

## <a id="custom-instrumentation" />Add custom instrumentation

Add OpenTelemetry auto-instrumentation to generate custom traces, metrics, and logs. Update your `app.yaml` and dependency files as shown for your framework.

> [!IMPORTANT]
>
> Set `OTEL_TRACES_SAMPLER` to `always_on` so OpenTelemetry records every trace. Without it, the default parent-based sampler follows each incoming request's sampling decision and drops requests marked as not sampled, which leaves your `otel_spans` table incomplete or empty.

### Streamlit

Update `app.yaml`:

```yaml
command: ['opentelemetry-instrument', 'streamlit', 'run', 'app.py']
env:
  - name: OTEL_TRACES_SAMPLER
    value: 'always_on'
```

Update `requirements.txt`:

```
streamlit==1.38.0

# Auto-instrumentation
opentelemetry-distro
opentelemetry-exporter-otlp-proto-grpc

# Required for Streamlit
opentelemetry-instrumentation-tornado

# Host metrics (CPU, memory)
opentelemetry-instrumentation-system-metrics
```

### Dash

Update `app.yaml`:

```yaml
command: ['opentelemetry-instrument', 'python', 'app.py']
env:
  - name: OTEL_TRACES_SAMPLER
    value: 'always_on'
```

Update `requirements.txt`:

```
dash
dash-bootstrap-components
pandas
plotly
databricks-sql-connector
databricks-sdk
python-dotenv
dash-ag-grid
opentelemetry-distro[otlp]
opentelemetry-instrumentation-flask
opentelemetry-exporter-otlp-proto-grpc
```

### Flask

Update `app.yaml`:

```yaml
command: ['opentelemetry-instrument', 'flask', '--app', 'app.py', 'run', '--no-reload']
env:
  - name: OTEL_TRACES_SAMPLER
    value: 'always_on'
```

Update `requirements.txt`:

```
opentelemetry-distro
opentelemetry-exporter-otlp-proto-grpc
opentelemetry-instrumentation-flask
```

### FastAPI

Update `app.yaml`:

```yaml
command: ['opentelemetry-instrument', 'uvicorn', 'app:app', '--host', '0.0.0.0', '--port', '8000']
env:
  - name: OTEL_TRACES_SAMPLER
    value: 'always_on'
```

Update `requirements.txt`:

```
fastapi
uvicorn
opentelemetry-distro
opentelemetry-exporter-otlp-proto-grpc
opentelemetry-instrumentation-fastapi
```

### Node.js

Create an `otel.js` file:

```javascript
'use strict';

import { NodeSDK } from '@opentelemetry/sdk-node';
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc';

const sdk = new NodeSDK({
  traceExporter: new OTLPTraceExporter(),
  metricReader: new PeriodicExportingMetricReader({
    exporter: new OTLPMetricExporter(),
    exportIntervalMillis: 10000,
  }),
  instrumentations: [
    getNodeAutoInstrumentations({
      '@opentelemetry/instrumentation-fs': { enabled: false },
    }),
  ],
});

try {
  sdk.start();
} catch (e) {
  console.error('OTel SDK failed to start', e);
}

async function shutdown(signal) {
  const hasAppHandler = process.listenerCount(signal) > 0;

  try {
    await sdk.shutdown();
  } catch (e) {
    console.error('OTel SDK shutdown failed', e);
  }

  if (!hasAppHandler) {
    process.kill(process.pid, signal);
  }
}
process.once('SIGTERM', shutdown);
process.once('SIGINT', shutdown);
```

The handler attempts to flush pending telemetry on shutdown. If your app registers its own signal handler, coordinate SDK shutdown with that handler to ensure flushing finishes before the app exits, and make sure your handler exits the process when its cleanup completes. Otherwise, the process exits after the SDK shutdown attempt completes.

Update `package.json`:

```json
{
  "name": "nodejs-otel",
  "version": "0.1.0",
  "private": true,
  "main": "app.js",
  "scripts": {
    "start": "node -r ./otel.js app.js"
  },
  "dependencies": {
    "express": "^4.21.2",
    "morgan": "^1.10.0",
    "@opentelemetry/api": "^1.9.0",
    "@opentelemetry/sdk-node": "0.203.0",
    "@opentelemetry/auto-instrumentations-node": "0.67.3",
    "@opentelemetry/exporter-trace-otlp-grpc": "0.203.0",
    "@opentelemetry/exporter-metrics-otlp-grpc": "0.203.0",
    "@opentelemetry/sdk-metrics": "2.0.1"
  }
}
```

## <a id="environment-variables" />Environment variables

When you enable app telemetry, Databricks automatically configures environment variables in your app runtime for the OTLP collector endpoint, export protocol, resource attributes, and batch processing. For the full list of OTel environment variables, see [App telemetry environment variables](https://docs.databricks.com/gcp/en/dev-tools/databricks-apps/system-env.md#otel-env).

## <a id="pricing" />Pricing

Telemetry ingestion is billed as Lakeflow Connect usage, because app telemetry writes to Unity Catalog tables through the Zerobus Ingest connector. This is separate from the compute charges for running the app itself.

Charges are billed against the "Jobs Serverless" SKU. For rates, see the [Lakeflow Connect pricing page](https://www.databricks.com/product/pricing/lakeflow-connect).

To track what your telemetry ingestion costs, query the billable usage system table. For the filters that isolate Zerobus Ingest usage, see [Monitoring your usage](https://docs.databricks.com/gcp/en/ingestion/zerobus-overview.md#monitoring-your-usage). To monitor the compute cost of the app itself, see [Monitor app costs](https://docs.databricks.com/gcp/en/dev-tools/databricks-apps/monitor.md#apps-cost-monitoring).

## <a id="limits" />Limits and limitations

App telemetry uses the Zerobus Ingest connector to write data to Unity Catalog tables. All Zerobus Ingest connector limitations apply to app telemetry, including limits on record size, throughput, delivery guarantees, and target table requirements. See [Zerobus Ingest quotas](https://docs.databricks.com/gcp/en/ingestion/zerobus-quotas.md).

In addition to Zerobus limits, app telemetry enforces a maximum log line size of 1 MB per log line.
