How to use captureException in Nuxt on Cloudflare #18587
-
|
Very happy with the Cloudflare Nitro plugin as introduced in #15597, that captures unhandled errors 👍 But I'm not clear on how we can use Sentry.captureException (or other methods for that matter)... The docs show this example, but that will not work import * as Sentry from "@sentry/nuxt";
try {
aFunctionThatMightFail();
} catch (err) {
Sentry.captureException(err);
}Ive tried this approach but with explicitly initializing sentry, but that does not work either, at least not is a cloudfalre environment (it does work on node) import * as Sentry from '@sentry/nuxt'
import { getSampleRates } from '~/config/sentry'
export const useSentry = () => {
const sentry = Sentry
const {
sentry: { dsn, environment, enabledServer, enabled }
} = useRuntimeConfig()
if (!Sentry.isInitialized()) {
console.log('Initializing useSentry...')
const sampleRates = getSampleRates(environment ?? 'prod')
const { sampleRate, tracesSampleRate } = sampleRates
sentry.init({
enabled: enabledServer && enabled,
dsn,
sampleRate,
tracesSampleRate,
environment: import.meta.dev ? 'dev' : environment
})
}
return { sentry, captureException: sentry.captureException.bind(sentry) }
}Any help would be welcome! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
@s1gr1d Maybe you have some insight into the matter? Thanks :) |
Beta Was this translation helpful? Give feedback.
-
|
Hi, using the exported methods like The docs for setting up the plugin can be found here: https://docs.sentry.io/platforms/javascript/guides/cloudflare/frameworks/nuxt/ Make sure that you deleted the |
Beta Was this translation helpful? Give feedback.
I created a minimal reproduction here (it's very minimal, I'm not using a lot of settings here): https://github.com/s1gr1d/nuxt-cloudflare-18587
Maybe you can use this as a base for your reproduction. However,
captureExceptionworks in this case.And regarding
useSentry(): Is there a specific reason you want to use it like this and not with a regular import from@sentry/nuxt?