fix(weave): Swallow GeneratorExit exceptions when consumer abandons the generator#6397
Merged
chance-wnb merged 1 commit intomasterfrom Mar 20, 2026
Merged
fix(weave): Swallow GeneratorExit exceptions when consumer abandons the generator#6397chance-wnb merged 1 commit intomasterfrom
chance-wnb merged 1 commit intomasterfrom
Conversation
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
Preview this PR with FeatureBee: https://beta.wandb.ai/?betaVersion=79540aa9fb2eef13c9717e6b9b88ab4745979bda |
64549ad to
9aa02e1
Compare
gtarpenning
approved these changes
Mar 19, 2026
Member
gtarpenning
left a comment
There was a problem hiding this comment.
amazing, that was annoying me
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
9aa02e1 to
d70833c
Compare
d70833c to
48418fe
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

suppress GeneratorExit errors in DataDog for streaming generator methods
Problem
Every call to the
/call/readendpoint (and any other endpoint that partially consumes a streaming generator) was producing error spans in DataDog witherror.type: builtins.GeneratorExit, despite the HTTP response being asuccessful 200. This generates unnecessary noises.
Exampes:
DD Trace for POST /traces/call/read
Root cause
ClickHouseTraceServer.call_readfetches only the first row fromcalls_query_streamand then explicitly closes the generator in itsfinallyblock:
res.close()injectsGeneratorExitinto the partially-consumed generator chain. This is the correct and expected Python pattern for releasing resources — the generator was intentionally closed early, not due to any error.However, two layers of DataDog tracing were incorrectly treating
GeneratorExitas an application error:Layer 1 —
TracingTraceServer(tracing_trace_server.py)Layer 2 —
@ddtrace.tracer.wrapon generator methods (clickhouse_trace_server_batched.py)ddtrace.tracer.wrapinternally usesyield fromto wrap generator functions, soGeneratorExitpropagates through its context manager and is recorded as an error on thecalls_query_streamand_query_streamspans.This produced three error spans in DataDog on every single
/call/readrequest:Fix
1.
tracing_trace_server.py— catchGeneratorExitin all streaming methodsAdded
except GeneratorExit: passinside thewith tracer.trace(...)block for all generator methods.GeneratorExitis aBaseException, not anException, so it bypasses normal error handling — this is the minimal targeted change.Applies to:
calls_query_stream,completions_create_stream,annotation_queues_query_stream.2.
datadog.py— newgenerator_tracedecoratorIntroduced
generator_trace(span_name)as a drop-in replacement for@ddtrace.tracer.wrapon generator functions. It creates a span that covers the full iteration lifetime and catchesGeneratorExitcleanly.3.
clickhouse_trace_server_batched.py— replace@ddtrace.tracer.wrapon generatorsReplaced
@ddtrace.tracer.wrapwith@generator_traceoncalls_query_streamand
_query_stream.Notice that catching these error at the HTTP endpoint root isn't enough: we don't want to see unexpected errors on any DD spans.
Verification
Without the fix, I got this DD trace:
https://us5.datadoghq.com/apm/trace/69bc788b000000004ed551844f71907b?graphType=waterfall&shouldShowLegend=true&spanID=9924611229400349424&timeHint=1773959307425.397&trace=AwAAAZ0INuMVPCpShwAAABhBWjBJTnZOWEFBQmVQZTN3c1ZFZlpkVk8AAAAkZjE5ZDA4MzctMmU3NS00OTkzLTk3MmMtOWZmZmU3ZjkxNzE0AAAAJg&traceQuery=
With the fix, I got this:
https://us5.datadoghq.com/apm/trace/69bc7d4c0000000057bf66bf13c0e7f1?spanID=7177803520423907467&timeHint=1773960524370.98&trace=AwAAAZ0ISXTmvZOdpgAAABhBWjBJU1g3ZEFBQm5NNTJuTnYxNnpyOVgAAAAkZjE5ZDA4NGEtMmRjNS00YjNiLThmNDYtN2E5ZTA0NWE2NmY5AAAACQ
Is there any valid case that we should surface up GeneratorExit exception from
calls_query_stream?No.
GeneratorExitis by definition a signal from the consumer saying "stop, I'm done with you" — it is never an application error. It carries no information about what went wrong; it only means the generator was closed early.