Skip to content

Commit

Permalink
ref: Only send 100 sessions in one envelope (#669)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Apr 17, 2020
1 parent cd64657 commit 8bd8044
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
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

0 comments on commit 8bd8044

Please sign in to comment.