scoutapp / scout_apm_node

ScoutAPM Agent for NodeJS. Supports Express and other frameworks
https://scoutapm.com
Other
8 stars 9 forks source link

[NestJS] Stopping undefined span #264

Closed Gilliam-avo closed 3 years ago

Gilliam-avo commented 3 years ago

We are using the express middleware on nestjs and it works fine except when the request is aborted. This causes span to be undefined and crashes the service. I linked the line that crashes and I can fix it by changing it to.

result = cb(() => span && span.stop(), {span, request, parent}); https://github.com/scoutapp/scout_apm_node/blob/5bc56f9af938108ecb97a6ac706fb6e9bfb49c38/lib/scout/index.ts#L608


at cb (/app/node_modules/@scout_apm/scout-apm/dist/lib/scout/index.js:424:48)
at ClientRequest.request.once (/app/node_modules/@scout_apm/scout-apm/dist/lib/integrations/http.js:115:17)
at Object.onceWrapper (events.js:286:20)
at ClientRequest.emit (events.js:198:13)
at ClientRequest.EventEmitter.emit (domain.js:448:20)
at Socket.socketCloseListener (_http_client.js:349:9)
at Socket.emit (events.js:203:15)
at Socket.EventEmitter.emit (domain.js:448:20)
at TCP._handle.close (net.js:606:12)```
ghost commented 3 years ago

Hey @Gilliam-avo thanks for reporting this -- I'm sorry to hear this,

I will make a PR and release a pre-release within the next 30 mins or so that you could use if you'd be OK with trying it out! There are some other changes in the pre-release version that you'll be able to use related to some open issues but you shouldn't see this bug any more

ghost commented 3 years ago

Hey @Gilliam-avo if you'd don't mind, please try out the v0.2.2-rc.1 pre-release build of scout

Gilliam-avo commented 3 years ago

Thanks, that solves our issue.

imashok02 commented 1 year ago

@Gilliam-avo Could you provide some of your code enabling scout to work on nestjs. I tried adding app.use(scout.expressMiddleware()); it works but often crashes the app.

Im getting below error on my local and not in my production

`/node_modules/got/index.js:482 proxy.emit('error', new got.HTTPError(statusCode, res.statusMessage, res.headers, opts), null, res); ^

GotError [HTTPError]: Response code 404 (Not Found) at EventEmitter. (/node_modules/got/index.js:482:24) at EventEmitter.emit (node:events:513:28) at getResponse (/node_modules/got/index.js:320:5) at Immediate. (/node_modules/got/index.js:147:6) at processImmediate (node:internal/timers:466:21) at process.callbackTrampoline (node:internal/async_hooks:130:17) { host: 's3-us-west-1.amazonaws.com', hostname: 's3-us-west-1.amazonaws.com', method: 'GET', path: '/scout-public-downloads/apm_core_agent/release/scout_apm_core-v1.3.0-unknown-apple-darwin.tgz', protocol: 'https:', url: 'https://s3-us-west-1.amazonaws.com/scout-public-downloads/apm_core_agent/release/scout_apm_core-v1.3.0-unknown-apple-darwin.tgz', statusCode: 404, statusMessage: 'Not Found', headers: { 'x-amz-request-id': 'XXXXXX', 'x-amz-id-2': 'XXXXXXXX', 'content-type': 'application/xml', 'transfer-encoding': 'chunked', date: 'Thu, 08 Dec 2022 16:28:50 GMT', server: 'AmazonS3', connection: 'close' } }`

Also tried v0.2.2-rc.1 pre-release build of scout

which was recommended.