Skip to content

feat: add support for langchain embedding#157

Open
minimAluminiumalism wants to merge 9 commits intoalibaba:mainfrom
minimAluminiumalism:main
Open

feat: add support for langchain embedding#157
minimAluminiumalism wants to merge 9 commits intoalibaba:mainfrom
minimAluminiumalism:main

Conversation

@minimAluminiumalism
Copy link
Copy Markdown
Contributor

@minimAluminiumalism minimAluminiumalism commented Mar 26, 2026

Description

Implement #142

Semconv ref https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/#embeddings

Clipboard_Screenshot_1774509500

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

instrumentation-loongsuite/loongsuite-instrumentation-langchain/tests/test_embedding_spans.py

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 future langchain_core.embeddings.Embeddings subclasses.
  • 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.

@alibaba alibaba deleted a comment from Copilot AI Apr 1, 2026
Copy link
Copy Markdown
Collaborator

@Cirilla-zmh Cirilla-zmh left a comment

Choose a reason for hiding this comment

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

Thanks for this great PR! Some comments should be resolved before getting merged.

Comment thread instrumentation-loongsuite/loongsuite-instrumentation-langchain/CHANGELOG.md Outdated
@Cirilla-zmh
Copy link
Copy Markdown
Collaborator

@minimAluminiumalism Hey! Thank you for your outstanding contributions over time. We are very pleased to invite you to become an approver for loongsuite-python-agent. If you are willing, you can leave an 👍 under this comment, and I’ll be happy to submit a PR for this.

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

@github-actions
Copy link
Copy Markdown

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.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label Apr 16, 2026
- 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
@github-actions github-actions Bot removed the Stale label Apr 19, 2026
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.
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.

5 participants