From ec2903e5ee06079681086fc02da95c8d59ca10f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannik=20Maierh=C3=B6fer?= <48529566+jannikmaierhoefer@users.noreply.github.com> Date: Thu, 19 Jun 2025 18:18:33 +0200 Subject: [PATCH] fix: upgrade langfuse code examples to langfuse python sdk v3 (#3030) Co-authored-by: Tony Kipkemboi --- docs/observability/langfuse.mdx | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/docs/observability/langfuse.mdx b/docs/observability/langfuse.mdx index 0202f39ef..1cfed6d9d 100644 --- a/docs/observability/langfuse.mdx +++ b/docs/observability/langfuse.mdx @@ -30,18 +30,29 @@ Set your Langfuse API keys and configure OpenTelemetry export settings to send t ```python import os -import base64 + +# Get keys for your project from the project settings page: https://cloud.langfuse.com +os.environ["LANGFUSE_PUBLIC_KEY"] = "pk-lf-..." +os.environ["LANGFUSE_SECRET_KEY"] = "sk-lf-..." +os.environ["LANGFUSE_HOST"] = "https://cloud.langfuse.com" # πŸ‡ͺπŸ‡Ί EU region +# os.environ["LANGFUSE_HOST"] = "https://us.cloud.langfuse.com" # πŸ‡ΊπŸ‡Έ US region + + +# Your OpenAI key +os.environ["OPENAI_API_KEY"] = "sk-proj-..." +``` +With the environment variables set, we can now initialize the Langfuse client. get_client() initializes the Langfuse client using the credentials provided in the environment variables. -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}" - -# your openai key -os.environ["OPENAI_API_KEY"] = "sk-..." +```python +from langfuse import get_client + +langfuse = get_client() + +# Verify connection +if langfuse.auth_check(): + print("Langfuse client is authenticated and ready!") +else: + print("Authentication failed. Please check your credentials and host.") ``` ### Step 3: Initialize OpenLit