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

[NEXT-1100] unhandledRejection: Error [TypeError]: trace.getSpan is not a function #48118

Closed
1 task done
dossy opened this issue Apr 8, 2023 · 24 comments · Fixed by #50554
Closed
1 task done

[NEXT-1100] unhandledRejection: Error [TypeError]: trace.getSpan is not a function #48118

dossy opened this issue Apr 8, 2023 · 24 comments · Fixed by #50554
Assignees
Labels
create-next-app Related to our CLI tool for quickly starting a new Next.js application. linear: next Confirmed issue that is tracked by the Next.js team.

Comments

@dossy
Copy link

dossy commented Apr 8, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 20.6.0: Sun Nov  6 23:17:00 PST 2022; root:xnu-7195.141.46~1/RELEASE_X86_64
    Binaries:
      Node: 18.12.1
      npm: 9.3.1
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.3.1-canary.2
      eslint-config-next: 13.3.0
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

CLI (create-next-app)

Link to the code that reproduces this issue

https://github.com/dossy/nextjs-trace-getSpan-is-not-a-function

To Reproduce

Provided by #48118 (comment)

reproduce with a yarn workspaces monorepo.

Check this one out here: jamesopti/next-tracespan-error-reproduction

The packages/server has "@opentelemetry/api": "^0.18.1"

The packages/client is a brand new create next app.

Describe the Bug

Trying to access the app results in an unhandledRejection: Error [TypeError]: trace.getSpan is not a function error:

$ yarn dev
yarn run v1.22.19
$ next dev
warn  - Port 3000 is in use, trying 3001 instead.
ready - started server on 0.0.0.0:3001, url: http://localhost:3001
(node:53803) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
event - compiled client and server successfully in 1821 ms (170 modules)
wait  - compiling / (client and server)...
event - compiled client and server successfully in 467 ms (217 modules)
error - unhandledRejection: Error [TypeError]: trace.getSpan is not a function
    at NextTracerImpl.getActiveScopeSpan ([REDACTED]/create-next-app-sample/node_modules/next/dist/server/lib/trace/tracer.js:50:22)
    at NextTracerImpl.trace ([REDACTED]/create-next-app-sample/node_modules/next/dist/server/lib/trace/tracer.js:69:103)
    at DevServer.handleRequest ([REDACTED]/create-next-app-sample/node_modules/next/dist/server/base-server.js:166:41)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async DevServer.handleRequest ([REDACTED]/create-next-app-sample/node_modules/next/dist/server/dev/next-dev-server.js:839:16) {
  digest: undefined
}

Expected Behavior

The home page should render in the browser.

Which browser are you using? (if relevant)

Chrome Version 111.0.5563.146 (Official Build) (x86_64)

How are you deploying your application? (if relevant)

locally

From SyncLinear.com | NEXT-1100

@dossy dossy added the bug Issue was opened via the bug report template. label Apr 8, 2023
@github-actions github-actions bot added the create-next-app Related to our CLI tool for quickly starting a new Next.js application. label Apr 8, 2023
@dossy
Copy link
Author

dossy commented Apr 8, 2023

#46632

@ndpa
Copy link

ndpa commented Apr 9, 2023

This also worked for me to resolve this issue as per #46632 / yarn add @opentelemetry/api @opentelemetry/resources @opentelemetry/semantic-conventions @opentelemetry/sdk-trace-node @opentelemetry/instrumentation

But, it seems very odd to me that I would need to do this. Please let me know if a better solution appears.

@pgsandstrom
Copy link

I am running into this problem when upgrading my next-apps from 12 to 13. It only happens in production. In development mode, everything works perfectly.

@jamesopti
Copy link

Trying to upgrade to the latest 13.4 and getting this error.

Any response from the next team? Seems odd that consumers would need to install opentelemetry themselves 🤔

@jamesopti
Copy link

It appears that @opentelemetry/api is a peerDependency now, but the docs dont indicate as much: https://github.com/vercel/next.js/blob/v13.4.1/packages/next/package.json#L95

@huozhi
Copy link
Member

huozhi commented May 5, 2023

@jamesopti There's a built-in version of opentelementry by default, it should work even you didn't install it.

I can't repro the error with latest version 13.4.1 with origin reproduction post in the issue description. Could you post another reproduction for this if you're still seeing the error?

@jamesopti
Copy link

We're using a monorepo where the client package is nextjs. Our server package requires @opentelemetry/api. Is it possible this is causing a conflict?

Additionally, why is @opentelemetry/api listed as a peer dependency? That sure seems like what is causing the problem here.

➜  client git:(main) yarn why @opentelemetry/api
├─ @opentelemetry/instrumentation-express@npm:0.16.0
│  └─ @opentelemetry/api@npm:1.0.0-rc.3 (via npm:^1.0.0-rc.0)
│
└─ server@workspace:packages/server
   └─ @opentelemetry/api@npm:0.18.1 (via npm:^0.18.1)

@jamesopti
Copy link

jamesopti commented May 5, 2023

FWIW, this issue was introduced in 13.4.0

13.3.4 does not have this problem.

EDIT: 13.1 does not have this issue, but 13.3.4 does

@huozhi
Copy link
Member

huozhi commented May 6, 2023

The different version could be possible reason, could you try add resolution in package.json to lock its version to one, we'll investigate the issue at the same time

@huozhi huozhi added kind: bug and removed bug Issue was opened via the bug report template. labels May 6, 2023
@huozhi huozhi changed the title unhandledRejection: Error [TypeError]: trace.getSpan is not a function [NEXT-1100] unhandledRejection: Error [TypeError]: trace.getSpan is not a function May 6, 2023
@jamesopti
Copy link

@huozhi Can you elaborate more? I'm not familiar with yarn resolutions.

I added this to our workspace root package.json but same issue happens when I run next dev in our client package

"resolutions": {
    "@opentelemetry/api-metrics": "0.19.0",
    "@opentelemetry/api": "0.18.1",
    "@opentelemetry/instrumentation": "0.19.0",
    "@opentelemetry/resources": "0.19.0",
    "@opentelemetry/semantic-conventions": "0.19.0"
  }

@huozhi
Copy link
Member

huozhi commented May 8, 2023

@jamesopti yes ideally only @opentelemetry/api will be fine so that it's always the same version. Can you try this?

"resolutions": {
  "**/@opentelemetry/api": "0.18.1",
}

@jamesopti
Copy link

@huozhi Tried that and still same error (also upgraded to latest 13.4.3 which fixes the dev server react issue).

Any other ideas?

@huozhi
Copy link
Member

huozhi commented May 20, 2023

@jamesopti We really need a minimal reproduction here as the original reproduction in the issue is not able to repro the issue. Please provide a reproduction repo

@huozhi huozhi added please add a complete reproduction The issue lacks information for further investigation and removed kind: bug labels May 20, 2023
@github-actions
Copy link
Contributor

We cannot recreate the issue with the provided information. Please add a reproduction in order for us to be able to investigate.

Why was this issue marked with the please add a complete reproduction label?

To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository (template for pages, template for App Router), but you can also use these templates: CodeSandbox: pages or CodeSandbox: App Router.

To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue.

Please test your reproduction against the latest version of Next.js (next@canary) to make sure your issue has not already been fixed.

I added a link, why was it still marked?

Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "example.com", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links.

What happens if I don't provide a sufficient minimal reproduction?

Issues with the please add a complete reproduction label that receives no meaningful activity (e.g. new comments with a reproduction link) are automatically closed and locked after 30 days.

If your issue has not been resolved in that time and it has been closed/locked, please open a new issue with the required reproduction.

I did not open this issue, but it is relevant to me, what can I do to help?

Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps. Furthermore, you can upvote the issue using the 👍 reaction on the topmost comment (please do not comment "I have the same issue" without reproduction steps). Then, we can sort issues by votes to prioritize.

I think my reproduction is good enough, why aren't you looking into it quicker?

We look into every Next.js issue and constantly monitor open issues for new comments.

However, sometimes we might miss one or two due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.

Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.

Useful Resources

@dossy
Copy link
Author

dossy commented May 21, 2023

I can no longer reproduce the issue, so if someone else can, please provide a minimal reproduction. Thanks!

@jamesopti
Copy link

@dossy @huozhi This is very easy to reproduce with a super simple yarn workspaces monorepo.

Check this one out here: https://github.com/jamesopti/next-tracespan-error-reproduction

The packages/server has "@opentelemetry/api": "^0.18.1"

The packages/client is a brand new create next app.

@huozhi huozhi removed the please add a complete reproduction The issue lacks information for further investigation label May 22, 2023
@timneutkens timneutkens added the linear: next Confirmed issue that is tracked by the Next.js team. label May 23, 2023
@jamesopti
Copy link

Any updates here? This has been a blocker for us upgrading for over a month now (stuck on 13.1)

@shuding
Copy link
Member

shuding commented May 30, 2023

Hey! I took a look and it appears that you're on @opentelemetry/api@0.18.1, which doesn't have the methods Next.js need (https://unpkg.com/browse/@opentelemetry/api@0.18.1/build/src/api/trace.js there's no getSpan method exposed). It's available in the latest version: https://unpkg.com/browse/@opentelemetry/api@1.4.1/build/src/api/trace.js.

Confirmed that your repo works fine if upgrading the @opentelemetry/api package. In the meantime I'll add a check in Next.js regarding the minimal required version of that lib.

@shuding shuding closed this as completed May 30, 2023
@jamesopti
Copy link

So now I'm really confused. Is @opentelemetry/api@^1.0.0 a required peer dependency for NextJS?

The solution to run my client can't just be to upgrade the entire telemetry package for my server.

@jamesopti There's a built-in version of opentelementry by default, it should work even you didn't install it.

According to this comment, I was under the impression that consumers were not required to install opentelementry themselves

@shuding
Copy link
Member

shuding commented May 30, 2023

@jamesopti I did a quick look and 0.19.0 already have that getSpan API (https://unpkg.com/browse/@opentelemetry/api@0.19.0/build/src/api/trace.js), you don't need to bump to 1.0.

The logic in Next.js is that if you have opentelementry installed, Next.js will use your version. Otherwise Next.js uses its built-in one. But here the problem is that the user provided version doesn't meet the need.

@jamesopti
Copy link

The logic in Next.js is that if you have opentelementry installed, Next.js will use your version. Otherwise Next.js uses its built-in one. But here the problem is that the user provided version doesn't meet the need.

So it sounds like I need a way to tell Yarn workspaces that the 0.18.1 version is for packages/server and that packages/client cannot use it.

In classic yarn you could use the noHoist option but with Yarn 3 I'm not sure how to do that anymore.

I'll also explore the 0.19.0 approach, which is much more doable than a major version upgrade.

Thanks for the detail

@jamesopti
Copy link

Unfortunately 0.19.0 has a bunch of breaking changes and is not an option for me to fix with this.

I'm going to capitulate and just install the latest @opentelemetry packages in my nextjs workspace.

@weyert
Copy link

weyert commented May 31, 2023

@dossy @huozhi This is very easy to reproduce with a super simple yarn workspaces monorepo.

Check this one out here: https://github.com/jamesopti/next-tracespan-error-reproduction

The packages/server has "@opentelemetry/api": "^0.18.1"

The packages/client is a brand new create next app.

Why do you use a two year old experimental version of @opentelemetry/api? v1 got released two years ago.

@dyladan Wasn't the idea that you could use different versions of the API-package without issues in one project?

@github-actions
Copy link
Contributor

github-actions bot commented Jul 2, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
create-next-app Related to our CLI tool for quickly starting a new Next.js application. linear: next Confirmed issue that is tracked by the Next.js team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants