Skip to content

Force Sentry to wait for every captureException call #15058

@cideM

Description

@cideM

Problem Statement

I have been working with the Go SDK for a while now and it's very pleasant to use and even includes a Sync transport.

I am now working in a Javascript project that uses a framework which unfortunately calls process.exit quite often. As a result, Sentry errors never make it to our dashboard, since Sentry doesn't have time to flush the buffer. I thought I could just set some option and force Sentry to wait for every single captureException call

Solution Brainstorm

One potential workaround would be to overwrite process.exit and call Sentry.close() in there.

I thought that I could also provide a sync transport (there appears to be none) so I tried something very simple:

const makeTransport = (options: NodeTransportOptions): Transport => {
  return {
    send: (e: Envelope): Promise<TransportMakeRequestResponse> => {
      console.log("send", e) // <-- console.log that transport is working
      return Promise.resolve({
        statusCode: 200,
        headers: {
          "x-sentry-rate-limits": null,
          "retry-after": null,
        },
      });
    },
    flush: (timeout?: number): Promise<boolean> => {
      console.log("flush");
      return Promise.resolve(true);
    },
  };
};

Later in this file I am doing the following to trigger the custom transport:

Sentry.init({
  debug: true,
  enabled: true,
  dsn: "....",
  transport: makeTransport,
  attachStacktrace: true,
});
Sentry.captureException("test");

I'd expect to see something in my console that indicates that send was called, but I don't. Is there some buffering going on before my custom transport is called?

It seems that there is currently no way to force Sentry to wait until every single captureException call has finished.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions