Skip to content

Conversation

@avirajsingh7
Copy link
Collaborator

@avirajsingh7 avirajsingh7 commented Sep 3, 2025

Added assistant_id as a tag in Langfuse tracing to improve observability and filtering capabilities.

Checklist

Before submitting a pull request, please ensure that you mark these task.

  • Ran fastapi run --reload app/main.py or docker compose up in the repository root and test.
  • If you've fixed a bug or added code that is tested and has test cases.

Notes

Please add here if any other information is required for the reviewer.

Summary by CodeRabbit

  • Chores
    • Enhanced observability by adding assistant-specific tags to tracing. This enables easier filtering, clearer analytics, and faster issue triage in monitoring tools.
    • No changes to user-facing behavior or workflows; performance and outputs remain the same.
    • Improves supportability and targeted performance insights without affecting existing functionality.

@coderabbitai
Copy link

coderabbitai bot commented Sep 3, 2025

Walkthrough

Introduces an optional tags parameter to LangfuseTracer.start_trace and propagates a tag from process_response by passing the request.assistant_id. The tags are forwarded to the underlying Langfuse trace creation. No other logic or public APIs are altered beyond the updated method signature.

Changes

Cohort / File(s) Summary
Tracing core update
backend/app/core/langfuse/langfuse.py
Added optional parameter tags: list[str]
Route integration
backend/app/api/routes/responses.py
Updated process_response to call tracer.start_trace with tags set to [request.assistant_id].

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Client
    participant API as API Route (process_response)
    participant Tracer as LangfuseTracer
    participant LF as Langfuse Backend

    Client->>API: HTTP request
    API->>Tracer: start_trace(name, input, metadata, tags=[assistant_id])
    Note right of Tracer: New: pass-through tags
    Tracer->>LF: create trace(name, input, metadata, tags)
    LF-->>Tracer: trace initialized
    Tracer-->>API: trace handle
    API-->>Client: Response (flow unchanged)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

enhancement

Suggested reviewers

  • AkhileshNegi
  • kartpop
  • nishika26

Poem

I hop through traces, light and spry,
Tagging threads as they flutter by.
A whisker-twitch, an ID bound—
Now every hop is neatly found.
With gentle paws I mark the trail,
So future hunts will never fail. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch enhancement/tag_assistant_id_langfuse

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Sep 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
backend/app/api/routes/responses.py (2)

197-204: Tag overwrite drops assistant_id; include both assistant_id and response.id

update_trace replaces the tag set, removing the assistant_id you added. Include both IDs or rely on tracer to merge.

Apply this minimal fix if you don’t update the tracer:

-        tracer.update_trace(
-            tags=[response.id],
+        tracer.update_trace(
+            tags=[request.assistant_id, response.id],
             output={
                 "status": "success",
                 "message": response.output_text,
                 "error": None,
             },
         )

95-101: Bug: file search results builder uses the wrong source list (always empty)

You iterate over the accumulating results list instead of the tool call’s results, producing empty chunks.

 def get_file_search_results(response):
     results: list[FileResultChunk] = []
     for tool_call in response.output:
         if tool_call.type == "file_search_call":
-            results.extend(
-                [FileResultChunk(score=hit.score, text=hit.text) for hit in results]
-            )
+            if getattr(tool_call, "results", None):
+                results.extend(
+                    FileResultChunk(score=hit.score, text=hit.text)
+                    for hit in tool_call.results
+                )
     return results
🧹 Nitpick comments (2)
backend/app/api/routes/responses.py (1)

42-44: Avoid bare except; log parse failures explicitly

Catching all exceptions hides real issues. Scope the except and log.

-        except:
-            pass
+        except ValueError as parse_err:
+            logger.debug("Failed to parse OpenAI error body: %s", parse_err)
backend/app/core/langfuse/langfuse.py (1)

40-43: Minor: fetch_traces expects a list for tags

Pass a list to avoid SDK edge cases.

-            if response_id:
-                traces = self.langfuse.fetch_traces(tags=response_id).data
+            if response_id:
+                traces = self.langfuse.fetch_traces(tags=[response_id]).data
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f24f4c5 and 73b8934.

📒 Files selected for processing (2)
  • backend/app/api/routes/responses.py (1 hunks)
  • backend/app/core/langfuse/langfuse.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
backend/app/api/routes/responses.py (1)
backend/app/tests/api/routes/test_assistants.py (1)
  • assistant_id (25-26)
🔇 Additional comments (1)
backend/app/api/routes/responses.py (1)

147-148: Assistant tag added to trace start – good, but watch for later overwrite

This correctly attaches assistant_id at trace start. Note that later updates overwrite tags, which will drop this assistant_id unless addressed (see below).

@AkhileshNegi AkhileshNegi changed the title feat: Add assistant_id as tag in Langfuse tracing Langfuse: Add assistant_id as tag in traces Sep 4, 2025
@AkhileshNegi AkhileshNegi merged commit 6685714 into main Sep 4, 2025
2 checks passed
@AkhileshNegi AkhileshNegi deleted the enhancement/tag_assistant_id_langfuse branch September 4, 2025 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request ready-for-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants