Skip to content

Commit 2afb11f

Browse files
committed
refactor: explicitly initialize langfuse client
1 parent f057556 commit 2afb11f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/api/models/bedrock.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import tiktoken
1515
from botocore.config import Config
1616
from fastapi import HTTPException
17+
from langfuse import Langfuse
1718
from langfuse.decorators import langfuse_context, observe
1819
from starlette.concurrency import run_in_threadpool
1920

@@ -54,6 +55,18 @@
5455

5556
logger = logging.getLogger(__name__)
5657

58+
# Explicitly initialize Langfuse client for @observe decorator
59+
# This ensures the consumer and auth check happen at module load time
60+
try:
61+
_langfuse = Langfuse(
62+
debug=DEBUG
63+
)
64+
if DEBUG:
65+
logger.info("Langfuse client initialized successfully")
66+
except Exception as e:
67+
logger.warning(f"Failed to initialize Langfuse client: {e}")
68+
_langfuse = None
69+
5770
config = Config(
5871
connect_timeout=60, # Connection timeout: 60 seconds
5972
read_timeout=900, # Read timeout: 15 minutes (suitable for long streaming responses)

0 commit comments

Comments
 (0)