---
type: concept
x-llmwiki:
  schemaVersion: "0.1"
  contentHash: 64e8483534d2fa43a922873e29ec68960ad60b9b587b836821f6a0ca673ca340
  pageDirectory: concepts
  sources:
    - export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md
  confidence: 0.96
  provenanceState: extracted
  freshnessStatus: unverified
  aliases:
    - langfuse-sdk-export-redirection
    - LSER
  citations:
    - file: export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md
title: Langfuse SDK Export Redirection
description: Technique of setting dummy Langfuse environment variables (LANGFUSE_HOST, LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY) to prevent traces from being sent to Langfuse servers while still using the SDK's OpenTelemetry TracerProvider for custom export.
tags:
  - langfuse
  - configuration
  - opentelemetry
timestamp: "2026-06-18T12:16:34.149Z"
---

# Langfuse SDK Export Redirection

**Langfuse SDK Export Redirection** is a configuration pattern that allows OpenTelemetry-based trace spans generated by the Langfuse SDK to be sent exclusively to the Databricks MLflow OTLP endpoint instead of a Langfuse server. This enables organizations to consolidate traces from Langfuse-instrumented workloads alongside other MLflow traces in Unity Catalog tables.^[export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md]

## Overview

By default, the Langfuse SDK sends trace data to a Langfuse-hosted server. By redirecting the export to Databricks, you can store all traces in a single location governed by [Unity Catalog](/concepts/unity-catalog.md), apply access controls and lineage, and query trace data at scale using Databricks SQL.^[export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md]

Consolidating traces on Databricks provides the following benefits:^[export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md]

- Query and compare Langfuse-instrumented calls together with traces from other frameworks in a single place.
- Use Databricks SQL to analyze trace data at scale.
- Apply Unity Catalog governance such as access controls and lineage to all your traces.

## How It Works

The Langfuse SDK registers its own OpenTelemetry `TracerProvider` as the global provider when initialized. The redirection pattern retrieves that provider and attaches a Databricks OTLPSpanExporter as an additional `BatchSpanProcessor`. Because the Langfuse environment variables are set to dummy values, the Databricks exporter becomes the only active processor, and all spans are sent exclusively to Databricks.^[export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md]

## Requirements

- A Databricks workspace with the **OpenTelemetry on Databricks** preview enabled. See [Manage Databricks previews](https://docs.databricks.com/aws/en/admin/workspace-settings/manage-previews).^[export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md]
- A new [MLflow Experiment](/concepts/mlflow-experiment.md).^[export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md]

## Configuration Steps

### 1. Install Packages

Install the required packages in a Databricks notebook:^[export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md]

```python
%pip install "langfuse>=3.14.5" "mlflow[databricks]>=3.10.0" opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp-proto-http
%restart_python
```

### 2. Disable Langfuse Trace Collection

Set the required environment variables to dummy values to prevent traces from being sent to a Langfuse server:^[export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md]

```python
import os

os.environ["LANGFUSE_HOST"] = "localhost"
os.environ["LANGFUSE_PUBLIC_KEY"] = ""
os.environ["LANGFUSE_SECRET_KEY"] = ""
```

Alternatively, you can set `LANGFUSE_TRACING_ENABLED=False` to disable Langfuse's built-in trace collection. The simplest approach is to use dummy values as shown above.^[export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md]

### 3. Configure Databricks Connection

Retrieve the workspace host URL and API token. In a Databricks notebook, these can be obtained from the notebook context:^[export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md]

```python
context = dbutils.notebook.entry_point.getDbutils().notebook().getContext()
DATABRICKS_HOST = context.apiUrl().get().rstrip("/")
DATABRICKS_TOKEN = context.apiToken().get()
```

If running outside a Databricks notebook, set the `DATABRICKS_HOST` and `DATABRICKS_TOKEN` environment variables manually.^[export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md]

### 4. Link an Experiment to Unity Catalog

Define a Unity Catalog [Catalog and Schema](/concepts/catalog-and-schema.md), then link them to an MLflow experiment using `set_experiment_trace_location`:^[export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md]

```python
import mlflow
from mlflow.entities import UCSchemaLocation
from mlflow.tracing.enablement import set_experiment_trace_location

CATALOG_NAME = "<UC_CATALOG_NAME>"
SCHEMA_NAME = "<UC_SCHEMA_NAME>"
EXPERIMENT_ID = "<EXPERIMENT_ID>"

trace_location = set_experiment_trace_location(
    location=UCSchemaLocation(catalog_name=CATALOG_NAME, schema_name=SCHEMA_NAME),
    experiment_id=EXPERIMENT_ID,
)
```

### 5. Add the Databricks OTLP Exporter

Retrieve the global `TracerProvider` that Langfuse registered, then attach a `BatchSpanProcessor` with an `OTLPSpanExporter` pointing to the Databricks OTLP endpoint:^[export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md]

```python
from langfuse import get_client
from opentelemetry import trace as otel_trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace.export import BatchSpanProcessor

# Initialize the Langfuse client
langfuse = get_client()

# Retrieve the global TracerProvider
provider = otel_trace.get_tracer_provider()

# Configure the OTLP exporter to send spans to the Databricks MLflow endpoint
databricks_exporter = OTLPSpanExporter(
    endpoint=f"{DATABRICKS_HOST}/api/2.0/otel/v1/traces",
    headers={
        "content-type": "application/x-protobuf",
        "Authorization": f"Bearer {DATABRICKS_TOKEN}",
        "X-Databricks-UC-Table-Name": trace_location.full_otel_spans_table_name,
    },
)

# Attach the Databricks exporter to Langfuse's provider
provider.add_span_processor(BatchSpanProcessor(databricks_exporter))
```

The `X-Databricks-UC-Table-Name` header routes incoming spans to the Unity Catalog table defined by the trace location. Because the Langfuse environment variables are set to dummy values, this processor is the only active exporter, so all spans are sent exclusively to Databricks.^[export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md]

### 6. Run a Traced Function

Use Langfuse's `@observe()` decorator to instrument functions. The decorator creates OTEL spans that the exporter sends to Databricks:^[export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md]

```python
from langfuse import observe

@observe()
def my_llm_call(prompt: str) -> str:
    # Replace with your LLM logic (OpenAI, Anthropic, etc.)
    return f"Response to: {prompt}"

@observe()
def my_pipeline(user_input: str) -> str:
    result = my_llm_call(user_input)
    return result

my_pipeline("Hello, world!")
```

### 7. View Traces

Open the MLflow experiment in your Databricks workspace and click the **Traces** tab. The trace from the instrumented function call should appear.^[export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md]

## Important Notes

- The Databricks OTLP exporter uses Protobuf encoding (`application/x-protobuf`) for efficient data transfer to the `https://<host>/api/2.0/otel/v1/traces` endpoint.^[export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md]
- The `X-Databricks-UC-Table-Name` header is critical — it ensures spans are routed to the correct Unity Catalog table.^[export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md]

## Related Concepts

- OpenTelemetry on Databricks — The preview feature enabling OTLP ingestion
- [MLflow Tracing](/concepts/mlflow-tracing.md) — The tracing framework for MLflow experiments
- OTLPSpanExporter — The OpenTelemetry exporter used to send spans to Databricks
- [Storing Traces in Unity Catalog](/concepts/model-traces-in-unity-catalog.md) — Managing trace data in UC tables
- Querying Traces with Databricks SQL — Analyzing trace data via SQL
- Searching Traces by OTel Span Attributes — Filtering ingested traces by span properties

## Sources

- export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md

# Citations

1. [export-langfuse-traces-to-databricks-mlflow-databricks-on-aws.md](/references/export-langfuse-traces-to-databricks-mlflow-databricks-on-aws-edce6b99.md)
