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

Unable to run Next in developer mode throws error TypeError: _tracer.tracer.withSpan is not a function when using Opentelemetry tracing #22574

Closed
weyert opened this issue Feb 26, 2021 · 3 comments · Fixed by #22713
Labels
bug Issue was opened via the bug report template.

Comments

@weyert
Copy link

weyert commented Feb 26, 2021

What version of Next.js are you using?

10.0.7

What version of Node.js are you using?

14.16.0

What browser are you using?

Edge

What operating system are you using?

macOS

How are you deploying your application?

local development

Describe the Bug

I am trying to integrate Opentelemetry 0.17 in my API routes but when I am running Next with custom server with the option const nextApp = next({ dev: true }) the application fails to process any handlers because of the following error:

Exception has occurred: TypeError: _tracer.tracer.withSpan is not a function
  at Object.loader (/Users/weyertdeboer/Development/Projects/next-app/node_modules/next/dist/build/webpack/loaders/babel-loader/src/index.js:5:23)
    at Object.<anonymous> (/Users/weyertdeboer/Development/Projects/next-app/node_modules/next/dist/build/webpack/loaders/babel-loader/src/index.js:4:30)
    at LOADER_EXECUTION (/Users/weyertdeboer/Development/Projects/next-app/node_modules/next/dist/compiled/webpack/bundle4.js:31690:14)
    at runSyncOrAsync (/Users/weyertdeboer/Development/Projects/next-app/node_modules/next/dist/compiled/webpack/bundle4.js:31691:4)
    at iterateNormalLoaders (/Users/weyertdeboer/Development/Projects/next-app/node_modules/next/dist/compiled/webpack/bundle4.js:31803:2)
    at Array.<anonymous> (/Users/weyertdeboer/Development/Projects/next-app/node_modules/next/dist/compiled/webpack/bundle4.js:31776:4)
    at Storage.finished (/Users/weyertdeboer/Development/Projects/next-app/node_modules/next/dist/compiled/webpack/bundle4.js:22941:16)
    at /Users/weyertdeboer/Development/Projects/next-app/node_modules/next/dist/compiled/webpack/bundle4.js:22977:9
    at /Users/weyertdeboer/Development/Projects/next-app/node_modules/next/dist/compiled/webpack/bundle4.js:29578:16
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)
    at FSReqCallback.callbackTrampoline (internal/async_hooks.js:123:14)

Expected Behavior

Next will load without any thrown errors and I am able to instrument my own code with the @opentelemetry-packages

To Reproduce

Please clone the repo that reproduces the problem: https://github.com/weyert/next-opentelemetry-bug:

  1. npm install
  2. npm run build
  3. NODE_ENV=development node server.js
    4: Open in http://127.0.0.1:3000 (edited)

after it finished loading you will see the following output:

❯ NODE_ENV=development node server.js                                                                     (main) [~/next-reproduce/nextjs-blog]
error - ./node_modules/next/dist/client/dev/amp-dev.js
TypeError: _tracer.tracer.withSpan is not a function
> Ready on http://localhost:3000
event - build page: /next/dist/pages/_error
wait  - compiling...
error - ./node_modules/next/dist/client/next-dev.js
TypeError: _tracer.tracer.withSpan is not a function
Error: Cannot find module '/Users/weyertdeboer/next-reproduce/nextjs-blog/.next/server/pages-manifest.json'
Require stack:
- /Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/next-server/server/require.js
- /Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/next-server/server/load-components.js
- /Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/next-server/server/api-utils.js
- /Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/next-server/server/next-server.js
- /Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/server/next.js
- /Users/weyertdeboer/next-reproduce/nextjs-blog/server.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1080:15)
    at Function.mod._resolveFilename (/Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/build/webpack/require-hook.js:4:1715)
    at Function.Module._load (internal/modules/cjs/loader.js:923:27)
    at Module.require (internal/modules/cjs/loader.js:1140:19)
    at require (internal/modules/cjs/helpers.js:75:18)
    at getPagePath (/Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/next-server/server/require.js:1:657)
    at requirePage (/Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/next-server/server/require.js:1:1062)
    at loadComponents (/Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/next-server/server/load-components.js:1:807)
    at DevServer.findPageComponents (/Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/next-server/server/next-server.js:74:296)
    at DevServer.renderErrorToHTML (/Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/next-server/server/next-server.js:134:120)
    at DevServer.renderErrorToHTML (/Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/server/next-dev-server.js:34:974)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async DevServer.render (/Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/next-server/server/next-server.js:72:236)
    at async Object.fn (/Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/next-server/server/next-server.js:56:580)
    at async Router.execute (/Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/next-server/server/router.js:23:67)
    at async DevServer.run (/Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/next-server/server/next-server.js:66:1042) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/next-server/server/require.js',
    '/Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/next-server/server/load-components.js',
    '/Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/next-server/server/api-utils.js',
    '/Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/next-server/server/next-server.js',
    '/Users/weyertdeboer/next-reproduce/nextjs-blog/node_modules/next/dist/server/next.js',
    '/Users/weyertdeboer/next-reproduce/nextjs-blog/server.js'
  ]
}
@weyert weyert added the bug Issue was opened via the bug report template. label Feb 26, 2021
@weyert
Copy link
Author

weyert commented Feb 27, 2021

This problem has been fixed in the @opentelemetry/api-package 0.18 release. Closing ticket.

@weyert weyert closed this as completed Feb 27, 2021
@weyert weyert reopened this Feb 27, 2021
@weyert
Copy link
Author

weyert commented Feb 27, 2021

Reopening this ticket as the problem still exists when actually starting an exporter this time it's the profiling-plugin:

if (tracerProvider instanceof ProxyTracerProvider) {

@kodiakhq kodiakhq bot closed this as completed in #22713 Mar 10, 2021
kodiakhq bot pushed a commit that referenced this issue Mar 10, 2021
A number of changes here.  I recommend viewing the diff with the <a href="?w=1">whitespace flag enabled</a>.

- OpenTelemetry is replaced with a custom and lightweight tracing solution.
- Three trace targets are currently supported: console, Zipkin, and NextJS.
- Tracing is now governed by environment variables rather than `--require instrument.js`.
  + `TRACE_TARGET`: one of `CONSOLE`, `ZIPKIN`, or `TELEMETRY`; defaults to `TELEMETRY` if unset or invalid.
  + `TRACE_ID`: an 8-byte hex-encoded value used as the Zipkin trace ID; if not provided, this value will be randomly generated and passed down to subprocesses.

Other sundry:

- I'm missing something, probably a setup step, with the Zipkin target.  Traces are captured successfully, but you have to manually enter the Trace ID in order to view the trace - it doesn't show up in queries.
- I'm generally unhappy with [this commit](235cedc).  It is... untidy to provide a telemetry object via `setGlobal`, but I don't have a ready alternative.  Is `distDir` strictly required when creating a new Telemetry object?  I didn't dig too deep here.

As noted, there are a lot of changes, so it'd be great if a reviewer could:

- [ ] pull down the branch and try to break it
- [ ] check the Zipkin traces and identify possible regressions in the functionality

Closes #22570
Fixes #22574
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants