Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force Sentry to wait for every captureException call #15058

Open
cideM opened this issue Jan 17, 2025 · 0 comments
Open

Force Sentry to wait for every captureException call #15058

cideM opened this issue Jan 17, 2025 · 0 comments

Comments

@cideM
Copy link

cideM commented Jan 17, 2025

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.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jan 17, 2025
@cideM cideM changed the title Sync transport for NodeJS like in Golang Force Sentry to wait for every captureException call Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for: Product Owner
Development

No branches or pull requests

1 participant