Skip to content

Conversation

2getsandesh
Copy link
Contributor

@2getsandesh 2getsandesh commented Aug 7, 2025

  • I have added tests that cover my changes.
  • If adding a new instrumentation or changing an existing one, I've added screenshots from some observability platform showing the change.
  • PR name follows conventional commits format: feat(instrumentation): ... or fix(instrumentation): ....
  • (If applicable) I have updated the documentation accordingly.

Important

Adds method to fetch model name from association metadata in span_utils.py and updates on_llm_end() in callback_handler.py to use it as a fallback.

  • Behavior:
    • Adds _extract_model_name_from_association_metadata() in span_utils.py to fetch model name from association metadata.
    • Updates on_llm_end() in callback_handler.py to use _extract_model_name_from_association_metadata() if model name is not found in response metadata.
  • Functions:
    • _extract_model_name_from_association_metadata() returns model name from association_properties or "unknown" if not found.

This description was created by Ellipsis for 44106ae. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability in extracting the model name by adding an additional fallback mechanism, ensuring the model name is identified even when not present in the initial response metadata.
  • Tests
    • Updated test data to reflect new API endpoints, request methods, and response formats.
    • Adjusted test assertions to accommodate changes in tool call IDs and logged event counts.

Copy link

coderabbitai bot commented Aug 7, 2025

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

📥 Commits

Reviewing files that changed from the base of the PR and between 2311966 and 832a121.

📒 Files selected for processing (5)
  • packages/opentelemetry-instrumentation-langchain/tests/cassettes/test_agents/test_agents.yaml (8 hunks)
  • packages/opentelemetry-instrumentation-langchain/tests/cassettes/test_agents/test_agents_with_events_with_content.yaml (12 hunks)
  • packages/opentelemetry-instrumentation-langchain/tests/cassettes/test_agents/test_agents_with_events_with_no_content.yaml (8 hunks)
  • packages/opentelemetry-instrumentation-langchain/tests/conftest.py (0 hunks)
  • packages/opentelemetry-instrumentation-langchain/tests/test_agents.py (5 hunks)
 _____________________________________________________________________________
< Easy things should be easy and hard things should be possible. - Larry Wall >
 -----------------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).

Walkthrough

This change introduces a new helper function to extract a model name from association metadata and updates the on_llm_end method to use this fallback when the model name is unavailable from previous sources. No public APIs or function signatures were modified.

Changes

Cohort / File(s) Change Summary
Fallback Model Name Extraction in Callback Handler
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/callback_handler.py
Adds logic in on_llm_end to use association metadata for model name extraction if not found in response metadata.
Helper Function for Model Name Extraction
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/span_utils.py
Introduces _extract_model_name_from_association_metadata to extract model name from given metadata dictionary.

Sequence Diagram(s)

sequenceDiagram
    participant CallbackHandler
    participant ContextAPI
    participant SpanUtils

    CallbackHandler->CallbackHandler: on_llm_end()
    alt Model name in response metadata
        CallbackHandler->CallbackHandler: Use model name from response
    else Model name not found
        CallbackHandler->ContextAPI: Check for get_value
        ContextAPI->CallbackHandler: Return association_properties
        CallbackHandler->SpanUtils: _extract_model_name_from_association_metadata(association_properties)
        SpanUtils-->CallbackHandler: Return model name or "unknown"
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related PRs

Poem

A rabbit hopped through code today,
Seeking model names along the way.
If none were found in plain old sight,
It peeked in metadata for insight.
Now with a helper’s gentle hand,
The model’s name is close at hand!
🐇✨

Tip

CodeRabbit can suggest fixes for GitHub Check annotations.

Configure reviews.tools.github-checks in your project's settings in CodeRabbit to adjust the time to wait for GitHub Checks to complete.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
  • 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 src/utils.ts and explain its main purpose.
    • @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 comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai 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

Documentation and Community

  • 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.

@CLAassistant
Copy link

CLAassistant commented Aug 7, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to 44106ae in 1 minute and 16 seconds. Click for details.
  • Reviewed 38 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/callback_handler.py:511
  • Draft comment:
    Consider adding an inline comment here to explain that if the response metadata doesn't yield a model name, the association metadata (from context_api) is used as a fallback.
  • Reason this comment was not posted:
    Confidence changes required: 20% <= threshold 50% None
2. packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/span_utils.py:372
  • Draft comment:
    Consider adding a docstring for _extract_model_name_from_association_metadata to clarify what metadata is expected and that it retrieves the 'ls_model_name', returning 'unknown' if not found.
  • Reason this comment was not posted:
    Confidence changes required: 20% <= threshold 50% None
3. packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/span_utils.py:373
  • Draft comment:
    Typo: There's an extra space between 'None' and ')' in the function parameter declaration. Consider removing the space for consistency.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% While the comment is technically correct about the extra space, this is an extremely minor formatting issue. Such minor spacing issues are typically handled automatically by code formatters like black, pylint, or other tools. It doesn't affect functionality and isn't worth a human reviewer's attention. The comment is factually accurate. Perhaps maintaining strict formatting consistency is important for this project's standards. Even if formatting is important, this is too minor to warrant a manual review comment. This should be handled by automated tools. Delete this comment as it's too minor of a formatting issue to warrant manual review attention.

Workflow ID: wflow_soMz3T6dtXfrolRh

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

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: 0

🧹 Nitpick comments (1)
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/span_utils.py (1)

371-372: Remove unnecessary empty lines.

The extra empty lines before the new function are not needed and don't follow the existing spacing pattern in the file.

-

-
+
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4f13da7 and 44106ae.

📒 Files selected for processing (2)
  • packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/callback_handler.py (2 hunks)
  • packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/span_utils.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/callback_handler.py (1)
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/span_utils.py (1)
  • _extract_model_name_from_association_metadata (373-376)
🔇 Additional comments (3)
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/span_utils.py (1)

373-376: LGTM! Clean implementation of the helper function.

The function correctly implements the fallback mechanism for extracting model names from association metadata. The logic is straightforward, handles edge cases appropriately, and follows the existing code conventions.

packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/callback_handler.py (2)

40-40: LGTM! Proper import of the new helper function.

The import is correctly added and follows the existing import pattern from the span_utils module.


512-514: LGTM! Well-implemented fallback mechanism.

The integration properly implements the cascading fallback approach for model name extraction. The safety check for hasattr(context_api, "get_value") is a good defensive programming practice, and the logic correctly uses the association_properties from the current context.

@2getsandesh
Copy link
Contributor Author

@nirga Hey Nir, this PR extends the existing logic for fetching the model name in metrics export.

Previously, as per @LakshmiPriyaSujith ’s PR, the model name was fetched from the response metadata. However, in some cases, the model name was missing in the response metadata, and as a result, the metrics were showing the model name as "unknown".

This PR adds a fallback mechanism:
If the model name is not available in the response metadata, it now attempts to retrieve it from the association metadata.

After these changes, the model name is correctly populated in the exported metrics where it was previously "unknown".

@nirga nirga merged commit feb570b into traceloop:main Aug 8, 2025
8 of 9 checks passed
nina-kollman pushed a commit that referenced this pull request Aug 11, 2025
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.

3 participants