Skip to content

Built-in monitoring & alerting for stuck / unprocessed envelopes #4936

Closed

Description

@dalnoki

Problem Statement

A customer encountered an issue where their application silently stopped sending events to Sentry. After local investigation, they discovered a number of .envelope files accumulating in the SDK’s local Sentry folder including very large files (~2GB) and very old files (dating back to February).

After manually clearing the folder, the Sentry SDK immediately resumed normal operation.

To prevent this kind of silent failure, they are requesting a built-in mechanism in the Sentry SDK that can detect envelope backlogs and surface an alert or warning to the Sentry dashboard (or at least application logs) so teams can act before ingestion silently stops.

Solution Brainstorm

No response

Activity

  1. linear commented on Nov 27, 2025

    @linear
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Nov 27, 2025
  3. adinauer commented on Dec 1, 2025

    @adinauer
    Member

    @dalnoki is this Android, JVM Desktop or something else?

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Dec 1, 2025
  5. mhogerheijde commented on Dec 1, 2025

    @mhogerheijde

    Hi, original reporter here.

    This is on JVM 21, Temurin runtime. Desktop I guess? I mean: we're running it on a server 😁.

    We're using Java modules io.sentry:sentry and io.sentry:sentry-logback both version 8.26.0.

    On Nov. 6th we switched from 8.23.0 to 8.25.0
    On Nov. 18th we switched from 8.25.0 to 8.26.0

    The oldest unsent .envelope file in the system was from February, so none of these versions was able to clean up the backlog. We noticed that Sentry stopped sending since we sent a "startup warning" every release in order to verify we didn't break anything. We release every week and upon inspection Sentry SDK stopped sending messages somewhere halfway the release.

    Unfortunately, the engineer that worked on the production machine removed the envelopes instead of moving them for later inspection. So I can't tell you what was in the envelopes so you can reproduce.

    Please let me know if we can be of any (further) assistance.

  6. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Dec 1, 2025
  7. adinauer commented on Dec 1, 2025

    @adinauer
    Member

    Thanks for the additional details @mhogerheijde.

    Just to make sure, you did configure cacheDirPath, correct?

    Let me check if there's some cleanup we perform on Android but don't on JVM.

  8. 25 remaining items

  9. mhogerheijde commented on Dec 8, 2025

    @mhogerheijde

    We had a restart of our server today, and we are left with 13 unsent envelopes:

    .../sentry/846e2159c1635d9c7012a115a1da70403d376b04$ ls -alsh
    total 3,0M
    4,0K drwxr-xr-x 3 root root 4,0K dec  8 09:16 .
    4,0K drwxr-xr-x 3 root root 4,0K nov 24 09:56 ..
     24K -rw-r--r-- 1 root root  24K dec  5 08:14 2bc0884284de471382d3fba7e0fe1ad4.envelope
     24K -rw-r--r-- 1 root root  22K dec  5 08:35 53d8cc0aa3b64303b158e03c9281fb11.envelope
    2,7M -rw-r--r-- 1 root root 2,7M dec  2 08:45 78209d18ebce4877969c4702015b64f6.envelope
     24K -rw-r--r-- 1 root root  22K dec  5 08:40 816b29f32111405ea534a292a39d2d09.envelope
     24K -rw-r--r-- 1 root root  22K dec  5 08:40 8687919cc7354ddabe56103c548a7749.envelope
     24K -rw-r--r-- 1 root root  22K dec  5 08:30 91bcfd4882a64757b31547297f1c01c0.envelope
     24K -rw-r--r-- 1 root root  22K dec  5 08:45 aeb9de3e40404a9885a0bf277eaf39f2.envelope
     24K -rw-r--r-- 1 root root  22K dec  5 08:45 bc795219f1ef498cbaba360756e23747.envelope
     24K -rw-r--r-- 1 root root  22K dec  5 08:30 d7f819003c6f47d2983a34d116d9b2b2.envelope
     24K -rw-r--r-- 1 root root  22K dec  5 08:24 ea6969f78e5343de8538ac672ef86732.envelope
     24K -rw-r--r-- 1 root root  22K dec  5 08:24 f1806642a71c4252a6a457c2013f680b.envelope
     24K -rw-r--r-- 1 root root  22K dec  5 08:19 f5cd63ab95a845248e7cf6319215cfd5.envelope
     24K -rw-r--r-- 1 root root  24K dec  5 08:14 f8c2deeb7a23430fa01c78a8c84c859c.envelope
    4,0K drwxr-xr-x 2 root root 4,0K nov 24 09:56 outbox
    

    server time is UTC.

    Our backend is currently up-and-running. Sentry is reporting, but these envelopes are still lingering around in the queue. Current server time is

    $ date
    ma  8 dec 2025  9:56:55 UTC
    

    I can share the envelopes with you if you want, but since this is our production server, I'd rather not share those traces publicly.

  10. mhogerheijde commented on Dec 10, 2025

    @mhogerheijde

    FYI, the envelopes all seem to be valid JSON to me (they parse as such), and a quick visual inspection didn't seem to indicate something wrong with these files.

  11. lcian commented on Dec 10, 2025

    @lcian
    Member

    Thank you for the additional information, @mhogerheijde.
    My colleague @adinauer is currently OOO and will be back next Monday to continue looking into this.
    In the meantime you can send me a couple of those envelopes via email at lorenzo.cian@sentry.io and I can quickly check whether they are valid.

  12. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Dec 10, 2025
  13. mhogerheijde commented on Dec 10, 2025

    @mhogerheijde

    @lcian thanks for the update. For us there is currently no rush or otherwise urgency on this. We've changed our monitoring to also look at the cache size and if it grows to much we get alerts.

    I'll sent the captured envelopes to you soon.

    Just to make sure, you did configure cacheDirPath, correct?

    We do set cacheDirPath. Inside the container it is set to /etc/hiber/sentry. That path is mounted onto the docker host filesystem, so the cache directory is persisted across containers

  14. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Dec 10, 2025
  15. lcian commented on Dec 11, 2025

    @lcian
    Member

    @mhogerheijde I've reviewed one of your envelopes. The culprit (at least in that one), is a too large value in exceptions.values. That's an exception message that contains a very long SQL query.
    The result is that Relay rejects the envelope with status 400.
    Note that the envelope itself is not oversized, so I assume the SDK treats it differently from an oversized envelope, and ends up keeping it in the cache.
    I'll leave it to @adinauer to determine the best path forward here as this seems related to the SDK truncation project we're working on.

  16. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Dec 11, 2025
  17. self-assigned this
    on Dec 15, 2025
  18. adinauer commented on Dec 16, 2025

    @adinauer
    Member

    @mhogerheijde I just took a look at the envelope files you sent and tried sending one of those into Sentry which worked for me.
    I simply configured sentry.cache-dir-path=/Users/... and added:

    @Bean
    public Sentry.OptionsConfiguration<SentryOptions> sentryOptionsConfiguration() {
      return options -> {
        options.addIntegration(new SendCachedEnvelopeFireAndForgetIntegration(new SendFireAndForgetEnvelopeSender(() -> options.getCacheDirPath())));
      };
    }
    

    It picked up the file, sent it to Sentry and it showed up in UI.

    I'm assuming these files (except the large one) remained in cache dir because there was a temporary network issue, rate limit or similar.

    I created a PR which will change the SDK to delete the cache files instead of retrying for 4xx and 5xx responses. This means your cache dir should no longer be filling up once the change has been released. Our intent here is to not overwhelm Sentry after an outage, after load shedding or by piling up envelopes that can't be ingested and are retried continuously.

    If you would still like to see cases like the large query in Sentry, your best option is to implement the onOversizedEvent callback and truncate exception messages. I asked internally and we're careful with default truncations we put into the SDK since those have bitten us in the past. I do understand this can be frustrating - sorry!

    Please let us know if you need more help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

FeatureJava

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions