You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Envelope exceeded size limits on file upload endpoints #2600
have a file upload endpoint (either form-data or binary)
inside the method that's executed on that endpoint capture the exception using the SentrySdk.CaptureException method
upload a file of size larger than 1MB to that endpoint
Expected Result
The captured exception gets sent to Sentry and the event is visible in the dashboard.
Actual Result
The envelope fails to get sent to sentry. With debug mode enabled this error is shown in the console:
fail: Sentry.ISentryClient[0]
Sentry rejected the envelope b028e13adc6b4344b34ec423354522ae. Status code: BadRequest. Error detail: envelope exceeded size limits (https://develop.sentry.dev/sdk/envelopes/#size-limits). Error causes: .
Looks like the uploaded file gets embedded in the envelope thus exceeding the envelope size limit.
Not sure if this is the normal behaviour but it would make sense to strip the uploaded file in that case so the envelope does not exceed the size limit. A workaround for this issue would be to set a method in SetBeforeSend that omits the Request.Data in case of file uploads.
Fair point. If the SDK can already predict that the envelope will be rejected due to size it should not simply attempt to send it.
I'm not sure where the attached file comes from? Are you capturing the exception manually?
@bitsandfoxes To add to this (I'm on the same team), we are utilizing the overload of the CaptureException method to configure the local scope on the fly and its where we are attaching the file, like so:
// Create attachment from uploaded file
var attachment = new Attachment(AttachmentType.Default, new StreamAttachmentContent(uploadedFileStream),
file.FileName, file.ContentType);
// Add attachment to Sentry
scope.AddAttachment(attachment);
We can work around the envelope exceeded limits by attaching a custom event processor as well, which strips the file from the request body, but if we do not do this, it might be useful for the SentrySdk to be a little more specific on the why the envelope was rejected, e.g. a multipart/form-data file was detected that exceeds the permitted file size limit.
Additionally, the attachment flow I outlined above does not seem to work - even though we attached the attachment in what looks to be the correct manner, it is still not visible in Sentry on web. Any pointers?
This starts to sound like multiple issues.
I'll bring "hitting size limits" up with the team. It seems like a recurring thing that we can definitely improve.
A workaround for this issue would be to set a method in SetBeforeSend that omits the Request.Data in case of file uploads.
You could rely on the hint object that gets passed to the SetBeforeSend callback instead of adding your own eventprocessor. The hint holds the attachments as a list and if you remove an attachment there it won't be sent with the event.
Additionally, the attachment flow I outlined above does not seem to work - even though we attached the attachment in what looks to be the correct manner, it is still not visible in Sentry on web. Any pointers?
Without having access to any logs it's a bit hard to tell. But you're right. It appears to be the correct manner. The only thing that comes to mind would be that since you're adding the attachment as a stream, during the upload that stream has been closed/disposed, causing the SDK to fail internally which would not be reported.
Can we make that limit on the server queryable maybe (so the client could read it via an API at startup)?
I don't think users that hit that problem are just slightly above the limit. So the users this should help are currently sending huge envelopes. This doesn't need to be this sophisticated. But filter obviously unreasonable envelopes (i.e. 3x? 5x? current max size) and revisit once we increase the accepted size.
I don't think users that hit that problem are just slightly above the limit.
Any data to back this assumption? I think it's very reasonable to be slightly over
So the users this should help are currently sending huge envelopes.
Relay drops it so it's already dealt with
But filter obviously unreasonable envelopes (i.e. 3x? 5x? current max size) and revisit once we increase the accepted size.
For that you need to know the size. Often we get a stream all the way to the writing it to the network so we only know the size anyway too late. All memory already allocated (or not allocated all at once, if we're really streaming through). Not sure this is worth the effort.
I have faced the same issue and tried to deal with it in SetBeforeSend callback by checking the Content-Type of the request and if it is set to multipart/form-data then set sentryEvent.Request.Data object to null. It didn't help and the request still gets rejected by the server. Can you advise on what I am missing here?
o.SetBeforeSend((sentryEvent, hint) =>
{
sentryEvent.Request.Data = null;
if (sentryEvent.Request.Headers.TryGetValue("Content-Type", out var contentType) &&
contentType.Contains("multipart/form-data"))
{
sentryEvent.Request.Data = null;
}
return sentryEvent;
});
Activity
bitsandfoxes commentedon Sep 7, 2023
Fair point. If the SDK can already predict that the envelope will be rejected due to size it should not simply attempt to send it.
I'm not sure where the attached file comes from? Are you capturing the exception manually?
fifi98 commentedon Sep 7, 2023
Correct - I am capturing the exception manually.
Here is a minimal reproduction snippet of code:
fobos531 commentedon Sep 8, 2023
@bitsandfoxes To add to this (I'm on the same team), we are utilizing the overload of the
CaptureExceptionmethod to configure the local scope on the fly and its where we are attaching the file, like so:We can work around the envelope exceeded limits by attaching a custom event processor as well, which strips the file from the request body, but if we do not do this, it might be useful for the
SentrySdkto be a little more specific on the why the envelope was rejected, e.g. amultipart/form-datafile was detected that exceeds the permitted file size limit.Additionally, the attachment flow I outlined above does not seem to work - even though we attached the attachment in what looks to be the correct manner, it is still not visible in Sentry on web. Any pointers?
bitsandfoxes commentedon Sep 8, 2023
This starts to sound like multiple issues.
I'll bring "hitting size limits" up with the team. It seems like a recurring thing that we can definitely improve.
You could rely on the
hintobject that gets passed to theSetBeforeSendcallback instead of adding your own eventprocessor. The hint holds theattachmentsas a list and if you remove an attachment there it won't be sent with the event.Without having access to any logs it's a bit hard to tell. But you're right. It appears to be the correct manner. The only thing that comes to mind would be that since you're adding the attachment as a stream, during the upload that stream has been closed/disposed, causing the SDK to fail internally which would not be reported.
4 remaining items
bitsandfoxes commentedon Jan 12, 2024
I don't think users that hit that problem are just slightly above the limit. So the users this should help are currently sending huge envelopes. This doesn't need to be this sophisticated. But filter obviously unreasonable envelopes (i.e. 3x? 5x? current max size) and revisit once we increase the accepted size.
bruno-garcia commentedon Jan 16, 2024
Any data to back this assumption? I think it's very reasonable to be slightly over
Relay drops it so it's already dealt with
For that you need to know the size. Often we get a stream all the way to the writing it to the network so we only know the size anyway too late. All memory already allocated (or not allocated all at once, if we're really streaming through). Not sure this is worth the effort.
lightel commentedon Feb 13, 2024
I have faced the same issue and tried to deal with it in
SetBeforeSendcallback by checking theContent-Typeof the request and if it is set tomultipart/form-datathen setsentryEvent.Request.Dataobject tonull. It didn't help and the request still gets rejected by the server. Can you advise on what I am missing here?bruno-garcia commentedon Feb 13, 2024
Best way to debug this is to keep the envelope around to check out what's going on:
sentry-dotnet/src/Sentry/Http/HttpTransportBase.cs
Line 362 in 00af4bc
With
SENTRY_KEEP_LARGE_ENVELOPE_PATHthe SDK will write the file somewhere, so u can check offline (attach here so we can debug for example)Note the SDK needs to be in
Debugmode (options.Debug = true)This can be found on our docs under 'troubleshooting': https://docs.sentry.io/platforms/dotnet/troubleshooting/#the-event-is-dropped-by-sentry-because-its-too-large
jamescrosswell commentedon Jul 1, 2025
From what I can tell, there's nothing for us to do in the SDK here so I'll close this for now.
If you believe there is a problem with the SDK or that the behaviour could be improved, feel free to reopen to continue the discussion.