sentry-native: Allow MIME detection for crashpad attachments in the backend

Environment

SaaS (https://sentry.io/)

Steps to Reproduce

Attach a JSON file and try to view it within the issue page. The preview option is greyed out with the text: Attachment cannot be previewed

A user got around this by adding contentType. It’s a property on the attachment object const filename = ‘XXX.json’; const contentType = ‘application/json’; // helps show Preview in Sentry hint.attachments = hint.attachments || []; hint.attachments.push({ filename, data, contentType });

We should try to derive the content type from the file name.

Expected Result

Can view the payload in the issue.

Actual Result

Screenshot 2023-10-11 at 4 30 07 PM

Product Area

Issues

Link

No response

DSN

No response

Version

No response

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

Hi @aallrd, We are currently working on integrating a change to the pipeline that would let attachment MIME detection run in the backend without you having to specify a content type in the SDK or change the file extension.

I think it does because it means that our attachments are generally MIME-detected and don’t require our users to provide a content type manually.

The other ticket might still make sense for the latter, but I think most users would be happy with the MIME detection in the backend if it actually runs rather than having to provide a content type for each attachment. So, #894 is more work and a less valuable feature.

So, the issue boils down to:

  • why don’t we get the MIME detection for crashpad events?
  • is it because the crashpad_handler does something wrong when attaching to multipart?

I know that the crashpad_handler sends all attachments as application/octet-stream while we do not add any Content-Type header to the envelope items that are attachments. So removing the Content-Type from the attachments sent from the crashpad_handler could do the trick.

Also, after a quick search in the backend, it seems like an attachment without a Content-Type header is the correct discriminator for automatic detection (cc: @Swatinem):

https://github.com/getsentry/sentry/blob/baaf0f404af0229334691f1ed4701950600f0de8/src/sentry/api/serializers/models/eventattachment.py#L39-L43

https://github.com/getsentry/sentry/blob/42050bfa4f3fcc6b19c9f104eba868dcc8535eaa/src/sentry/models/eventattachment.py#L184-L187

I have no way of seeing how attachments are processed, though, so I would need support from an employee when testing this.

If it turns out we can fix this at that point, I think it would be an extremely valuable fix and little effort.