Skip to content

Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.

[Docs]: Add Langfuse as a connection (#600)

Jannik Maierhöferbc6ea3acd7de
diff --git a/docs/latest/connections/intro.mdx b/docs/latest/connections/intro.mdx
index 57c64d5a..4c3b680f 100644
--- a/docs/latest/connections/intro.mdx
+++ b/docs/latest/connections/intro.mdx
@@ -3201,6 +3201,13 @@ Below is a list of observability tools that work seamlessly with OpenLIT SDK:
</svg>
}>
</Card>
+ <Card
+ title="Langfuse"
+ href="/latest/connections/langfuse"
+ icon={
+ <svg height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Langfuse</title><g fill="none" fill-rule="evenodd"><path d="M6.327 12.922c1.914-.003 3.399.092 4.479.578.487.218.944.497 1.362.83l.246.206c.62.549 1.889 1.415 3.452 1.12.199-.038.39-.088.573-.15a6.594 6.594 0 014.958 1.287c-1.055 1.445-2.67 2.409-4.493 2.55l-.17.01c-2.138.108-3.752-.879-4.823-1.795-1.894-1.016-3.377-1.272-4.244-1.493a4.86 4.86 0 01-1.329-.584l-.239-.155a2.706 2.706 0 01-.797-.869 2.79 2.79 0 01-.367-1.444l.314-.038a9.624 9.624 0 011.078-.053zm16.188-2.841c.078.38.16.566.19.848a9.84 9.84 0 01-.21 3.224 13.33 13.33 0 00-3.577-1.271c.116-.36.18-.74.19-1.125.008-.305-.027-.419-.08-.714.539-.091 1.21-.24 1.823-.4.647-.17 1.126-.367 1.664-.562zM11.782 5.917l.155-.127c.584-.464 2.346-1.68 4.805-1.46 1.123.1 2.051.47 2.779.898.682.402 1.26.992 1.736 1.615-.43.31-1.065.643-1.916.908a6.69 6.69 0 01-2.914.23c-1.333-.336-2.799.154-3.803 1.251-.558.609-1.204 1.129-1.941 1.494-1.116.553-2.821.542-4.806.43a9.36 9.36 0 01-.756-.074 4.11 4.11 0 01.835-1.427 4.102 4.102 0 011.653-1.11c2.047-.794 3.748-2.224 4.173-2.628zm-9.14 1.39a8.873 8.873 0 01-1.76-1.21c-.226-.2-.578-.037-.578.269v2.498a.36.36 0 00.131.28l1.011.984a5.82 5.82 0 011.196-2.821zM.86 18.157a.35.35 0 01-.555-.29V14.8c0-.093.035-.181.096-.247l.054-.047a.235.235 0 01.018-.011l1.001-.436a7.94 7.94 0 001.17 2.927L.858 18.157z" fill="#0A60B5" fill-rule="nonzero"></path><path d="M7.308 4.751c2.004-.1 3.502.75 4.274 1.317-.585.523-2.167 1.784-4.037 2.512a4.083 4.083 0 00-.485.212 3.96 3.96 0 00-2.194 3.458c-.006.242.006.483.038.72h-.01c-.006.247.014.827.367 1.434.314.542.736.832.945.958.104.07.27.17.475.276a4.03 4.03 0 00.943.362l.352.086c.892.214 2.245.539 3.903 1.421.168.143.348.286.542.426-.06.054-.109.1-.149.138-.342.293-2.219 1.841-4.964 1.596a6.577 6.577 0 01-2.78-.902c-1.225-.726-2.151-1.873-2.656-3.215a9.805 9.805 0 01-.227-6.239c.743-2.51 2.91-4.351 5.492-4.548l.171-.012zm14.03 11.965a6.637 6.637 0 00-4.947-1.27c-.183.06-.374.11-.572.147-1.563.293-2.83-.566-3.45-1.11a6.397 6.397 0 00-.373-.303 6.293 6.293 0 011.376-.94c1.117-.555 2.823-.544 4.81-.433 2.737.155 4.628 1.475 5.382 2.082.085.067.133.17.133.278v2.491a.35.35 0 01-.582.269 8.905 8.905 0 00-1.777-1.211zm-8.775-7.444c-.18.197-.368.384-.566.56.383.289.797.532 1.236.727 1.08.482 2.563.576 4.476.574a11.21 11.21 0 005.82-1.656.356.356 0 00.168-.304V6.116a.351.351 0 00-.558-.29c-.552.403-1.373.917-2.432 1.32a6.62 6.62 0 01-1.422.637 6.667 6.667 0 01-2.916.231c-1.334-.337-2.8.155-3.806 1.258z" fill="#E11312"></path><path d="M1.498 15.41c-.098-.283-.19-.59-.27-.917l-.601.26-.015.023-.004.023v3.068c0 .047.04.069.07.047l1.53-1.007a6.888 6.888 0 01-.62-1.248l-.09-.25zm20.85-4.733l-.05-.195-.35.13a11.45 11.45 0 01-2.563.7l.006.034c.018.132.025.256.02.418a4.334 4.334 0 01-.08.735l-.03.129a9.772 9.772 0 012.984 1.045l.059-.344c.058-.382.092-.772.103-1.168l.002-.4a9.54 9.54 0 00-.047-.802l-.015-.108-.038-.174zM.609 6.366v2.498c0 .013.003.024.015.039l.628.612.056-.223c.049-.179.107-.359.175-.54l.11-.272c.134-.311.287-.597.455-.86l.145-.215-.028-.016A9.104 9.104 0 01.95 6.551l-.27-.23c-.028-.024-.072-.003-.072.045zm6.212 8.999c.225.121.473.223.75.302l-.014.053.015-.053.01.003-.016.053.019-.052.223.058.794.195c.805.206 1.865.526 3.105 1.15l.343.177.025.021c.162.138.336.277.523.412l.307.223-.019.017c1.15.784 2.409 1.2 3.828 1.128l.168-.01c1.519-.118 2.918-.843 3.93-2l.155-.187-.234-.155a6.221 6.221 0 00-1.396-.651l-.317-.094a6.226 6.226 0 00-2.483-.162 4.76 4.76 0 01-.613.159c-1.318.25-2.518-.208-3.52-1.027l-.425-.36a6.07 6.07 0 00-1.298-.79c-.871-.392-2.032-.538-4.014-.55h-.522c-.178.003-.335.01-.491.02l-.187.013-.22.021.01.1c.028.242.094.49.212.74l.098.188.109.173c.219.292.462.475.622.578l.218.138.09.052.215.117zm5.873-1.355l-.216.165.298.248c.64.506 1.714 1.107 2.988.868l.183-.039.178-.045.2-.062.157-.021a6.939 6.939 0 012.394.118l.251.062a6.994 6.994 0 012.269 1.074l.104.077.236.126a9.245 9.245 0 011.43.987l.149.127.014.01.011.003.027-.005a.05.05 0 00.02-.017.047.047 0 00.008-.028v-2.491l-.005-.022-.013-.016-.093-.074a9.246 9.246 0 00-.908-.625l-.022-.01a12.991 12.991 0 00-3.457-1.235 8.9 8.9 0 00-.731-.071l-.42-.022c-.829-.04-1.593-.056-2.275-.012-.798.051-1.458.183-1.964.435a5.717 5.717 0 00-.813.495zM1.86 9.67c-.034.13-.066.263-.096.4l-.096.696-.026-.026a9.426 9.426 0 00.03 2.903l.033-.015.068.377a7.616 7.616 0 001.125 2.815l.131.202A5.79 5.79 0 004.681 18.5a6.276 6.276 0 002.654.861c2.35.21 4.036-.957 4.594-1.402l-.162-.136c-.832-.445-1.63-.77-2.452-1.02-.31-.096-.61-.176-.958-.26l-.765-.185a5.079 5.079 0 01-1.42-.624l-.247-.161c-.244-.17-.47-.38-.667-.636a3.074 3.074 0 01-.259-.377l-.09-.168a3.07 3.07 0 01-.32-1.352 32.26 32.26 0 01-.026-.54v-.258l.01-.21a4.265 4.265 0 012.149-3.406l.128-.07c.213-.118.43-.214.649-.293l.306-.125.306-.136.13-.061a14.74 14.74 0 002.641-1.684l.199-.163-.08-.051c-.752-.473-1.914-.996-3.38-.993l-.296.008-.167.01c-1.61.124-3.055.922-4.057 2.136l-.287.375a6.233 6.233 0 00-.879 1.82l-.076.271zm3.31 2.588v.225l.01.197.038-.005c.13-.014.262-.025.397-.033l.338-.016c.117-.004.24-.006.374-.006h.352c2.06.014 3.283.169 4.253.605.36.162.706.355 1.034.58a6.458 6.458 0 011.273-.84l.236-.107c.564-.23 1.23-.344 1.957-.39.834-.055 1.772-.023 2.767.033.17.01.338.024.501.041l.054-.264c.03-.174.047-.35.051-.529.002-.087.001-.156-.004-.222l-.018-.14c-.344.034-.702.052-1.073.053l-.376-.001c-1.734-.01-3.153-.121-4.223-.599l-.272-.128a6.68 6.68 0 01-1.022-.633l.199.144a6.453 6.453 0 01-1.196.773c-1.04.516-2.42.604-4.96.461a9.87 9.87 0 01-.569-.049c-.073.275-.114.56-.121.85zM19.118 8.15a6.962 6.962 0 01-2.51.202l-.312-.04.015-.048-.015.048c-.927-.234-1.935-.031-2.778.535-.18.126-.35.268-.512.425l-.158.163a8.123 8.123 0 01-.36.37l.141.09c.233.144.475.272.726.384l.208.085c.996.38 2.353.464 4.145.462l.338-.006c.305-.01.6-.032.885-.066l.046-.008c.52-.089 1.18-.235 1.797-.396.254-.066.471-.132.733-.223a10.98 10.98 0 001.864-.912l.017-.018.006-.024V6.116l-.008-.027a.048.048 0 00-.07-.013c-.511.372-1.246.838-2.182 1.23l-.086.035a6.544 6.544 0 01-.631.326l-.232.1a7.207 7.207 0 01-.811.31l-.256.073zm-11.464.717l-.102.038a3.752 3.752 0 00-.225.097l-.129.064a3.752 3.752 0 00-.19.1c-.29.177-.567.403-.826.69a3.756 3.756 0 00-.522.742l-.112.229.098.01.248.017.636.032c2.03.087 3.19-.02 4.017-.43A5.83 5.83 0 0011.6 9.78l.384-.351.182-.18.332-.35a4.581 4.581 0 011.12-.822c.895-.48 1.912-.634 2.853-.396a6.276 6.276 0 002.78-.22c.16-.05.313-.102.46-.157.24-.099.458-.206.654-.314l.212-.122.233-.095-.183-.22a5.62 5.62 0 00-1.04-.928l-.22-.139a6.268 6.268 0 00-2.65-.856c-1.868-.167-3.416.464-4.586 1.392l-.138.112c-.651.62-1.646 1.358-2.75 1.97-.492.278-1.027.543-1.588.762zm16.032.872l-.123.074-.325.187c-.118.066-.246.134-.383.203l.101.4c.024.102.04.196.05.296a10.141 10.141 0 01-.166 3.1c.39.245.697.476.913.65a.664.664 0 01.247.518v2.491l-.007.098a.654.654 0 01-1 .462l-.076-.06a8.72 8.72 0 00-1.412-1.004l-.2.242c-1.117 1.299-2.678 2.116-4.38 2.247l-.176.012c-1.634.082-3.064-.417-4.323-1.313l-.114.093c-.605.484-2.449 1.768-5.03 1.537l-.316-.035a6.89 6.89 0 01-2.591-.908l-.253-.158a6.426 6.426 0 01-1.568-1.466l-1.515.995A.653.653 0 010 17.867V14.8c0-.168.064-.33.2-.473l.08-.068.07-.04.75-.326a10.044 10.044 0 01-.16-1.639v-.382c.013-.589.077-1.139.172-1.645l-.868-.849A.66.66 0 010 8.864V6.366c0-.563.66-.87 1.084-.495.431.38.921.736 1.468 1.043 1.105-1.393 2.733-2.318 4.563-2.457l.016.219-.015-.22.176-.011c1.953-.098 3.444.665 4.289 1.247l.007-.007.159-.13c1.285-1.02 2.974-1.708 5.022-1.526a6.876 6.876 0 012.907.939c.622.367 1.19.893 1.712 1.55a10.09 10.09 0 001.574-.94l.083-.052a.655.655 0 01.955.59v3.057l-.007.098a.663.663 0 01-.307.468z" fill="#000" fill-rule="nonzero"></path></g></svg>
+ }>
+</Card>
</CardGroup>
---
diff --git a/docs/latest/connections/langfuse.mdx b/docs/latest/connections/langfuse.mdx
new file mode 100644
index 00000000..079e36aa
--- /dev/null
+++ b/docs/latest/connections/langfuse.mdx
@@ -0,0 +1,82 @@
+---
+title: 'Langfuse'
+description: 'LLM Observability with Langfuse and OpenLIT'
+---
+
+# LLM Observability with Langfuse and OpenLIT
+
+Langfuse is an [OpenTelemetry backend](https://langfuse.com/docs/opentelemetry/example-openlit), allowing trace ingestion from various OpenTelemetry instrumentation libraries. This guide demonstrates how to use the [OpenLit](https://docs.openlit.io/latest/features/tracing) instrumentation library to instrument a compatible framework or LLM provider.
+
+> **What is Langfuse?** [Langfuse](https://langfuse.com) is an open-source platform for LLM engineering. It provides tracing and monitoring capabilities for AI agents, helping developers debug, analyze, and optimize their products. Langfuse integrates with various tools and frameworks via native integrations, OpenTelemetry, and SDKs.
+
+## Step 1: Install Dependencies
+
+Install the necessary Python packages: `openai`, `langfuse`, and `openlit`. These will allow you to interact with OpenAI as well as setup the instrumentation for tracing.
+
+```python
+%pip install openai langfuse openlit
+```
+
+## Step 2: Configure Environment Variables
+
+Before sending any requests, you need to configure your credentials and endpoints. First, set up the Langfuse authentication by providing your public and secret keys. Then, configure the OpenTelemetry exporter endpoint and headers to point to Langfuse's backend. You should also specify your OpenAI API key.
+
+
+```python
+import os
+import base64
+
+# Note: Replace the placeholder Langfuse API keys below with your actual credentials in production.
+
+LANGFUSE_PUBLIC_KEY = "pk-lf-..."
+LANGFUSE_SECRET_KEY = "sk-lf-..."
+LANGFUSE_AUTH = base64.b64encode(f"{LANGFUSE_PUBLIC_KEY}:{LANGFUSE_SECRET_KEY}".encode()).decode()
+
+os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "https://cloud.langfuse.com/api/public/otel" # 🇪🇺 EU data region
+# os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "https://us.cloud.langfuse.com/api/public/otel" # 🇺🇸 US data region
+
+os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = f"Authorization=Basic {LANGFUSE_AUTH}"
+
+# Set your OpenAI API key.
+os.environ["OPENAI_API_KEY"] = ""
+```
+
+*Explanation:* This block configures the necessary environment variables. The Langfuse keys are combined and base64 encoded to form an authentication token that is then set in the OTLP headers. Additionally, the OpenTelemetry endpoint is provided to direct trace data to Langfuse's backend.
+
+## Step 3: Initialize Instrumentation and make a Chat Completion Request
+
+With the environment set up, import the needed libraries and initialize OpenLIT instrumentation. For this example, we will make a simple chat completion request to the OpenAI Chat API. This will generate trace data that you can later view in Langfuse's observability dashboard.
+
+```python
+from openai import OpenAI
+import openlit
+
+# Initialize OpenLIT instrumentation. The disable_batch flag is set to true to process traces immediately.
+openlit.init(disable_batch=True)
+
+# Create an instance of the OpenAI client.
+openai_client = OpenAI()
+
+# Make a sample chat completion request. This request will be traced by OpenLIT and sent to Langfuse.
+chat_completion = openai_client.chat.completions.create(
+ messages=[
+ {
+ "role": "user",
+ "content": "What is LLM Observability?",
+ }
+ ],
+ model="gpt-3.5-turbo",
+)
+
+print(chat_completion)
+```
+
+## Step 4: See Traces in Langfuse
+
+You can view the generated trace data in Langfuse. You can view this [example trace](https://cloud.langfuse.com/project/cloramnkj0002jz088vzn1ja4/traces/64902f6a5b4f27738be939b7ad38eab3?timestamp=2025-02-02T22%3A09%3A53.053Z) in the Langfuse UI.
+
+![OpenLIT OpenAI Trace](https://langfuse.com/images/cookbook/otel-integration-openlit/openlit-openai-trace.png)
+
+
+
+