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

integrate with Nuxtjs but cannot see any transaction in APM #4143

Closed
cwhsu1984 opened this issue Jul 18, 2024 · 11 comments
Closed

integrate with Nuxtjs but cannot see any transaction in APM #4143

cwhsu1984 opened this issue Jul 18, 2024 · 11 comments

Comments

@cwhsu1984
Copy link

This is how I init apm in Dockerfile.

CMD node -r ./server/node_modules/elastic-apm-node/start.js ./server/index.mjs

This is the env config, and we run containers in kubernetes.

ELASTIC_APM_ENVIRONMENT=Staging
ELASTIC_APM_SERVICE_NAME=Lego
ELASTIC_APM_SERVER_URL=http://my-apm-server
ELASTIC_APM_TRANSACTION_SAMPLE_RATE=1
ELASTIC_APM_CAPTURE_BODY=all
ELASTIC_APM_USE_ELASTIC_TRACEPARENT_HEADER=true
ELASTIC_APM_TRACE_CONTINUATION_STRATEGY=restart
ELASTIC_APM_LOG_LEVEL=trace

I check the service in APM, but there is no data.

image

But If I look at Metrics tab, the cpu and memory related info is collected
image

Below is the container log. And I suspect it's due to the message "no active transaction found - cannot build new span".
I already try to adjust ELASTIC_APM_TRACE_CONTINUATION_STRATEGY into different settings, but still no luck.

What is the possible cause of this?
Any suggestion on how to debug this?

{"log.level":"warn","@timestamp":"2024-07-18T09:44:13.171Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","message":"unknown log levelName \"Trace\": cannot setLogLevel"}
{"log.level":"info","@timestamp":"2024-07-18T09:44:13.176Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","agentVersion":"4.7.0","env":{"pid":1,"proctitle":"node","os":"linux 5.15.133+","arch":"x64","host":"myproject-576bf9784f-42j4r","timezone":"UTC-0400","runtime":"Node.js v20.6.0"},"config":{"captureBody":{"source":"environment","value":"all","commonName":"capture_body"},"environment":{"source":"environment","value":"Staging"},"logLevel":{"source":"environment","value":"Trace","commonName":"log_level"},"serverUrl":{"source":"environment","value":"http://apm-server","commonName":"server_url"},"traceContinuationStrategy":{"source":"environment","value":"restart","commonName":"trace_continuation_strategy"},"transactionSampleRate":{"source":"environment","value":1,"commonName":"transaction_sample_rate","sourceValue":"1"},"useElasticTraceparentHeader":{"source":"environment","value":true,"sourceValue":"true"},"serviceName":{"source":"environment","value":"myproject","commonName":"service_name"},"serviceVersion":{"source":"default","value":"0.0.0","commonName":"service_version"}},"activationMethod":"preload","message":"Elastic APM Node.js Agent v4.7.0"} {"log.level":"trace","@timestamp":"2024-07-18T09:44:13.257Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","event.module":"apmclient","message":"corking (cloudMetadataFetcher)"}
{"log.level":"debug","@timestamp":"2024-07-18T09:44:13.260Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","message":"adding Node.js module loader hooks"}
{"log.level":"debug","@timestamp":"2024-07-18T09:44:13.260Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","message":"instrumenting fetch"}
{"log.level":"trace","@timestamp":"2024-07-18T09:44:13.454Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","message":"azure metadata server responded, but there was an error parsing the result: {}"}
{"log.level":"debug","@timestamp":"2024-07-18T09:44:13.554Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","message":"gcp metadata server responded, but there was an error parsing the result: {}"}
{"log.level":"trace","@timestamp":"2024-07-18T09:44:13.555Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","message":"aws metadata server responded, but there was an error parsing the result: {}"}
{"log.level":"debug","@timestamp":"2024-07-18T09:44:13.556Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","message":"no cloud metadata servers responded"}
{"log.level":"trace","@timestamp":"2024-07-18T09:44:13.556Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","event.module":"apmclient","message":"getCloudMetadata err: Error: no response from any callback, no cloud metadata will be set (normal outside of cloud env.)"}
{"log.level":"trace","@timestamp":"2024-07-18T09:44:13.557Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","event.module":"apmclient","_encodedMetadata":"{\"metadata\":{\"service\":{\"name\":\"myproject\",\"environment\":\"Staging\",\"runtime\":{\"name\":\"node\",\"version\":\"20.6.0\"},\"language\":{\"name\":\"javascript\"},\"agent\":{\"name\":\"nodejs\",\"version\":\"4.7.0\",\"activation_method\":\"preload\"},\"version\":\"0.0.0\"},\"process\":{\"pid\":1,\"ppid\":0,\"title\":\"node\",\"argv\":[\"/usr/local/bin/node\",\"/app/server/index.mjs\"]},\"system\":{\"architecture\":\"x64\",\"platform\":\"linux\",\"detected_hostname\":\"myproject-576bf9784f-42j4r\"}}}\n","message":"_resetEncodedMetadata"}
{"log.level":"trace","@timestamp":"2024-07-18T09:44:13.557Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","event.module":"apmclient","message":"uncorked (cloudMetadataFetcher)"}
{"log.level":"trace","@timestamp":"2024-07-18T09:44:13.558Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","event.module":"apmclient","_encodedMetadata":"{\"metadata\":{\"service\":{\"name\":\"myproject\",\"environment\":\"Staging\",\"runtime\":{\"name\":\"node\",\"version\":\"20.6.0\"},\"language\":{\"name\":\"javascript\"},\"agent\":{\"name\":\"nodejs\",\"version\":\"4.7.0\",\"activation_method\":\"preload\"},\"version\":\"0.0.0\"},\"process\":{\"pid\":1,\"ppid\":0,\"title\":\"node\",\"argv\":[\"/usr/local/bin/node\",\"/app/server/index.mjs\"]},\"system\":{\"architecture\":\"x64\",\"platform\":\"linux\",\"detected_hostname\":\"myproject-576bf9784f-42j4r\"}}}\n","message":"_resetEncodedMetadata"}
{"log.level":"debug","@timestamp":"2024-07-18T09:44:13.558Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","event.module":"apmclient","apmServerVersion":"8.10.3","message":"fetched APM Server version"}
{"log.level":"debug","@timestamp":"2024-07-18T09:44:13.560Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","remoteConf":{},"message":"central config received"}
{"log.level":"trace","@timestamp":"2024-07-18T09:44:13.660Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","event.module":"apmclient","reqId":"d7cc7cf1a38215e9b31a3b664c0eab02","message":"intake request start"}
{"log.level":"trace","@timestamp":"2024-07-18T09:44:13.661Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","event.module":"apmclient","fullTimeMs":5.45473,"numEvents":1,"numBytes":898,"message":"_write: encode object"}
{"log.level":"trace","@timestamp":"2024-07-18T09:44:13.662Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","event.module":"apmclient","reqId":"d7cc7cf1a38215e9b31a3b664c0eab02","message":"intakeReq \"socket\": unref it"}
Listening on http://[::]:5314
{"log.level":"debug","@timestamp":"2024-07-18T09:44:19.766Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","message":"no active transaction found - cannot build new span"}
...
{"log.level":"trace","@timestamp":"2024-07-18T09:47:23.290Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","event.module":"apmclient","reqId":"960d17340bffd882f71eb36987172bca","concluded":false,"message":"completePart intakeReq"}
{"log.level":"trace","@timestamp":"2024-07-18T09:47:23.295Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","event.module":"apmclient","reqId":"960d17340bffd882f71eb36987172bca","statusCode":202,"reqFinished":true,"message":"intakeReq \"response\""}
{"log.level":"trace","@timestamp":"2024-07-18T09:47:23.296Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","event.module":"apmclient","reqId":"960d17340bffd882f71eb36987172bca","message":"intakeRes \"end\""}
{"log.level":"trace","@timestamp":"2024-07-18T09:47:23.296Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","event.module":"apmclient","reqId":"960d17340bffd882f71eb36987172bca","concluded":false,"message":"completePart intakeRes"}
{"log.level":"trace","@timestamp":"2024-07-18T09:47:23.296Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","event.module":"apmclient","reqId":"960d17340bffd882f71eb36987172bca","timeline":[[10001.372483,"completePart gzipStream",null],[10001.704373,"completePart intakeReq",null],[10007.856263,"completePart intakeRes",null]],"bytesWritten":644,"backoffDelayMs":0,"message":"conclude intake request: success"}
{"log.level":"trace","@timestamp":"2024-07-18T09:47:43.289Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","event.module":"apmclient","reqId":"c8f5424184da22dfd24d2ae765732e2b","message":"intake request start"}
{"log.level":"trace","@timestamp":"2024-07-18T09:47:43.289Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","event.module":"apmclient","fullTimeMs":1.396559,"numEvents":1,"numBytes":925,"message":"_write: encode object"}
{"log.level":"trace","@timestamp":"2024-07-18T09:47:43.289Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","event.module":"apmclient","reqId":"c8f5424184da22dfd24d2ae765732e2b","message":"intakeReq \"socket\": unref it"}
{"log.level":"trace","@timestamp":"2024-07-18T09:47:43.682Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","event.module":"apmclient","message":"_pollConfig: no new central config since last poll"}
{"log.level":"debug","@timestamp":"2024-07-18T09:47:44.567Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","message":"no active transaction found - cannot build new span"}
[INFORMATION] 2024-07-18T09:47:44.653Z [23907d94-8e65-4149-a9e1-0cb1a181ca6e] - [access] 2024-07-18T09:47:44.653Z POST http localhost /api/public/getToggle - 200 89 ::1 [-] [-] [-]
{"log.level":"debug","@timestamp":"2024-07-18T09:47:44.664Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","message":"no active transaction found - cannot build new span"}
@trentm
Copy link
Member

trentm commented Jul 19, 2024

@cwhsu1984 Hi. Thanks for the issue. There are a few things to note here, but ultimately, this APM agent is not currently able to instrument NuxtJS 3 apps.

instrumenting the dev server (somewhat)

I created a basic Nuxt 3 app using the getting started doc: https://nuxt.com/docs/getting-started/introduction
and added one API endpoint.
My repo is here:
https://github.com/trentm/nuxtplay

I was able to get some tracing data for HTTP requests to the server when using the dev server:

NODE_OPTIONS=--require=elastic-apm-node/start npm run dev -- -o

Then I would get traces something like the following (this is a text-based summary of traces rather than showing screenshots from Kibana):

    trace d9e0fd
    `- transaction 52cef6 "GET unknown route" (0.729ms, GET http://localhost:3000/_nuxt/@id/virtual:nuxt:/Users/trentm/tmp/nuxtplay/.nuxt/pages.mjs -> 200)
    trace 779ade
    `- transaction e31389 "GET unknown route" (1.338ms, GET http://localhost:3000/_nuxt/node_modules/nuxt/dist/app/components/welcome.vue?vue&type=style&index=0&scoped=8e92eaa8&lang.css -> 200)
    trace b27ced
    `- transaction 0c716a "GET unknown route" (0.194ms, GET http://127.0.0.1:63764/__nuxt_vite_node__/invalidates -> 200)

...

    trace b0ed13
    `- transaction c25a09 "GET unknown route" (67.971ms, GET http://localhost:3000/api/hello -> 200)
       `- span 4616b8 "GET localhost:3000" (63.624ms, http)

These transactions and spans are coming from automatic instrumentation of the http library used when the Nuxt dev server is running.

This tracing is, of course, limited because the APM agent (elastic-apm-node) doesn't know anything about Nuxt routing, so all transactions are named {method} unknown route.

No tracing for the production server

When I build and run the production (non-dev) server:

npm run build
NODE_OPTIONS=--require=elastic-apm-node/start node .output/server/index.mjs

This does not work.
The first issue is that the built server is an ES module (ESM) as opposed to CommonJS.
Support for instrumentating ES modules is experimental and limited. It is discussed here: https://www.elastic.co/guide/en/apm/agent/nodejs/current/esm.html

Ideally we would be able to get some instrumentation of the ESM code by using the additional --experimental-loader=elastic-apm-node/loader.mjs option:

node --require=elastic-apm-node/start.js --experimental-loader=elastic-apm-node/loader.mjs .output/server/index.mjs

This partially works. For example, when manually making a call to just the added "/api/hello" endpoint in my small Nuxt app:

% curl localhost:3000/api/hello
Hello World!

I successfully get a trace from the APM agent:

    trace e2e9f1
    `- transaction d5f7f2 "GET unknown route" (10.366ms, GET http://localhost:3000/api/hello -> 200)

However, when loading the full app in a browser (http://localhost:3000), I get a 500 error in the browser and this in the app log:

[nuxt] [request error] [unhandled] [500] The requested module 'vue/server-renderer' does not provide an export named 'renderToString'
  at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
  at async ModuleJob.run (node:internal/modules/esm/module_job:191:5)
  at async ModuleLoader.import (node:internal/modules/esm/loader:337:24)
  at async Object.handler (./.output/server/chunks/runtime.mjs:2887:19)
  at async Server.toNodeHandle (./.output/server/chunks/runtime.mjs:3157:7)
New request: http://localhost:3000/__nuxt_error?url=%2F&statusCode=500&statusMessage&message=The+requested+module+%27vue%2Fserver-renderer%27+does+not+provide+an+export+named+%27renderToString%27&stack
[nuxt] [request error] [unhandled] [500] The requested module 'vue/server-renderer' does not provide an export named 'renderToString'
  at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
  at async ModuleJob.run (node:internal/modules/esm/module_job:191:5)
  at async ModuleLoader.import (node:internal/modules/esm/loader:337:24)
  at async Object.handler (./.output/server/chunks/runtime.mjs:2887:19)
  at async Server.toNodeHandle (./.output/server/chunks/runtime.mjs:3157:7)

This is almost certainly a bug in the underlying library that the APM agent is using to hook into ES module imports. That hooking is breaking the vue/server-renderer module. That library, import-in-the-middle, is under active development: https://github.com/nodejs/import-in-the-middle/pulls
I expect the handling of this will improve over time.

Bundling

Finally, if I understand correctly, the built server code uses a bundler (esbuild?). Currently this APM agent does not support instrumenting libraries used in bundled code. Node.js core libraries (like http) can still be instrumented, but any other libraries cannot. That may mean somewhat limited tracing data.

If you are mainly interested in HTTP incoming and outgoing spans, then this may be fine for you.

options

I have not tried this, but perhaps the Nuxt tsconfig could be changed to build a CommonJS server, rather than ESM code. Then that might allow the built server to be instrumented without the --experimental-loader=elastic-apm-node/loader.mjs loader that is causing issues.

@trentm trentm removed the triage label Jul 19, 2024
@cwhsu1984
Copy link
Author

@cwhsu1984 Hi. Thanks for the issue. There are a few things to note here, but ultimately, this APM agent is not currently able to instrument NuxtJS 3 apps.

instrumenting the dev server (somewhat)

I created a basic Nuxt 3 app using the getting started doc: https://nuxt.com/docs/getting-started/introduction and added one API endpoint. My repo is here: https://github.com/trentm/nuxtplay

I was able to get some tracing data for HTTP requests to the server when using the dev server:

NODE_OPTIONS=--require=elastic-apm-node/start npm run dev -- -o

Then I would get traces something like the following (this is a text-based summary of traces rather than showing screenshots from Kibana):

    trace d9e0fd
    `- transaction 52cef6 "GET unknown route" (0.729ms, GET http://localhost:3000/_nuxt/@id/virtual:nuxt:/Users/trentm/tmp/nuxtplay/.nuxt/pages.mjs -> 200)
    trace 779ade
    `- transaction e31389 "GET unknown route" (1.338ms, GET http://localhost:3000/_nuxt/node_modules/nuxt/dist/app/components/welcome.vue?vue&type=style&index=0&scoped=8e92eaa8&lang.css -> 200)
    trace b27ced
    `- transaction 0c716a "GET unknown route" (0.194ms, GET http://127.0.0.1:63764/__nuxt_vite_node__/invalidates -> 200)

...

    trace b0ed13
    `- transaction c25a09 "GET unknown route" (67.971ms, GET http://localhost:3000/api/hello -> 200)
       `- span 4616b8 "GET localhost:3000" (63.624ms, http)

These transactions and spans are coming from automatic instrumentation of the http library used when the Nuxt dev server is running.

This tracing is, of course, limited because the APM agent (elastic-apm-node) doesn't know anything about Nuxt routing, so all transactions are named {method} unknown route.

No tracing for the production server

When I build and run the production (non-dev) server:

npm run build
NODE_OPTIONS=--require=elastic-apm-node/start node .output/server/index.mjs

This does not work. The first issue is that the built server is an ES module (ESM) as opposed to CommonJS. Support for instrumentating ES modules is experimental and limited. It is discussed here: https://www.elastic.co/guide/en/apm/agent/nodejs/current/esm.html

Ideally we would be able to get some instrumentation of the ESM code by using the additional --experimental-loader=elastic-apm-node/loader.mjs option:

node --require=elastic-apm-node/start.js --experimental-loader=elastic-apm-node/loader.mjs .output/server/index.mjs

This partially works. For example, when manually making a call to just the added "/api/hello" endpoint in my small Nuxt app:

% curl localhost:3000/api/hello
Hello World!

I successfully get a trace from the APM agent:

    trace e2e9f1
    `- transaction d5f7f2 "GET unknown route" (10.366ms, GET http://localhost:3000/api/hello -> 200)

However, when loading the full app in a browser (http://localhost:3000), I get a 500 error in the browser and this in the app log:

[nuxt] [request error] [unhandled] [500] The requested module 'vue/server-renderer' does not provide an export named 'renderToString'
  at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
  at async ModuleJob.run (node:internal/modules/esm/module_job:191:5)
  at async ModuleLoader.import (node:internal/modules/esm/loader:337:24)
  at async Object.handler (./.output/server/chunks/runtime.mjs:2887:19)
  at async Server.toNodeHandle (./.output/server/chunks/runtime.mjs:3157:7)
New request: http://localhost:3000/__nuxt_error?url=%2F&statusCode=500&statusMessage&message=The+requested+module+%27vue%2Fserver-renderer%27+does+not+provide+an+export+named+%27renderToString%27&stack
[nuxt] [request error] [unhandled] [500] The requested module 'vue/server-renderer' does not provide an export named 'renderToString'
  at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
  at async ModuleJob.run (node:internal/modules/esm/module_job:191:5)
  at async ModuleLoader.import (node:internal/modules/esm/loader:337:24)
  at async Object.handler (./.output/server/chunks/runtime.mjs:2887:19)
  at async Server.toNodeHandle (./.output/server/chunks/runtime.mjs:3157:7)

This is almost certainly a bug in the underlying library that the APM agent is using to hook into ES module imports. That hooking is breaking the vue/server-renderer module. That library, import-in-the-middle, is under active development: https://github.com/nodejs/import-in-the-middle/pulls I expect the handling of this will improve over time.

Bundling

Finally, if I understand correctly, the built server code uses a bundler (esbuild?). Currently this APM agent does not support instrumenting libraries used in bundled code. Node.js core libraries (like http) can still be instrumented, but any other libraries cannot. That may mean somewhat limited tracing data.

If you are mainly interested in HTTP incoming and outgoing spans, then this may be fine for you.

options

I have not tried this, but perhaps the Nuxt tsconfig could be changed to build a CommonJS server, rather than ESM code. Then that might allow the built server to be instrumented without the --experimental-loader=elastic-apm-node/loader.mjs loader that is causing issues.

I would like to thank you for the very detailed response to the thread.
Ok, I'll try to survey other possibilities.

@trentm
Copy link
Member

trentm commented Jul 23, 2024

Okay, thanks. I'll close this issue now. Please feel free to re-open, or create a new one if you have other questions. I'm sorry this doesn't work out of the box for you.

@trentm trentm closed this as completed Jul 23, 2024
@trentm
Copy link
Member

trentm commented Jul 23, 2024

However, when loading the full app in a browser (http://localhost:3000), I get a 500 error in the browser and this in the app log:

[nuxt] [request error] [unhandled] [500] The requested module 'vue/server-renderer' does not provide an export named 'renderToString'
  at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
  at async ModuleJob.run (node:internal/modules/esm/module_job:191:5)
  at async ModuleLoader.import (node:internal/modules/esm/loader:337:24)
  at async Object.handler (./.output/server/chunks/runtime.mjs:2887:19)
  at async Server.toNodeHandle (./.output/server/chunks/runtime.mjs:3157:7)
...

This is almost certainly a bug in the underlying library that the APM agent is using to hook into ES module imports. That hooking is breaking the vue/server-renderer module. That library, import-in-the-middle, is under active development: https://github.com/nodejs/import-in-the-middle/pulls I expect the handling of this will improve over time.

Actually this exact issue was just recently fixed in import-in-the-middle: nodejs/import-in-the-middle#139
The next release of elastic-apm-node will include a fix for this. So, that means that:

  1. You should be able to get limited instrumentation of Nuxt 3 apps via node --require=elastic-apm-node/start.js --experimental-loader=elastic-apm-node/loader.mjs .output/server/index.mjs.
  2. Limitation: Because the built server is bundled the instrumentation will be limited to core Node.js modules (i.e. mainly http and https usage). Other modules, like express or pg, etc. will not be instrumented.
  3. Limitation: The APM agent doesn't know about Nuxt routing, so while incoming HTTP requests will be instrumented the transaction name won't be as useful as it could be.

@trentm trentm mentioned this issue Jul 23, 2024
@cwhsu1984
Copy link
Author

I have tried the --experimental-loader with 4.7.0, and saw the same error that you show previously.
This is the result that I see in the APM.
image

I just tried the same with 4.7.1, and unfortunately I saw another issue as below. My application crashed after some time, so it seems 4.7.1 still not solving the usage for Nuextjs.

[ERROR] 2024-07-30T06:40:34.520Z [96dc4b49-23df-48a7-ae38-259654fc4898] - logId: C30-202-740 error-message: The requested module 'vue' does not provide an export named 'unref' stack: import { version, unref } from 'vue';
  ^^^^^
  SyntaxError: The requested module 'vue' does not provide an export named 'unref'
  at ModuleJob._instantiate (node:internal/modules/esm/module_job:131:21)
  at async ModuleJob.run (node:internal/modules/esm/module_job:213:5)
  at async ModuleLoader.import (node:internal/modules/esm/loader:308:24)
  at async server/chunks/nitro/node-server.mjs:2380:19
  at async Object.callAsync (server/chunks/nitro/node-server.mjs:5324:16)
  at async Server.toNodeHandle (server/chunks/nitro/node-server.mjs:2569:7)
[nuxt] [request error] [unhandled] [500] The requested module 'vue' does not provide an export named 'unref'
  at ModuleJob._instantiate (node:internal/modules/esm/module_job:131:21)
  at async ModuleJob.run (node:internal/modules/esm/module_job:213:5)
  at async ModuleLoader.import (node:internal/modules/esm/loader:308:24)
  at async ./server/chunks/nitro/node-server.mjs:2380:19
  at async Object.callAsync (./server/chunks/nitro/node-server.mjs:5324:16)
  at async Server.toNodeHandle (./server/chunks/nitro/node-server.mjs:2569:7)
[ERROR] 2024-07-30T06:40:34.586Z [2e1e8b13-bd97-4cf1-9975-20fa001306d7] - logId: U30-802-140 error-message: The requested module 'vue' does not provide an export named 'unref' stack: import { version, unref } from 'vue';
  ^^^^^
  SyntaxError: The requested module 'vue' does not provide an export named 'unref'
  at ModuleJob._instantiate (node:internal/modules/esm/module_job:131:21)
  at async ModuleJob.run (node:internal/modules/esm/module_job:213:5)
  at async ModuleLoader.import (node:internal/modules/esm/loader:308:24)
  at async server/chunks/nitro/node-server.mjs:2380:19
  at async Object.callAsync (server/chunks/nitro/node-server.mjs:5324:16)
  at async Server.toNodeHandle (server/chunks/nitro/node-server.mjs:2569:7)
[nuxt] [request error] [unhandled] [500] The requested module 'vue' does not provide an export named 'unref'
  at ModuleJob._instantiate (node:internal/modules/esm/module_job:131:21)
  at async ModuleJob.run (node:internal/modules/esm/module_job:213:5)
  at async ModuleLoader.import (node:internal/modules/esm/loader:308:24)
  at async ./server/chunks/nitro/node-server.mjs:2380:19
  at async Object.callAsync (./server/chunks/nitro/node-server.mjs:5324:16)
  at async Server.toNodeHandle (./server/chunks/nitro/node-server.mjs:2569:7)

@trentm
Copy link
Member

trentm commented Aug 1, 2024

SyntaxError: The requested module 'vue' does not provide an export named 'unref'

It looks like that particular crash will be fixed when we have a release with this update: #4162

@cwhsu1984
Copy link
Author

I'm not sure exactly how I should apply this, so this is what I did.

...
WORKDIR /app/server
RUN npm install [email protected]
RUN npm install [email protected]
WORKDIR /app
COPY --from=builder /app/.env.* ./
COPY --from=builder /app/.output .

CMD node -r ./server/node_modules/elastic-apm-node/start.js --experimental-loader=./server/node_modules/elastic-apm-node/loader.mjs ./server/index.mjs

Still the same error.

[ERROR] 2024-08-02T02:12:25.215Z [6cf1909a-1645-4b3b-aa87-e54cc7d9dd78] - logId: L01-722-812 error-message: The requested module 'vue' does not provide an export named 'unref' stack: import { version, unref } from 'vue';
  ^^^^^
  SyntaxError: The requested module 'vue' does not provide an export named 'unref'
  at ModuleJob._instantiate (node:internal/modules/esm/module_job:132:21)
  at async ModuleJob.run (node:internal/modules/esm/module_job:214:5)
  at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
  at async server/chunks/nitro/node-server.mjs:2380:19
  at async Object.callAsync (server/chunks/nitro/node-server.mjs:5324:16)
  at async Server.toNodeHandle (server/chunks/nitro/node-server.mjs:2569:7)
[nuxt] [request error] [unhandled] [500] The requested module 'vue' does not provide an export named 'unref'
  at ModuleJob._instantiate (node:internal/modules/esm/module_job:132:21)
  at async ModuleJob.run (node:internal/modules/esm/module_job:214:5)
  at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
  at async ./server/chunks/nitro/node-server.mjs:2380:19
  at async Object.callAsync (./server/chunks/nitro/node-server.mjs:5324:16)
  at async Server.toNodeHandle (./server/chunks/nitro/node-server.mjs:2569:7)

@trentm
Copy link
Member

trentm commented Aug 2, 2024

@cwhsu1984 Sorry to imply that we had a release with that fix. We do not yet have a release of this APM agent with the update to the import-in-the-middle library that you need.

@cwhsu1984
Copy link
Author

Is there a timeline or schedule date for the next release?

trentm added a commit that referenced this issue Aug 8, 2024
This should fix the issue being hit here:
#4143 (comment)
@trentm trentm mentioned this issue Aug 8, 2024
trentm added a commit that referenced this issue Aug 9, 2024
This should fix the issue being hit here:
#4143 (comment)
trentm added a commit that referenced this issue Aug 9, 2024
This should fix the issue being hit here:
#4143 (comment)
@trentm
Copy link
Member

trentm commented Aug 9, 2024

@cwhsu1984 There is now a v4.7.3 release that has a fix for that particular issue from #4143 (comment)

(Note again, to set expectations, that instrumentation of a Nuxtjs app possibly using ESM and bundling, will be limited. Of course the APM agent should never cause the app to crash.)

@cwhsu1984
Copy link
Author

Thanks for the info again.
I tried v4.7.3 and it fixed the crash for the Nuxtjs app. And as you mentioned, it's still not getting useful data for transaction.

{"log.level":"debug","@timestamp":"2024-08-13T02:13:53.620Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","message":"no active transaction found - cannot build new span"}

fpm-peter pushed a commit to fpm-git/apm-agent-nodejs that referenced this issue Aug 20, 2024
This should fix the issue being hit here:
elastic#4143 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants