-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(metrics): do not report metrics from worker threads (#517)
refs 88823, refs #500 When instrumented via NODE_OPTIONS="--require ..." (which is inherited by worker threads), each worker thread will announce independently and act like the main thread. This can cause issues, in particular if the worker thread is started from a dependency in node_ module and it identifies a different package.json as its main package.json, hence reporting a different application name etc. To prevent this, we disable sending metrics and snapshot data from worker threads for now.
- Loading branch information
Showing
11 changed files
with
329 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/collector/test/metrics/appWithWorkerThread/app.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* (c) Copyright IBM Corp. 2022 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
if (!process.env.NODE_OPTIONS) { | ||
// Either the test instruments this app via NODE_OTIONS=--require... or it expects the app to be instrumneted via | ||
// an in-code require. | ||
require('../../..')(); | ||
} | ||
|
||
const express = require('express'); | ||
const morgan = require('morgan'); | ||
|
||
const { getLogger } = require('../../../../core/test/test_util'); | ||
|
||
const app = express(); | ||
const logPrefix = `Worker Thread App (${process.pid}):\t`; | ||
const log = getLogger(logPrefix); | ||
|
||
// starts the worker thread | ||
require('module-that-creates-a-worker-thread')(); | ||
|
||
if (process.env.WITH_STDOUT) { | ||
app.use(morgan(`${logPrefix}:method :url :status`)); | ||
} | ||
|
||
app.get('/', (req, res) => { | ||
res.sendStatus(200); | ||
}); | ||
|
||
app.listen(process.env.APP_PORT, () => { | ||
log(`Listening on port: ${process.env.APP_PORT}`); | ||
}); |
59 changes: 59 additions & 0 deletions
59
...est/metrics/appWithWorkerThread/node_modules/module-that-creates-a-worker-thread/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
...rThread/node_modules/module-that-creates-a-worker-thread/node_modules/README.md
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
...metrics/appWithWorkerThread/node_modules/module-that-creates-a-worker-thread/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
packages/collector/test/metrics/appWithWorkerThread/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "worker-thread-test-app", | ||
"private": true, | ||
"version": "1.0.0", | ||
"description": "This is a test application to test snapshot and metrics data.", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/instana/nodejs.git" | ||
}, | ||
"main": "app.js", | ||
"author": { | ||
"name": "Bastian Krol", | ||
"email": "[email protected]" | ||
}, | ||
"license": "MIT" | ||
} |
Oops, something went wrong.