Skip to content

Conversation

minimAluminiumalism
Copy link
Contributor

@minimAluminiumalism minimAluminiumalism commented Sep 19, 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.

Implement #3384

Span generation conditions

EMBEDDING

  • LangChain Embedding components: OpenAIEmbeddings().embed_documents()
  • Components with embeddingor embed in name

RETRIEVER

  • BaseRetriever subclass calls: retriever.invoke()
  • Components with retriever, retrieve, search in name

RERANKER

  • Components with rerank or reorder in name

GENERATION

  • LLM component calls: ChatOpenAI().invoke()
  • All non-embedding language models

Important

Expands span kind functionality in Langchain instrumentation by adding new span kinds and updating callback handler logic.

  • Behavior:
    • Adds new span kinds EMBEDDING, RETRIEVER, RERANKER, and GENERATION to TraceloopSpanKindValues in semconv_ai/__init__.py.
    • Updates TraceloopCallbackHandler in callback_handler.py to determine span kinds using _determine_llm_span_kind() and _determine_chain_span_kind().
    • Implements on_retriever_start() and on_retriever_end() in callback_handler.py to handle retriever spans.
  • Tests:
    • Adds test_span_kinds.py to test span kind detection and creation for various models and chains.
  • Misc:
    • Updates pyproject.toml to use local path for opentelemetry-semantic-conventions-ai dependency.

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

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 7e7fc67 in 2 minutes and 8 seconds. Click for details.
  • Reviewed 574 lines of code in 5 files
  • Skipped 1 files when reviewing.
  • Skipped posting 9 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/__init__.py:86
  • Draft comment:
    The new wrapper for CallbackManager.configure is well integrated. Ensure that duplicate handler additions are avoided if the method is invoked multiple times.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
2. packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/__init__.py:168
  • Draft comment:
    Properly unwrapping CallbackManager.configure in _uninstrument ensures clean removal. This is consistent with the instrumentation logic.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
3. packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/callback_handler.py:381
  • Draft comment:
    The new _determine_llm_span_kind method is clear and assigns span kind based on the serialized model info. Consider caching the lowercased class name to avoid recalculating in multiple conditions.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
4. packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/callback_handler.py:395
  • Draft comment:
    The _determine_chain_span_kind function covers various scenarios well. For minor performance and consistency gains, consider storing the lowercased class name in a variable instead of repeatedly calling lower().
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50% The suggestion is technically correct - there are multiple calls to class_name.lower() which could be optimized. However, this is a minor performance optimization that would only save a few string operations. The current code is more readable with the inline .lower() calls. The performance impact would be negligible in the context of the larger operations this code is performing (tracing and instrumentation). The comment identifies a real optimization opportunity. In performance-critical code, reducing redundant string operations could be important. While technically correct, this optimization would be premature. The method is called during tracing/instrumentation where network and IO operations dominate performance. The readability benefit of inline .lower() outweighs the minor performance gain. Delete the comment. While technically correct, this optimization suggestion is too minor to be worth implementing, and the current code is more readable.
5. packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/callback_handler.py:463
  • Draft comment:
    Splitting the base_kind determination from the chain span type calculation in on_chain_start improves clarity. The updated logic cleanly distinguishes workflow and task spans.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% This comment is purely informative, explaining the changes made in the code without providing any actionable feedback or suggestions. It does not align with the rules for useful comments in a pull request review.
6. packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/callback_handler.py:787
  • Draft comment:
    The new on_retriever_start and on_retriever_end implementations correctly create and finalize retriever spans. Limiting output size in on_retriever_end is a good safeguard.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% This comment is purely informative, as it only describes what the new implementations do and praises a safeguard without suggesting any changes or asking for clarification. It doesn't provide any actionable feedback or raise any concerns.
7. packages/opentelemetry-instrumentation-langchain/tests/test_span_kinds.py:12
  • Draft comment:
    The tests in test_span_kinds.py provide comprehensive coverage for the new span kind functionality. Excellent job verifying various scenarios!
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% This comment is purely informative and praises the author for their work. It does not provide any actionable feedback or suggestions for improvement.
8. packages/opentelemetry-instrumentation-langchain/pyproject.toml:29
  • Draft comment:
    Using a local path for opentelemetry-semantic-conventions-ai in development is acceptable; remember to update this for release builds if required.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% This comment is purely informative and does not provide a specific code suggestion or request for confirmation. It simply reminds the author to update a local path for release builds, which is not actionable feedback.
9. packages/opentelemetry-semantic-conventions-ai/opentelemetry/semconv_ai/__init__.py:302
  • Draft comment:
    The expansion of TraceloopSpanKindValues with new span kinds (EMBEDDING, RETRIEVER, RERANKER, GENERATION) is implemented correctly. Verify that downstream consumers handle these new values as expected.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.

Workflow ID: wflow_Vy61rLVv3YBFyt8v

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

@minimAluminiumalism minimAluminiumalism changed the title feat(semconv): expand genai span kind feat(semconv): expand traceloop span kind Sep 22, 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.

1 participant