Langfuse

Langfuse is an open-source LLM observability platform. The Respan instrumentor patches Langfuse’s OTLP exporter to redirect traces to Respan, so your existing @observe decorators and langfuse.trace() calls continue to work unchanged. You also get gateway routing through the OpenAI-compatible Respan endpoint.

Create an account at platform.respan.ai and grab an API key. For gateway, also add credits or a provider key.

Run npx @respan/cli setup to set up with your coding agent.

Setup

1

Install packages

pip install respan-ai respan-instrumentation-langfuse langfuse openai
2

Set environment variables

export OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
export LANGFUSE_PUBLIC_KEY="YOUR_LANGFUSE_PUBLIC_KEY"
export LANGFUSE_SECRET_KEY="YOUR_LANGFUSE_SECRET_KEY"

OPENAI_API_KEY is used for LLM requests. RESPAN_API_KEY is used to export traces to Respan. Langfuse keys are still required for the SDK to initialize.

3

Initialize and run

LangfuseInstrumentor must be activated before importing langfuse. The instrumentor patches the OTLP exporter at import time.

from respan import Respan
from respan_instrumentation_langfuse import LangfuseInstrumentor
# Activate BEFORE importing langfuse
respan = Respan(instrumentations=[LangfuseInstrumentor()])
from langfuse.decorators import observe
from openai import OpenAI
client = OpenAI()
@observe()
def generate_joke():
response = client.chat.completions.create(
model="gpt-4.1-nano",
messages=[{"role": "user", "content": "Tell me a joke about AI"}],
)
return response.choices[0].message.content
@observe()
def joke_pipeline():
return generate_joke()
print(joke_pipeline())
4

View your trace

Open the Traces page to see your Langfuse traces in Respan.

Configuration

ParameterTypeDefaultDescription
api_keystr | NoneNoneFalls back to RESPAN_API_KEY env var.
base_urlstr | NoneNoneFalls back to RESPAN_BASE_URL env var.
instrumentationslist[]Plugin instrumentations to activate (e.g. LangfuseInstrumentor()).
customer_identifierstr | NoneNoneDefault customer identifier for all spans.
metadatadict | NoneNoneDefault metadata attached to all spans.
environmentstr | NoneNoneEnvironment tag (e.g. "production").

Attributes

In Respan()

Set defaults at initialization — these apply to all spans.

from respan import Respan
from respan_instrumentation_langfuse import LangfuseInstrumentor
respan = Respan(
instrumentations=[LangfuseInstrumentor()],
customer_identifier="user_123",
metadata={"service": "chat-api", "version": "1.0.0"},
)

With propagate_attributes

Override per-request using a context scope.

from respan import Respan, propagate_attributes
from respan_instrumentation_langfuse import LangfuseInstrumentor
respan = Respan(instrumentations=[LangfuseInstrumentor()])
from langfuse.decorators import observe
@observe()
def handle_request(user_id: str, question: str):
with propagate_attributes(
customer_identifier=user_id,
thread_identifier="conv_abc_123",
metadata={"plan": "pro"},
):
# your Langfuse-traced code here
...
AttributeTypeDescription
customer_identifierstrIdentifies the end user in Respan analytics.
thread_identifierstrGroups related messages into a conversation.
metadatadictCustom key-value pairs. Merged with default metadata.