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

Sentry Deno - supabase edge function not picking up errors #15229

Closed
3 tasks done
aaa3334 opened this issue Jan 30, 2025 · 2 comments
Closed
3 tasks done

Sentry Deno - supabase edge function not picking up errors #15229

aaa3334 opened this issue Jan 30, 2025 · 2 comments
Labels
Package: deno Issues related to the Sentry Deno SDK

Comments

@aaa3334
Copy link

aaa3334 commented Jan 30, 2025

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/deno

SDK Version

import * as Sentry from "npm:@sentry/deno";

Framework Version

Deno with Supabase

Link to Sentry event

No response

Reproduction Example/SDK Setup

import * as Sentry from "npm:@sentry/deno";

Sentry.init({
  // https://docs.sentry.io/product/sentry-basics/concepts/dsn-explainer/#where-to-find-your-dsn
  dsn: Deno.env.get("SENTRY_DSN"),
  // defaultIntegrations: false,
  // Performance Monitoring
  tracesSampleRate: 1.0,
  // debug: true,
});


Sentry.setTag("region", Deno.env.get("SB_REGION"));
Sentry.setTag("execution_id", Deno.env.get("SB_EXECUTION_ID"));
Sentry.captureMessage("Hello, world!");


const handler = async (_request: Request): Promise<Response> => {
.....

  Sentry.captureException(new Error("Good bye")); -- This works

try{
...
  setTimeout(() => {
      throw new Error();
    }); -- This comes up with an error on supabase edge function but nothing comes up in the sentry dashboard

...

  } catch (error) {
    Sentry.captureException(error);
    console.error(error);

    return new Response(JSON.stringify(error), {
      status: 500,
      headers: {
        "Content-Type": "application/json",
      },
    });
  }
};

Steps to Reproduce

  1. Create an edge function or add into an existing
  2. Added in the Sentry code above (I originally followed the installation steps in Sentry itself and on Supabase's website but I realised its outdated as the deno.land package is depreciated. I am now using the npm install as in the code above
  3. Trigger the edge function

Note:
6. If this: setTimeout(() => { throw new Error(); }); is not in there, the messages above work and send through (like the 'Good bye' and 'Hello world'. If it is in there however, I get the logs appearing in supabase edge function until that point, then I get the error. I do not get any of the Good bye or Hellp world ones.

Expected Result

That this error would come up in sentry runtime and adding in this error (the example error) wouldn't stop any of the errors from going to sentry.

It is not however. I do see the error in the edgefunctions logs on supabase but not anywhere else.

Note I can see results from eg:
Sentry.captureException(new Error("Good bye"));
or
Sentry.captureMessage("Hello, world!");

Note this may be the expected behaviour and the setTimeout(() => { throw new Error(); }); might not be meant to throw an error picked up here - but that it is not working shows maybe it wont pick up other errors in here either....

Actual Result

Nothing comes up in Sentry.

This is the log for the error in the supabase edge function logs:

{
"event_message": "event loop error: Error: test\n at file:///Users/a/Documents/Automations/supabase-edge-functions/supabase/functions/pilot2email/index.ts:50:13\n at eventLoopTick (ext:core/01_core.js:203:13)",
"id": "33341939-735b-4c14-89ae-dc707dc284f0",
"metadata": [
{
"boot_time": null,
"cpu_time_used": null,
"deployment_id": "cmhsbvzpocwhojvycyin_ca0f2255-4455-42b7-8ca6-4c4ef8284b7f_16",
"event_type": "UncaughtException",
"execution_id": "506ce836-5122-4273-a7d7-ea1b7f34b2f3",
"function_id": "ca0f2255-4455-42b7-8ca6-4c4ef8284b7f",
"level": "error",
"memory_used": [],
"project_ref": "cmhsbvzpocwhojvycyin",
"reason": null,
"region": "ap-southeast-2",
"served_by": "supabase-edge-runtime-1.66.5 (compatible with Deno v1.45.2)",
"timestamp": "2025-01-30T04:59:09.683Z",
"version": "16"
}
],
"timestamp": 1738213153590102
}

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jan 30, 2025
@github-actions github-actions bot added the Package: deno Issues related to the Sentry Deno SDK label Jan 30, 2025
@mydea
Copy link
Member

mydea commented Jan 30, 2025

Hey, thanks for writing in. Is the issue only happening inside of setTimeout calls? If so, I would assume it is simply due to timing issues and things happening outside of the thread 🤔 Like, at the point that the timeout function is called, the response has already been sent, and possibly Sentry doesn't catch stuff anymore then.

I believe you need to wrap the content of your setTimeout callback in try-catch itself, then it should work - a bit manual, but you can possibly extract this into a utility:

function wrapWithSentry(callback) {
  return (...args) => {
    try {
      callback(...args);
    } catch (error) {
      Sentry.captureException(error);
    }
}

// then...
setTimeout(wrapWithSentry(() => {
    throw new Error();
});

Does that work for you?

@aaa3334
Copy link
Author

aaa3334 commented Jan 31, 2025

Hi Mydea,

Thank you for the response! Yes that works! Thank you! It was within a try catch block but will try and make them smaller to ensure it captures them properly

@aaa3334 aaa3334 closed this as completed Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: deno Issues related to the Sentry Deno SDK
Projects
Archived in project
Development

No branches or pull requests

2 participants