Skip to content

Conversation

@constantinius
Copy link
Contributor

Description

Wrap the backends OpenAIEmbeddings, AzureOpenAIEmbeddings, VertexAIEmbeddings, BedrockEmbeddings, CohereEmbeddings, MistralAIEmbeddings, HuggingFaceEmbeddings, OllamaEmbeddings and their embed_documents, embed_query, aembed_documents, aembed_query methods to properly instrument embeddings

Issues

Closes https://linear.app/getsentry/issue/TET-1460/add-embedding-support-for-langchain

Reminders

@constantinius constantinius requested a review from a team as a code owner November 19, 2025 18:42
@linear
Copy link

linear bot commented Nov 19, 2025

@constantinius constantinius requested a review from a team November 19, 2025 18:42
@codecov
Copy link

codecov bot commented Nov 19, 2025

Codecov Report

❌ Patch coverage is 89.88764% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.01%. Comparing base (48ddf8c) to head (05deaa3).
⚠️ Report is 2 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/integrations/langchain.py 89.65% 2 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5120      +/-   ##
==========================================
+ Coverage   83.95%   84.01%   +0.06%     
==========================================
  Files         180      180              
  Lines       18077    18168      +91     
  Branches     3215     3227      +12     
==========================================
+ Hits        15176    15264      +88     
+ Misses       1919     1916       -3     
- Partials      982      988       +6     
Files with missing lines Coverage Δ
sentry_sdk/consts.py 99.41% <100.00%> (+<0.01%) ⬆️
sentry_sdk/integrations/langchain.py 71.50% <89.65%> (+3.25%) ⬆️

... and 2 files with indirect coverage changes

@sentrivana sentrivana mentioned this pull request Nov 20, 2025
sentrivana added a commit that referenced this pull request Nov 20, 2025
### Description
Regenerating tox because we need to update the config for the langchain
test suite in #5120 and I
don't want to pull in lots of unrelated changes on the feature branch.

Dramatiq 2.0 has been released and our tests fail on it. Excluding it
for now, we will follow up in
#5123.

#### Issues
<!--
* resolves: #1234
* resolves: LIN-1234
-->

#### Reminders
- Please add tests to validate your changes, and lint your code using
`tox -e linters`.
- Add GH Issue ID _&_ Linear ID (if applicable)
- PR title should use [conventional
commit](https://develop.sentry.dev/engineering-practices/commit-messages/#type)
style (`feat:`, `fix:`, `ref:`, `meta:`)
- For external contributors:
[CONTRIBUTING.md](https://github.com/getsentry/sentry-python/blob/master/CONTRIBUTING.md),
[Sentry SDK development docs](https://develop.sentry.dev/sdk/), [Discord
community](https://discord.gg/Ww9hbqr)
@constantinius constantinius enabled auto-merge (squash) November 20, 2025 10:11
if hasattr(provider_class, "aembed_query"):
provider_class.aembed_query = _wrap_async_embedding_method(
provider_class.aembed_query
)
Copy link

Choose a reason for hiding this comment

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

Bug: Missing guard against double-wrapping embedding methods

The _patch_embeddings_provider function lacks a guard to prevent double-wrapping when setup_once is called multiple times. Each call wraps the methods again, creating nested wrappers that can cause incorrect behavior. Other integrations like Celery, Huey, and Beam use a _sentry_is_patched flag to prevent this issue. The tests explicitly call setup_once multiple times, which triggers this bug.

Fix in Cursor Fix in Web

@constantinius constantinius merged commit 7d91ce7 into master Nov 20, 2025
132 checks passed
@constantinius constantinius deleted the constantinius/feat/integrations/langchain-genai-embeddings branch November 20, 2025 13:17
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.

4 participants