-
Couldn't load subscription status.
- Fork 569
Fix clickhouse logic for generator case #4722
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,40 +146,47 @@ def _inner_send_data( | |
| **kwargs: Any, | ||
| ) -> Any: | ||
| span = getattr(self.connection, "_sentry_span", None) | ||
| if span is None: | ||
| return original_send_data( | ||
| self, sample_block, data, types_check, columnar, *args, **kwargs | ||
| ) | ||
|
|
||
| if span is not None: | ||
| data = _get_db_data(self.connection) | ||
| _set_on_span(span, data) | ||
|
|
||
| if should_send_default_pii(): | ||
| saved_db_data: dict[str, Any] = getattr( | ||
| self.connection, "_sentry_db_data", {} | ||
| ) | ||
| db_params: list[Any] = saved_db_data.get("db.params") or [] | ||
| db_data = _get_db_data(self.connection) | ||
| _set_on_span(span, db_data) | ||
|
|
||
| if isinstance(data, (list, tuple)): | ||
| db_params.extend(data) | ||
| saved_db_data: dict[str, Any] = getattr(self.connection, "_sentry_db_data", {}) | ||
| db_params: list[Any] = saved_db_data.get("db.params") or [] | ||
|
|
||
| else: # data is a generic iterator | ||
| orig_data = data | ||
| if should_send_default_pii(): | ||
| if isinstance(data, (list, tuple)): | ||
| db_params.extend(data) | ||
|
|
||
| # Wrap the generator to add items to db.params as they are yielded. | ||
| # This allows us to send the params to Sentry without needing to allocate | ||
| # memory for the entire generator at once. | ||
| def wrapped_generator() -> "Iterator[Any]": | ||
| for item in orig_data: | ||
| db_params.append(item) | ||
| yield item | ||
| else: # data is a generic iterator | ||
| orig_data = data | ||
|
|
||
| # Replace the original iterator with the wrapped one. | ||
| data = wrapped_generator() | ||
| # Wrap the generator to add items to db.params as they are yielded. | ||
| # This allows us to send the params to Sentry without needing to allocate | ||
| # memory for the entire generator at once. | ||
| def wrapped_generator() -> "Iterator[Any]": | ||
| for item in orig_data: | ||
| db_params.append(item) | ||
| yield item | ||
|
|
||
| span.set_attribute("db.params", _serialize_span_attribute(db_params)) | ||
| # Replace the original iterator with the wrapped one. | ||
| data = wrapped_generator() | ||
|
|
||
| return original_send_data( | ||
| rv = original_send_data( | ||
| self, sample_block, data, types_check, columnar, *args, **kwargs | ||
| ) | ||
|
|
||
| if should_send_default_pii() and db_params: | ||
| # need to do this after the original function call to make sure | ||
| # db_params is populated correctly | ||
| saved_db_data["db.params"] = db_params | ||
| span.set_attribute("db.params", _serialize_span_attribute(db_params)) | ||
|
|
||
| return rv | ||
|
Comment on lines
+178
to
+188
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential bug: If
|
||
|
|
||
| clickhouse_driver.client.Client.send_data = _inner_send_data | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved this to an early return