Skip to content

Commit 7c68b5e

Browse files
committed
feat: Send transactions in envelopes
This matches what the JS SDK does and what the Tracing dev docs indicates.
1 parent b539ecb commit 7c68b5e

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

sentry_sdk/client.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
from sentry_sdk._compat import string_types, text_type, iteritems
99
from sentry_sdk.utils import (
10-
handle_in_app,
11-
get_type_name,
1210
capture_internal_exceptions,
1311
current_stacktrace,
1412
disable_capture_event,
13+
format_timestamp,
14+
get_type_name,
15+
handle_in_app,
1516
logger,
1617
)
1718
from sentry_sdk.serializer import serialize
@@ -20,7 +21,7 @@
2021
from sentry_sdk.integrations import setup_integrations
2122
from sentry_sdk.utils import ContextVar
2223
from sentry_sdk.sessions import SessionFlusher
23-
from sentry_sdk.envelope import Envelope
24+
from sentry_sdk.envelope import Envelope, Item, PayloadRef
2425

2526
from sentry_sdk._types import MYPY
2627

@@ -334,7 +335,22 @@ def capture_event(
334335
if session:
335336
self._update_session_from_event(session, event)
336337

337-
self.transport.capture_event(event_opt)
338+
if event_opt.get("type") == "transaction":
339+
# Transactions should go to the /envelope/ endpoint.
340+
self.transport.capture_envelope(
341+
Envelope(
342+
headers={
343+
"event_id": event_opt["event_id"],
344+
"sent_at": format_timestamp(datetime.utcnow()),
345+
},
346+
items=[
347+
Item(payload=PayloadRef(json=event_opt), type="transaction"),
348+
],
349+
)
350+
)
351+
else:
352+
# All other events go to the /store/ endpoint.
353+
self.transport.capture_event(event_opt)
338354
return event_id
339355

340356
def capture_session(

0 commit comments

Comments
 (0)