Skip to content

fix(langchain): Ensure no duplicate SentryLangchainCallback #4485

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged

Conversation

szokeasaurusrex
Copy link
Member

Ensure that SentryLangchainCallback does not get added twice by also checking the inheritable_callbacks

Fixes #4443

@szokeasaurusrex szokeasaurusrex changed the title Szokeasaurusrex/fix-duplicate-langchain-callbacks fix(langchain): Ensure no duplicate SentryLangchainCallback Jun 17, 2025
Copy link

codecov bot commented Jun 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.67%. Comparing base (4a0e5ed) to head (083e45a).
Report is 6 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4485      +/-   ##
==========================================
- Coverage   80.67%   80.67%   -0.01%     
==========================================
  Files         156      156              
  Lines       16461    16463       +2     
  Branches     2799     2799              
==========================================
+ Hits        13280    13281       +1     
- Misses       2296     2298       +2     
+ Partials      885      884       -1     
Files with missing lines Coverage Δ
sentry_sdk/integrations/langchain.py 71.55% <100.00%> (+1.11%) ⬆️

... and 3 files with indirect coverage changes

@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/refactor-langchain-args branch from 8adbbe7 to 901b579 Compare June 17, 2025 10:29
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/fix-duplicate-langchain-callbacks branch from a42d29f to ccdd82f Compare June 17, 2025 10:29
szokeasaurusrex added a commit that referenced this pull request Jun 24, 2025
Resolving #4443 requires some changes to this method, but the current
`args`/`kwargs` business makes the method difficult to reason through.

This PR simplifies the logic by listing out the parameters we need to
access, so we don't need to access them through `args` and `kwargs`.

We also cut down on the amount of branching and the amount of variables
(`new_callbacks` vs `existing_callbacks`).

Behavior does not change in this PR; we fix the #4443 bug in #4485,
which is based on this PR
<!-- Describe your PR here -->

---

Thank you for contributing to `sentry-python`! Please add tests to
validate your changes, and lint your code using `tox -e linters`.

Running the test suite on your PR might require maintainer approval.
Base automatically changed from szokeasaurusrex/refactor-langchain-args to master June 24, 2025 12:37
@szokeasaurusrex szokeasaurusrex marked this pull request as ready for review June 24, 2025 12:37
@szokeasaurusrex szokeasaurusrex requested a review from a team as a code owner June 24, 2025 12:37
Ensure that `SentryLangchainCallback` does not get added twice by also checking the `inheritable_callbacks`

Fixes #4443
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/fix-duplicate-langchain-callbacks branch from ccdd82f to 083e45a Compare June 24, 2025 12:50
@szokeasaurusrex szokeasaurusrex merged commit 0a2d858 into master Jun 25, 2025
137 checks passed
@szokeasaurusrex szokeasaurusrex deleted the szokeasaurusrex/fix-duplicate-langchain-callbacks branch June 25, 2025 09:37
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Langchain Integration adds redundant callbacks
2 participants