Skip to content

ref(langchain): Greatly simplify _wrap_configure #4479

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

szokeasaurusrex
Copy link
Member

@szokeasaurusrex szokeasaurusrex commented Jun 16, 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


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.

Copy link

codecov bot commented Jun 16, 2025

Codecov Report

Attention: Patch coverage is 36.36364% with 7 lines in your changes missing coverage. Please review.

Project coverage is 80.63%. Comparing base (fedcb07) to head (901b579).
Report is 1 commits behind head on master.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/integrations/langchain.py 36.36% 4 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4479      +/-   ##
==========================================
- Coverage   80.64%   80.63%   -0.01%     
==========================================
  Files         142      142              
  Lines       16033    16037       +4     
  Branches     2747     2741       -6     
==========================================
+ Hits        12930    12932       +2     
- Misses       2236     2239       +3     
+ Partials      867      866       -1     
Files with missing lines Coverage Δ
sentry_sdk/integrations/langchain.py 70.43% <36.36%> (+2.40%) ⬆️

... and 4 files with indirect coverage changes

@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/refactor-langchain-args branch from f2bd2a6 to 9880666 Compare June 17, 2025 07:26
@szokeasaurusrex szokeasaurusrex marked this pull request as ready for review June 17, 2025 08:00
@szokeasaurusrex szokeasaurusrex requested a review from a team as a code owner June 17, 2025 08:00
@szokeasaurusrex szokeasaurusrex marked this pull request as draft June 17, 2025 08:01
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/refactor-langchain-args branch 2 times, most recently from e4dadc3 to 8adbbe7 Compare June 17, 2025 08:43
@szokeasaurusrex szokeasaurusrex marked this pull request as ready for review June 17, 2025 08:43
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 will introduce behavior changes in a subsequent PR
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/refactor-langchain-args branch from 8adbbe7 to 901b579 Compare June 17, 2025 10:29
szokeasaurusrex added a commit that referenced this pull request Jun 17, 2025
While implementing #4479, I noticed that our Langchain integration lacks support for the `local_callbacks` having type `BaseCallbackManager`, which according to the type hint is possible.

This change adds support for this case.
Copy link
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

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

Soo much better! 🥔

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.

2 participants