Outdated setup of sentry for cloud function
nwaughachukwuma opened this issue · 1 comments
nwaughachukwuma commented
Environment
Sentry: v7.11.1
Node: v16.13.1
Firebase functions: 3.21.2
Steps to Reproduce
- Integrate and init sentry like so:
// sentry.ts
import * as Sentry from '@sentry/serverless'
Sentry.GCPFunction.init({
dsn: 'dsn-number',
tracesSampleRate: 1.0,
enabled: Boolean(process.env.FUNCTIONS_EMULATOR !== 'true'),
environment: 'prod',
release: build.env.VERSION,
})
export const GCPFunction = Sentry.GCPFunction
export const captureException = Sentry.captureException
export default Sentry
- Use it like so
import {GCPFunction} from './sentry.ts'
// like in the example - it didn't work.
export const forceErrorA = GCPFunction.wrapHttpFunction(((_, res) => {
throw new Error('Forced error')
}))
// a working construct - doesn't report error
export const forceErrorB = GCPFunction.wrapHttpFunction(
https.onRequest(async (_, res) => {
throw new Error('Forced error')
}),
)
- captureException from
@sentry/serverless
throws 'not a function' error
Expected Result
- to see an updated example on how to integrate
@sentry/serveless
on GCP cloud functions - for the integration to actually work.
Actual Result
No error is reported or captured. I had to do the following to report error, which renders GCPFunction.wrapHttpFunction redundant :
// sentry.ts
import * as Serverless from '@sentry/serverless'
import * as Sentry from '@sentry/node'
Serverless.GCPFunction.init({
dsn: 'dsn-number',
tracesSampleRate: 1.0,
enabled: Boolean(process.env.FUNCTIONS_EMULATOR !== 'true'),
environment: 'prod',
release: build.env.VERSION,
})
export const GCPFunction = Serverless.GCPFunction
export const captureException = Sentry.captureException
export default Sentry
then at use site
import {GCPFunction, captureException} from './sentry.ts'
export const forceError = GCPFunction.wrapHttpFunction(
https.onRequest(async (_, res) => {
captureException(new Error('Forced error'))
res.status(400).send('Forced error')
}),
)
AbhiPrasad commented
Closing this issue for repo clean up - we are planning to deprecate this examples repo and will be adding new examples elsewhere.