Skip to content

Commit 0a8a804

Browse files
authored
fix(eventstream): Fix trace item inserts to EAP via Snuba HTTP backend (#103857)
Follow-up to #103566. The previous logic did not correctly serialize the trace item when making a POST request to the "/tests/entities/eap_items/insert_bytes" endpoint. With this updated logic we should see successful EAP inserts (example below). Querying via `docker exec -it snuba-clickhouse-1 clickhouse-client --query "SELECT item_id, project_id, organization_id, trace_id, item_type, timestamp FROM eap_items_1_local ORDER BY timestamp DESC LIMIT 5 FORMAT Pretty"`. Before ingesting new event: <img width="1061" height="183" alt="image" src="https://github.com/user-attachments/assets/9d2eca89-8fc9-4ab5-9fb3-ae34fd862ef8" /> After ingesting new event: <img width="1055" height="186" alt="image" src="https://github.com/user-attachments/assets/18caf67e-4d4b-4232-a2a9-b00225a52396" />
1 parent 11e4a63 commit 0a8a804

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/sentry/eventstream/snuba.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import urllib3
1010
from sentry_protos.snuba.v1.trace_item_pb2 import TraceItem
11+
from urllib3.fields import RequestField
12+
from urllib3.filepost import encode_multipart_formdata
1113

1214
from sentry import quotas
1315
from sentry.conf.types.kafka_definition import Topic, get_topic_codec
@@ -497,10 +499,16 @@ def _send(
497499

498500
def _send_item(self, trace_item: TraceItem) -> None:
499501
try:
502+
serialized = trace_item.SerializeToString()
503+
field = RequestField(name="item_0", data=serialized, filename="item_0")
504+
field.make_multipart(content_type="application/octet-stream")
505+
body, content_type = encode_multipart_formdata([field])
506+
500507
resp = snuba._snuba_pool.urlopen(
501508
"POST",
502509
EAP_ITEMS_INSERT_ENDPOINT,
503-
fields={"item_0": trace_item.SerializeToString()},
510+
body=body,
511+
headers={"Content-Type": content_type},
504512
)
505513

506514
if resp.status == 200:

0 commit comments

Comments
 (0)