Skip to content

Commit 4533eea

Browse files
committed
chore: updated
1 parent 4db557b commit 4533eea

File tree

4 files changed

+11
-208
lines changed

4 files changed

+11
-208
lines changed

packages/collector/src/announceCycle/agentready.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ function enter(_ctx) {
154154
// eslint-disable-next-line no-unused-expressions
155155
process?.send?.('instana.collector.initialized');
156156

157-
if (!isMainThread) {
157+
if (!isMainThread && process.env.INSTANA_PARENT_PROCESS_COMMUNICATION !== 'false') {
158158
const { parentPort } = require('worker_threads');
159159

160160
if (parentPort) {

packages/collector/test/tracing/logging/pino/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ describe('tracing/logging/pino', function () {
112112
env: {
113113
PINO_WORKER_MODE: 'transport',
114114
PINO_EXPRESS: 'false',
115-
NODE_OPTIONS: `--require ${path.join(__dirname, '../../../..', 'src', 'immediate.js')}`
115+
NODE_OPTIONS: `--require ${path.join(__dirname, '../../../..', 'src', 'immediate.js')}`,
116+
INSTANA_PARENT_PROCESS_COMMUNICATION: 'false'
116117
}
117118
});
118119

packages/core/src/util/excludedFromInstrumentation.js

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,61 +13,22 @@
1313
// no value and also creates confusing log output, so we exclude them here explicitly.
1414
const excludePattern = /^.*\/(?:npm(?:\.js)?|npm-cli(?:\.js)?|yarn(?:\.js)?|yarn\/lib\/cli(?:\.js)?)$/i;
1515

16-
/**
17-
* Determines if the current process is a Pino thread-stream worker.
18-
* Pino uses background worker threads for "thread-stream" logging, which should not be instrumented.
19-
* @returns {boolean}
20-
*/
21-
function isPinoThreadStreamWorker() {
22-
try {
23-
const { isMainThread, workerData } = require('worker_threads');
24-
if (isMainThread) return false;
25-
26-
if (workerData && typeof workerData === 'object') {
27-
const nested = workerData.workerData;
28-
const isPinoWorker =
29-
typeof workerData.filename === 'string' &&
30-
nested &&
31-
nested.$context &&
32-
typeof nested.$context.threadStreamVersion === 'string';
33-
34-
if (isPinoWorker) {
35-
return true;
36-
}
37-
}
38-
return false;
39-
} catch {
40-
return false;
41-
}
42-
}
43-
4416
/**
4517
* @type {Function}
4618
* @returns {boolean}
4719
*/
4820
module.exports = exports = function isExcludedFromInstrumentation() {
4921
const mainModule = process.argv[1];
50-
let excludedFromInstrumentation = typeof mainModule === 'string' && excludePattern.test(mainModule);
51-
let reason = 'npm-yarn';
52-
53-
if (!excludedFromInstrumentation && isPinoThreadStreamWorker()) {
54-
excludedFromInstrumentation = true;
55-
reason = 'pino-thread-stream';
56-
}
22+
const excludedFromInstrumentation = typeof mainModule === 'string' && excludePattern.test(mainModule);
5723

58-
const logEnabled =
59-
process.env.INSTANA_DEBUG ||
60-
(process.env.INSTANA_LOG_LEVEL && ['info', 'debug'].includes(process.env.INSTANA_LOG_LEVEL.toLowerCase()));
24+
if (excludedFromInstrumentation) {
25+
const logLevelIsDebugOrInfo =
26+
process.env.INSTANA_DEBUG ||
27+
(process.env.INSTANA_LOG_LEVEL &&
28+
(process.env.INSTANA_LOG_LEVEL.toLowerCase() === 'info' ||
29+
process.env.INSTANA_LOG_LEVEL.toLowerCase() === 'debug'));
6130

62-
if (excludedFromInstrumentation && logEnabled) {
63-
if (reason === 'pino-thread-stream') {
64-
// eslint-disable-next-line no-console
65-
console.log(
66-
// eslint-disable-next-line max-len
67-
`[Instana] INFO: Skipping instrumentation for process ${process.pid} - detected as a Pino thread-stream worker. ` +
68-
'Logging threads do not require instrumentation.'
69-
);
70-
} else {
31+
if (logLevelIsDebugOrInfo) {
7132
// eslint-disable-next-line no-console
7233
console.log(
7334
`[Instana] INFO: Not instrumenting process ${process.pid}: ${process.argv[0]} ${mainModule}` +

packages/core/test/util/excludedFromInstrumentation_test.js

Lines changed: 0 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -66,165 +66,6 @@ describe('util.excludedFromInstrumentation', () => {
6666
expect(isExcluded('/usr/local/npmx.js')).to.be.false;
6767
});
6868

69-
describe('pino thread-stream worker detection', () => {
70-
let originalRequire;
71-
72-
beforeEach(() => {
73-
originalRequire = require.cache[require.resolve('worker_threads')];
74-
});
75-
76-
afterEach(() => {
77-
if (originalRequire) {
78-
require.cache[require.resolve('worker_threads')] = originalRequire;
79-
} else {
80-
delete require.cache[require.resolve('worker_threads')];
81-
}
82-
delete require.cache[require.resolve('../../src/util/excludedFromInstrumentation')];
83-
});
84-
85-
it('should exclude Pino thread-stream worker with valid structure', () => {
86-
mockWorkerThreads({
87-
isMainThread: false,
88-
workerData: {
89-
filename: '/path/to/worker.js',
90-
workerData: {
91-
$context: {
92-
threadStreamVersion: '2.0.0'
93-
},
94-
target: 'pino-pretty'
95-
}
96-
}
97-
});
98-
99-
const checkExclusion = require('../../src/util/excludedFromInstrumentation');
100-
expect(checkExclusion()).to.be.true;
101-
});
102-
103-
it('should exclude Pino thread-stream worker with targets property', () => {
104-
mockWorkerThreads({
105-
isMainThread: false,
106-
workerData: {
107-
filename: '/path/to/worker.js',
108-
workerData: {
109-
$context: {
110-
threadStreamVersion: '2.1.0'
111-
},
112-
targets: [{ target: 'pino-pretty' }]
113-
}
114-
}
115-
});
116-
117-
const checkExclusion = require('../../src/util/excludedFromInstrumentation');
118-
expect(checkExclusion()).to.be.true;
119-
});
120-
121-
it('should not exclude main thread', () => {
122-
mockWorkerThreads({
123-
isMainThread: true,
124-
workerData: {
125-
filename: '/path/to/worker.js',
126-
workerData: {
127-
$context: {
128-
threadStreamVersion: '2.0.0'
129-
}
130-
}
131-
}
132-
});
133-
134-
const checkExclusion = require('../../src/util/excludedFromInstrumentation');
135-
expect(checkExclusion()).to.be.false;
136-
});
137-
138-
it('should not exclude worker without workerData', () => {
139-
mockWorkerThreads({
140-
isMainThread: false,
141-
workerData: null
142-
});
143-
144-
const checkExclusion = require('../../src/util/excludedFromInstrumentation');
145-
expect(checkExclusion()).to.be.false;
146-
});
147-
148-
it('should not exclude worker without filename', () => {
149-
mockWorkerThreads({
150-
isMainThread: false,
151-
workerData: {
152-
workerData: {
153-
$context: {
154-
threadStreamVersion: '2.0.0'
155-
}
156-
}
157-
}
158-
});
159-
160-
const checkExclusion = require('../../src/util/excludedFromInstrumentation');
161-
expect(checkExclusion()).to.be.false;
162-
});
163-
164-
it('should not exclude worker without nested workerData', () => {
165-
mockWorkerThreads({
166-
isMainThread: false,
167-
workerData: {
168-
filename: '/path/to/worker.js'
169-
}
170-
});
171-
172-
const checkExclusion = require('../../src/util/excludedFromInstrumentation');
173-
expect(checkExclusion()).to.be.false;
174-
});
175-
176-
it('should not exclude worker without $context', () => {
177-
mockWorkerThreads({
178-
isMainThread: false,
179-
workerData: {
180-
filename: '/path/to/worker.js',
181-
workerData: {
182-
someOtherProperty: 'value'
183-
}
184-
}
185-
});
186-
187-
const checkExclusion = require('../../src/util/excludedFromInstrumentation');
188-
expect(checkExclusion()).to.be.false;
189-
});
190-
191-
it('should not exclude worker without threadStreamVersion', () => {
192-
mockWorkerThreads({
193-
isMainThread: false,
194-
workerData: {
195-
filename: '/path/to/worker.js',
196-
workerData: {
197-
$context: {
198-
someOtherProperty: 'value'
199-
}
200-
}
201-
}
202-
});
203-
204-
const checkExclusion = require('../../src/util/excludedFromInstrumentation');
205-
expect(checkExclusion()).to.be.false;
206-
});
207-
208-
it('should not exclude non-Pino worker thread', () => {
209-
mockWorkerThreads({
210-
isMainThread: false,
211-
workerData: {
212-
customData: 'some other worker'
213-
}
214-
});
215-
216-
const checkExclusion = require('../../src/util/excludedFromInstrumentation');
217-
expect(checkExclusion()).to.be.false;
218-
});
219-
220-
function mockWorkerThreads(mockData) {
221-
const mockModule = {
222-
exports: mockData
223-
};
224-
require.cache[require.resolve('worker_threads')] = mockModule;
225-
}
226-
});
227-
22869
function isExcluded(argv1) {
22970
process.argv[1] = argv1;
23071
return isExcludedFromInstrumentation();

0 commit comments

Comments
 (0)