Skip to content

Commit a147d4c

Browse files
committed
Fix Langfuse userId tracking: use start_span() instead of start_as_current_span()
start_as_current_span() returns a context manager, not a span object, causing 'update_trace()' to fail with: '_AgnosticContextManager' object has no attribute 'update_trace' Signed-off-by: sallyom <somalley@redhat.com>
1 parent b6459b4 commit a147d4c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

components/runners/claude-code-runner/wrapper.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,9 @@ async def _run_claude_agent_sdk(self, prompt: str):
208208
user_id = os.getenv('USER_ID', '').strip()
209209
user_name = os.getenv('USER_NAME', '').strip()
210210

211-
# Start a span for this session (Langfuse SDK 3.x)
212-
langfuse_session_span = langfuse_client.start_as_current_span(
211+
# Start a trace for this session with userId (Langfuse SDK 3.x)
212+
# Use start_span() instead of start_as_current_span() for long-lived traces
213+
langfuse_session_span = langfuse_client.start_span(
213214
name="claude_agent_session",
214215
input={"prompt": prompt},
215216
metadata={
@@ -219,7 +220,7 @@ async def _run_claude_agent_sdk(self, prompt: str):
219220
},
220221
)
221222

222-
# Set userId on the trace (trace-level attribute, not span-level)
223+
# Set userId on the trace (trace-level attribute)
223224
if user_id:
224225
try:
225226
langfuse_session_span.update_trace(user_id=user_id)

0 commit comments

Comments
 (0)