-
Notifications
You must be signed in to change notification settings - Fork 17
Add langfuse instrumentation #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The following environment variables must be added to .env: LANGFUSE_SECRET_KEY LANGFUSE_PUBLIC_KEY LANGFUSE_HOST If these are not available, the app will still work, you just won't get any instrumentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds Langfuse instrumentation to monitor and trace API calls in the application. The instrumentation is configured to be optional - if the required environment variables are not set, the app will continue to function without instrumentation.
- Adds Langfuse dependencies and OpenTelemetry instrumentation for Anthropic API calls
- Integrates Langfuse client initialization with authentication verification
- Sets up automatic instrumentation for Anthropic API calls using OpenTelemetry
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| shinyapp/requirements.txt | Adds instrumentation dependencies: openai, langfuse, and opentelemetry-instrumentation-anthropic |
| shinyapp/app.py | Initializes Langfuse client, adds authentication check, and enables Anthropic API instrumentation |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if langfuse.auth_check(): | ||
| print("Langfuse client is authenticated and ready!") | ||
| else: | ||
| print("Authentication failed. Please check your credentials and host.") |
Copilot
AI
Sep 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message for authentication failure is not helpful for debugging. Consider providing more specific guidance about checking the LANGFUSE_SECRET_KEY, LANGFUSE_PUBLIC_KEY, and LANGFUSE_HOST environment variables mentioned in the PR description.
| print("Authentication failed. Please check your credentials and host.") | |
| print( | |
| "Authentication failed. Please check your LANGFUSE_SECRET_KEY, LANGFUSE_PUBLIC_KEY, and LANGFUSE_HOST environment variables." | |
| ) |
| else: | ||
| print("Authentication failed. Please check your credentials and host.") | ||
|
|
||
| AnthropicInstrumentor().instrument() | ||
|
|
Copilot
AI
Sep 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Anthropic instrumentation is enabled unconditionally, even when Langfuse authentication fails. According to the PR description, instrumentation should be optional when environment variables are not available. Consider wrapping the instrumentation in the authentication check or adding proper error handling.
| else: | |
| print("Authentication failed. Please check your credentials and host.") | |
| AnthropicInstrumentor().instrument() | |
| AnthropicInstrumentor().instrument() | |
| else: | |
| print("Authentication failed. Please check your credentials and host.") |
The following environment variables must be added to .env:
LANGFUSE_SECRET_KEY
LANGFUSE_PUBLIC_KEY
LANGFUSE_HOST
If these are not available, the app will still work, you just won't get any instrumentation.
See https://langfuse.com/integrations/model-providers/anthropic