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

Use utils in the NextJs API #9133

Closed
3 tasks done
lucasantoniooficial opened this issue Sep 27, 2023 · 7 comments
Closed
3 tasks done

Use utils in the NextJs API #9133

lucasantoniooficial opened this issue Sep 27, 2023 · 7 comments

Comments

@lucasantoniooficial
Copy link

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

7.64.0

Framework Version

NextJs 13.3.1

Link to Sentry event

No response

SDK Setup

import * as Sentry from "@sentry/nextjs";

Sentry.init({
dsn: "",
release: front-end@${process.env.APP_VERSION},
integrations: [
new Sentry.BrowserTracing(),
new Sentry.Replay(),
],
tracesSampleRate: 1.0,
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
autoSessionTracking: true
});

Steps to Reproduce

    1. First install the iron-session package: https://github.com/vvo/iron-session
  1. First create the _utils folder inside page/api
  2. Create the file _constructorApi.ts file model is in the link: Problem with utils within the API #9132
  3. Import the constructorApi into some api file, for example login, there is a ready example also in the link: Problem with utils within the API #9132

Expected Result

API needs to work normally as it should, in case the login logs in and creates the session.

Actual Result

error - Error [TypeError]: resolver is not a function at /app/node_modules/next/dist/server/api-utils/node.js:392:16 at /app/node_modules/next/dist/server/lib/trace/tracer.js:108:36 at NoopContextManager.with (/app/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057) at ContextAPI.with (/app/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516) at NoopTracer.startActiveSpan (/app/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086) at ProxyTracer.startActiveSpan (/app/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847) at /app/node_modules/next/dist/server/lib/trace/tracer.js:97:107 at NoopContextManager.with (/app/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057) at ContextAPI.with (/app/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516) at NextTracerImpl.trace (/app/node_modules/next/dist/server/lib/trace/tracer.js:97:32) at apiResolver (/app/node_modules/next/dist/server/api-utils/node.js:390:63) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async DevServer.runApi (/app/node_modules/next/dist/server/next-server.js:668:9) at async Object.fn (/app/node_modules/next/dist/server/next-server.js:1118:35) at async Router.execute (/app/node_modules/next/dist/server/router.js:311:32) at async DevServer.runImpl (/app/node_modules/next/dist/server/base-server.js:599:29) at async DevServer.run (/app/node_modules/next/dist/server/dev/next-dev-server.js:922:20) at async DevServer.handleRequestImpl (/app/node_modules/next/dist/server/base-server.js:528:20) { digest: undefined } This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason: TypeError: Cannot read properties of undefined (reading 'end') at Object.autoEndTransactionOnResponseEnd (/app/node_modules/@sentry/nextjs/cjs/common/utils/responseEnd.js:33:11) at /app/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:118:29 at /app/node_modules/@sentry/node/cjs/async/hooks.js:38:14 at AsyncLocalStorage.run (node:async_hooks:346:14) at Object.runWithAsyncContext (/app/node_modules/@sentry/node/cjs/async/hooks.js:37:25) at Object.runWithAsyncContext (/app/node_modules/@sentry/core/cjs/hub.js:527:36) at Object.apply (/app/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:58:33) at Object.apply (/app/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:25:61) at eval (webpack-internal:///(api)/./src/pages/api/auth/login.ts:25:114) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) error - unhandledRejection: Error [TypeError]: Cannot read properties of undefined (reading 'end') at Object.autoEndTransactionOnResponseEnd (/app/node_modules/@sentry/nextjs/cjs/common/utils/responseEnd.js:33:11) at /app/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:118:29 at /app/node_modules/@sentry/node/cjs/async/hooks.js:38:14 at AsyncLocalStorage.run (node:async_hooks:346:14) at Object.runWithAsyncContext (/app/node_modules/@sentry/node/cjs/async/hooks.js:37:25) at Object.runWithAsyncContext (/app/node_modules/@sentry/core/cjs/hub.js:527:36) at Object.apply (/app/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:58:33) at Object.apply (/app/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:25:61) at eval (webpack-internal:///(api)/./src/pages/api/auth/login.ts:25:114) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { digest: undefined }

@Lms24
Copy link
Member

Lms24 commented Oct 2, 2023

Hi @lucasantoniooficial thanks for writing in! I'm not the NextJS expert of this team but can you please provide a minimal reproduction example (in the form of a GH repo)? Seems like quite a few moving parts are involved and this would help us get to the bottom of this faster. Thanks!

@lucasantoniooficial
Copy link
Author

I can assemble it, but I won't be able to send it until next week.

@Lms24
Copy link
Member

Lms24 commented Oct 5, 2023

I can assemble it, but I won't be able to send it until next week.

That'd be great, thanks!

From taking a look at the iron-session package, I suspect it could be related to some sort of conflict between their wrappers and ours which are applied at build time. @lforst have you hear of this before?

@lucasantoniooficial you could try disabeling server auto instrumentation as described here. If this fixes the error, we know we're on the right track.

@lforst
Copy link
Member

lforst commented Oct 5, 2023

This line in the stack trace seems to be the offending part:

TypeError: Cannot read properties of undefined (reading 'end') at Object.autoEndTransactionOnResponseEnd

Maybe we should just be more defensive here.

@lforst
Copy link
Member

lforst commented Oct 5, 2023

Hm. We're already super careful around making sure res is defined. We fixed this in version 7.65.0 of the SDK (PR). Please upgrade your SDK and verify if it fixed your problem. Thanks!

@lucasantoniooficial
Copy link
Author

I'll be doing these tests and let you know

@lucasantoniooficial
Copy link
Author

I put the version: 7.73.0 and it resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Archived in project
Development

No branches or pull requests

3 participants