feat: add support for langchain embedding#157
feat: add support for langchain embedding#157minimAluminiumalism wants to merge 9 commits intoalibaba:mainfrom
Conversation
…essor span support Automatically instrument BaseDocumentCompressor subclasses to emit rerank spans with OpenTelemetry semantic conventions. Uses __init_subclass__ hook to cover classes defined after instrumentation.
ca63521 to
7a72725
Compare
There was a problem hiding this comment.
Pull request overview
Adds LangChain Embeddings instrumentation to loongsuite-instrumentation-langchain, emitting GenAI embedding spans via opentelemetry-util-genai per the GenAI semantic conventions.
Changes:
- Introduces an Embeddings patch that wraps
embed_*/aembed_*on all current and futurelangchain_core.embeddings.Embeddingssubclasses. - Adds a comprehensive embedding span test suite (sync/async, error cases, dedup/proxy behavior, late subclassing, uninstrumentation).
- Documents embedding spans in the README and records the feature in the changelog.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| instrumentation-loongsuite/loongsuite-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/internal/patch_embedding.py | New patch module that wraps Embeddings methods and emits embedding spans through ExtendedTelemetryHandler. |
| instrumentation-loongsuite/loongsuite-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/init.py | Wires embedding instrumentation into the instrumentor’s instrument/uninstrument lifecycle. |
| instrumentation-loongsuite/loongsuite-instrumentation-langchain/tests/test_embedding_spans.py | New tests validating span creation, attributes, errors, deduplication, and uninstrument behavior for embeddings. |
| instrumentation-loongsuite/loongsuite-instrumentation-langchain/README.md | Adds “Embedding” span kind and its key attributes to the supported spans table. |
| instrumentation-loongsuite/loongsuite-instrumentation-langchain/CHANGELOG.md | Notes embedding span support in the Unreleased “Added” section. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Cirilla-zmh
left a comment
There was a problem hiding this comment.
Thanks for this great PR! Some comments should be resolved before getting merged.
|
@minimAluminiumalism Hey! Thank you for your outstanding contributions over time. We are very pleased to invite you to become an approver for If it’s convenient for you, you’re also welcome to join our DingTalk group and contact “希铭” in the group. We look forward to connecting with you more closely. |
|
This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment. |
- guard instrument_embeddings against double-instrument so the captured __init_subclass__ original can't be overwritten with the patched hook - fall back to class name when no model attribute is exposed so spans always carry a non-empty gen_ai.request.model - collapse the four wrapper factories into one sync + one async helper - match neighbouring CHANGELOG entry style (two-line wrap) - add regression tests for the idempotency and model-fallback fixes
Resolves ruff PLC0415 (`import` should be at the top-level of a file) flagged by the langchain lint job after the previous review-fix commit.

Description
Implement #142
Semconv ref https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/#embeddings
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
instrumentation-loongsuite/loongsuite-instrumentation-langchain/tests/test_embedding_spans.py
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.