Skip to content
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

ref: Only send 100 sessions in one envelope #669

Merged
merged 1 commit into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import uuid
import random
from datetime import datetime
from itertools import islice
import socket

from sentry_sdk._compat import string_types, text_type, iteritems
Expand Down Expand Up @@ -99,10 +100,15 @@ def _init_impl(self):
def _send_sessions(sessions):
# type: (List[Any]) -> None
transport = self.transport
if sessions and transport:
if not transport or not sessions:
return
sessions_iter = iter(sessions)
while True:
envelope = Envelope()
for session in sessions:
for session in islice(sessions_iter, 100):
envelope.add_session(session)
if not envelope.items:
break
transport.capture_envelope(envelope)

try:
Expand Down
3 changes: 3 additions & 0 deletions sentry_sdk/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def update(
sid=None, # type: Optional[Union[str, uuid.UUID]]
did=None, # type: Optional[str]
timestamp=None, # type: Optional[datetime]
started=None, # type: Optional[datetime]
duration=None, # type: Optional[float]
status=None, # type: Optional[SessionStatus]
release=None, # type: Optional[str]
Expand All @@ -194,6 +195,8 @@ def update(
if timestamp is None:
timestamp = datetime.utcnow()
self.timestamp = timestamp
if started is not None:
self.started = started
if duration is not None:
self.duration = duration
if release is not None:
Expand Down