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

TypeError: Cannot convert undefined or null to object #5501

Closed
3 tasks done
P4sca1 opened this issue Jul 31, 2022 · 2 comments · Fixed by #5502
Closed
3 tasks done

TypeError: Cannot convert undefined or null to object #5501

P4sca1 opened this issue Jul 31, 2022 · 2 comments · Fixed by #5502
Assignees
Labels
Package: node Issues related to the Sentry Node SDK Type: Bug

Comments

@P4sca1
Copy link

P4sca1 commented Jul 31, 2022

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/node

SDK Version

7.8.0

Framework Version

express 5.0.0-beta.1

Link to Sentry event

No response

Steps to Reproduce

After ugprading @sentry/integrations, @sentry/node, and @sentry/tracing from version 7.7.0 to 7.8.0, my application no longer starts up.

/**
 * Initializes Sentry.
 * @see {@link https://docs.sentry.io/platforms/node/}
 *
 * @param app - the Express.js app. Used to configure the Sentry-Express integration.
 */
export function initSentry(app: Express) {
	const env = process.env.SENTRY_ENV || process.env.NODE_ENV || 'development'
	const version = process.env.PACKAGE_VERSION

	Sentry.init({
		dsn: 'xxx',
		release: version ? `api@${version}` : undefined,
		environment: env,
		integrations: [
			new Dedupe(),
			new RewriteFrames({ root }),
			new Sentry.Integrations.Http({ breadcrumbs: true, tracing: true }),
			new Integrations.Express({ app }),
			new Integrations.Prisma({ client: prisma }),
		],
		beforeBreadcrumb: (breadcrumb) => {
			// Filter out writes to apollographql use reporting API, because they are not helpful for error tracing
			// and spam breadcrumbs.
			if (
				breadcrumb.type === 'http' &&
				typeof breadcrumb.data?.url === 'string' &&
				breadcrumb.data.url.includes('usage-reporting.api.apollographql.com')
			) {
				return null
			}

			return breadcrumb
		},
		tracesSampleRate: 0.25,
	})
}

Expected Result

It should continue to work as in version 7.7.0.

Actual Result

TypeError: Cannot convert undefined or null to object
    at Function.getPrototypeOf (<anonymous>)
    at instrumentRouter (omitted/node_modules/@sentry/tracing/cjs/integrations/node/express.js:195:28)
    at Express.setupOnce (omitted/node_modules/@sentry/tracing/cjs/integrations/node/express.js:48:5)
    at omitted/node_modules/@sentry/src/integration.ts:68:1
    at Array.forEach (<anonymous>)
    at Object.setupIntegrations (omitted/node_modules/@sentry/src/integration.ts:64:1)
    at NodeClient.setupIntegrations (omitted/node_modules/@sentry/src/baseclient.ts:258:1)
    at Hub.bindClient (omitted/node_modules/@sentry/src/hub.ts:123:1)
    at Object.initAndBind (omitted/node_modules/@sentry/src/sdk.ts:35:1)
    at Object.init (omitted/node_modules/@sentry/node/cjs/sdk.js:148:8)
@P4sca1 P4sca1 changed the title 7.8.0 breaks TypeError: Cannot convert undefined or null to object Jul 31, 2022
@Lms24
Copy link
Member

Lms24 commented Aug 1, 2022

Hi @P4sca1 and thanks for writing in!

On first glance, this looks like a problem caused by #5450 to me. I didn't test this code with the Express 5.0 beta. Did you by any chance try 7.8.0 with Express 4 and get the same error?

@Lms24
Copy link
Member

Lms24 commented Aug 1, 2022

Quick update: I checked the router instrumentation with Express 5 and it seems like it'll be a little more work to properly support early URL paramterization in Express 5 (which is what we wanted to achieve in #5450). So for now we'll bail out if we detect that the router from Express 4 isn't available.

So for Express 5 users, nothing will change compared to how it was in v7.7.0. We'll discuss proper Express 5 internally and see how this work fits into our time schedule.

Lms24 added a commit that referenced this issue Aug 1, 2022
Hotfixes a problem in our router instrumentation introduced in #5450 which would cause Express 5 Node apps to crash on startup. Because the internals of Express 5 (which is still in beta) have changed quite a bit compared to Express 4, there is unfortunately no quick way of supporting the new version in our current router instrumentation. 

Therefore, this patch simply checks if the router we retrieve from Express 4 apps (which we get from `app._router`) exists. In case it does, we can patch it; in case it doesn't, we know that the integration is either used with Express 3 or 5. In both cases, we early return and do not patch the router.

We can revisit adding proper support for early URL parameterization of Express 5 apps but for now, this PR will unblock Express 5 users by skipping instrumentation. This means that for Express 5, we fall back to our old way of instrumenting routes (which means we get paramterized routes for transaction names but only after the route handler was executed and the transaction is finished).

fixes #5501
@Lms24 Lms24 self-assigned this Aug 1, 2022
@Lms24 Lms24 mentioned this issue Aug 2, 2022
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: node Issues related to the Sentry Node SDK Type: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants