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
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)
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:
crashpad_handlerdoes something wrong when attaching to multipart?I know that the
crashpad_handlersends all attachments asapplication/octet-streamwhile we do not add anyContent-Typeheader to the envelope items that are attachments. So removing theContent-Typefrom the attachments sent from thecrashpad_handlercould do the trick.Also, after a quick search in the backend, it seems like an attachment without a
Content-Typeheader 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.