Has anyone used attachment uploads from sentry?
Whenever the “extra” of “myAttachment” is found I try to upload it, but I never see it. In development I get a 201, but in prod I get “TypeError: Network request failed”.
Sentry.Browser.addGlobalEventProcessor(event => {
if (event?.extra?.myAttachment) {
try {
console.log('has myAttachment!');
const myAttachment = event.extra.myAttachment;
delete event.extra.myAttachment;
const client = Sentry.Browser.getCurrentHub().getClient();
if (!client) {
console.error(
new Error('No client available.'),
'sentry.uploadMyAttachment'
);
return event;
}
const dsn = client.getDsn();
if (!dsn) {
console.error(
new Error('No client DSN available.'),
'sentry.uploadMyAttachment'
);
return event;
}
if (!event.event_id) {
console.error(
new Error('No event_id available.'),
'sentry.uploadMyAttachment'
);
return event;
}
const endpoint = attachmentUrlFromDsn(dsn, event.event_id);
const formData = new FormData();
formData.append(
'my-attachment',
new Blob([JSON.stringify(myAttachment)], {
type: 'application/json'
}),
'myAttachment.json'
);
console.log('has myAttachment endpoint!', endpoint);
fetch(endpoint, { method: 'POST', body: formData })
.then(async res => {
const text = await res.text();
console.log('has myAttachment response!', {
status: res.status,
text
});
})
// we have to catch this otherwise it throws an infinite loop in Sentry
.catch(error => {
console.error(error, 'sentry.uploadMyAttachment.fetch');
});
} catch (error) {
console.error(error, 'sentry.uploadMyAttachment');
}
}
return event;
});