Skip to content

TypeError: Cannot convert undefined or null to object #5501

Description

@P4sca1

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)

Activity

  1. changed the title [-]7.8.0 breaks [/-] [+]TypeError: Cannot convert undefined or null to object[/+] on Jul 31, 2022
  2. Lms24 commented on Aug 1, 2022

    @Lms24
    Member

    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?

  3. Lms24 commented on Aug 1, 2022

    @Lms24
    Member

    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.

  4. added a commit that references this issue on Aug 1, 2022
    0b86dd8
  5. self-assigned this
    on Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions