Skip to content

Conversation

@jcheng5
Copy link
Contributor

@jcheng5 jcheng5 commented Sep 30, 2025

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

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.
@jcheng5 jcheng5 requested a review from Copilot September 30, 2025 15:01
Copy link

Copilot AI left a 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.")
Copy link

Copilot AI Sep 30, 2025

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.

Suggested change
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."
)

Copilot uses AI. Check for mistakes.
Comment on lines +47 to +51
else:
print("Authentication failed. Please check your credentials and host.")

AnthropicInstrumentor().instrument()

Copy link

Copilot AI Sep 30, 2025

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.

Suggested change
else:
print("Authentication failed. Please check your credentials and host.")
AnthropicInstrumentor().instrument()
AnthropicInstrumentor().instrument()
else:
print("Authentication failed. Please check your credentials and host.")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants