Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(langchain): Makespan_map an instance variable#4476

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@szokeasaurusrex
Copy link
Member

@szokeasaurusrexszokeasaurusrex commentedJun 16, 2025
edited
Loading

span_map should be an instance variable; otherwise, separate instances of theSentryLangchainCallback share the samespan_map object, which is clearly not intended here.

Also, remove themax_span_map_size class variable, it is always set on the instance, and so not needed.

Ref#4443

@codecov
Copy link

codecovbot commentedJun 16, 2025
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.69%. Comparing base(0a2d858) to head(d71743f).
Report is 1 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@##           master    #4476      +/-   ##==========================================- Coverage   80.70%   80.69%   -0.02%==========================================  Files         156      156                Lines       16475    16474       -1       Branches     2799     2799              ==========================================- Hits        13296    13293       -3- Misses       2296     2298       +2  Partials      883      883
Files with missing linesCoverage Δ
sentry_sdk/integrations/langchain.py70.12% <100.00%> (-1.43%)⬇️

... and1 file with indirect coverage changes

@szokeasaurusrexszokeasaurusrexforce-pushed thecursor/fix-race-condition-and-add-test-04f0 branch 2 times, most recently from329ed33 to906f75fCompareJune 16, 2025 13:44
@szokeasaurusrexszokeasaurusrex marked this pull request as ready for reviewJune 24, 2025 12:43
@szokeasaurusrexszokeasaurusrex requested a review froma team as acode ownerJune 24, 2025 12:43
@szokeasaurusrexszokeasaurusrexforce-pushed thecursor/fix-race-condition-and-add-test-04f0 branch from906f75f to876e6fbCompareJune 24, 2025 12:43
Copy link
Contributor

@sentrivanasentrivana left a comment
edited
Loading

Choose a reason for hiding this comment

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

Q: Was this an actual problem or is this more of a nice-to-have small refactor? As I understand from the other PR, we're actively avoiding having more than oneSentryLangchainCallback around at a time.

I think the change itself is fine but we don't need tests for an implementation detail like this. We also don't test thatmax_span_map_size,include_prompts, etc. are not shared between instances. (And we also shouldn't test that, because it's not behavior worth testing, and the tests would just add clutter without any signal.)

Copy link
Contributor

@sentrivanasentrivana left a comment

Choose a reason for hiding this comment

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

See previous comment, looks good but let's remove the tests (or at leasttest_span_map_not_class_attribute)

@szokeasaurusrex
Copy link
MemberAuthor

Q: Was this an actual problem or is this more of a nice-to-have small refactor? As I understand from the other PR, we're actively avoiding having more than one SentryLangchainCallback around at a time.

@sentrivana Yes, so the problem occurred when attempting to reproduce#4443. I was confused why, despite having two callbacks, the data in Sentry was not duplicated. I assumed that perhaps theDedupeIntegration was dropping stuff, but when I enableddebug=True in the SDK init, I got the following error, instead of a notice that theDedupeIntegration dropped the extra span:

 [sentry] ERROR: Internal error in sentry_sdkTraceback (most recent call last):  File "/Users/dszoke/Development/SDK/sentry-python/sentry_sdk/integrations/langchain.py", line 267, in on_llm_end    span_data = self.span_map[run_id]                ~~~~~~~~~~~~~^^^^^^^^KeyError: UUID('2a2c72c8-66f1-4607-b4d2-bd6e93125c39')

The reason, of course, is that the first callback which ends deletes the span from thespan_map, so that when the duplicate callback is called, that span is gone.

Of course, you are right that we try to only have one callback per LLM request in#4485. But, what happens if we have concurrent requests to LLMs, or some other more complex setup, where having two callbacks would be expected? I am unsure how realistic such setups are, but if they do occur, I am pretty confident that we don't want the span map to be shared between the instances.

@sentrivana
Copy link
Contributor

Not against the change itself, seems reasonable in any case.

I was more pondering if this is behavior that needs testing (rather than a small internal refactor), but if you believe it is, I'd saytest_span_map_is_instance_variable is sufficient. I'd removetest_span_map_not_class_attribute as it doesn't add any value -- we should test behavior, not implementation details, and the behavior in this case is covered by the first test already.

szokeasaurusrex reacted with thumbs up emoji

@szokeasaurusrexLinear
Copy link
MemberAuthor

sounds reasonable, the first test is definitely more important anyhow

@szokeasaurusrexszokeasaurusrexforce-pushed thecursor/fix-race-condition-and-add-test-04f0 branch from876e6fb tobecd3eaCompareJune 25, 2025 09:36
@szokeasaurusrexszokeasaurusrexenabled auto-merge (squash)June 25, 2025 09:36
@szokeasaurusrexszokeasaurusrexforce-pushed thecursor/fix-race-condition-and-add-test-04f0 branch frombecd3ea tod71743fCompareJune 25, 2025 09:40
@szokeasaurusrexszokeasaurusrex merged commit7804260 intomasterJun 25, 2025
136 checks passed
@szokeasaurusrexszokeasaurusrex deleted the cursor/fix-race-condition-and-add-test-04f0 branchJune 25, 2025 09:47
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@sentrivanasentrivanaAwaiting requested review from sentrivana

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@szokeasaurusrex@sentrivana@cursoragent

[8]ページ先頭

©2009-2025 Movatter.jp