Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions sentry_sdk/_batcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
from datetime import datetime, timezone
from typing import TYPE_CHECKING, TypeVar, Generic

from sentry_sdk.utils import format_timestamp
from sentry_sdk.envelope import Envelope, Item, PayloadRef
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Removed TypeVar breaks class definition at import time

High Severity

The T = TypeVar("T") definition was removed but Generic[T] is still used in the class declaration. This causes a NameError at import time, making the entire _batcher module un-importable. Since Batcher is imported by _log_batcher.py, _metrics_batcher.py, and _span_batcher.py, this cascades and breaks log, metrics, and span batching functionality. The PR title indicates this is a CI workflow test — these destructive changes appear unintentional for merge.

Fix in Cursor Fix in Web


if TYPE_CHECKING:
from typing import Optional, Callable, Any

T = TypeVar("T")


class Batcher(Generic[T]):
Comment on lines 7 to 8
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The _add_to_envelope and _flush methods use format_timestamp, Envelope, Item, and PayloadRef, but their imports have been removed, which will cause a NameError at runtime.
Severity: CRITICAL

Suggested Fix

Restore the deleted import statements for format_timestamp, Envelope, Item, and PayloadRef to make them available at runtime for the _add_to_envelope and _flush methods. Specifically, add back from sentry_sdk.utils import format_timestamp and from sentry_sdk.envelope import Envelope, Item, PayloadRef.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: sentry_sdk/_batcher.py#L7-L8

Potential issue: The pull request removes the imports for `format_timestamp`,
`Envelope`, `Item`, and `PayloadRef` from `sentry_sdk.utils` and `sentry_sdk.envelope`.
However, these are still used as constructors and functions within the
`_add_to_envelope` and `_flush` methods of the `Batcher` class. If the module were to
load successfully, calling these methods would result in a `NameError` at runtime
because these names are no longer defined in the module's scope.

Did we get this right? 👍 / 👎 to inform future reviews.

MAX_BEFORE_FLUSH = 100
Expand Down
Loading