fix(sdk-crash): Add Trace ID#117372
Conversation
| value={ | ||
| "trace_id": uuid4().hex, | ||
| "span_id": None, |
There was a problem hiding this comment.
Bug: The code generates a trace_id but sets span_id to None, which is inconsistent and may cause issues in downstream systems that expect a valid span_id.
Severity: MEDIUM
Suggested Fix
Generate a valid span_id in addition to the trace_id. Instead of setting span_id to None, create a 16-character hex string, for example: "span_id": uuid4().hex[:16]. This ensures the trace context is complete and consistent.
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: src/sentry/utils/sdk_crashes/sdk_crash_detection.py#L134-L136
Potential issue: The code adds a trace context to SDK crash events by generating a
`trace_id` but explicitly sets the corresponding `span_id` to `None`. While the event
schema allows a null `span_id`, this is inconsistent with other parts of the codebase
where a valid hex `span_id` is always generated alongside a `trace_id`. This could cause
issues for downstream consumers like the EAP system, which may expect both a valid
`trace_id` and `span_id` to be present for tracing. A trace context with a valid trace
ID but a null span ID is semantically unusual and may be rejected by tracing
infrastructure.
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
Maybe it makes sense to fix this in the event manager. I imagine there could be more places that create an event that could lack a trace ID.
There was a problem hiding this comment.
We handle most of them in Relay — this appears to be unique among error-type occurrences in that it strips that relay-set default in postprocess. (Confirmed by looking at logs re: which projects are missing trace ID — only related to this case, it seems.)
Might be worth adding there as another backstop if this doesn't work, though.
We strip SDK crash errors in postprocess. This strips out their Trace ID; we need Trace IDs to store errors in EAP. This PR adds a new Trace ID to these errors.
932b611 to
d2d1d25
Compare
We strip SDK crash errors in postprocess. This strips out their Trace ID; we need Trace IDs to store errors in EAP.
This PR adds a new Trace ID to these errors.