Skip to content

Commit 216c6db

Browse files
authored
fix: resolved TypeError undefined (reading 'pid') (#2124)
refs https://jsw.ibm.com/browse/INSTA-62678
1 parent aa185de commit 216c6db

File tree

4 files changed

+136
-1
lines changed

4 files changed

+136
-1
lines changed

packages/collector/src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ function init(userConfig = {}) {
116116

117117
pidStore.init(config);
118118
agentOpts.init(config);
119-
announceCycle.init(config, pidStore);
120119
agentConnection.init(config, pidStore);
120+
121+
announceCycle.init(config, pidStore);
121122
instanaNodeJsCore.init(config, agentConnection, pidStore);
122123

123124
if (isMainThread) {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* (c) Copyright IBM Corp. 2025
3+
*/
4+
5+
'use strict';
6+
7+
// NOTE: c8 bug https://github.com/bcoe/c8/issues/166
8+
process.on('SIGTERM', () => {
9+
process.disconnect();
10+
process.exit(0);
11+
});
12+
13+
require('@instana/collector')();
14+
15+
const logPrefix = `HTTP: Server (${process.pid}):\t`;
16+
17+
const port = process.env.APP_PORT;
18+
19+
const server = require('http')
20+
.createServer()
21+
.listen(port, () => {
22+
log(`Listening (HTTP) on port: ${port}`);
23+
});
24+
25+
server.on('request', (req, res) => {
26+
res.end();
27+
});
28+
29+
function log() {
30+
const args = Array.prototype.slice.call(arguments);
31+
args[0] = logPrefix + args[0];
32+
// eslint-disable-next-line no-console
33+
console.log.apply(console, args);
34+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
#######################################
4+
# (c) Copyright IBM Corp. 2025
5+
#######################################
6+
7+
current_dir=$(pwd)
8+
9+
cd "$(dirname "$0")/../../../../collector"
10+
echo "Running npm pack in $(pwd)"
11+
npm pack
12+
13+
version=$(node -p "require('./package.json').version")
14+
tarball="instana-collector-${version}.tgz"
15+
cp "./${tarball}" $current_dir/collector.tgz
16+
17+
cd "$(dirname "$0")/../core"
18+
echo "Running npm pack in $(pwd)"
19+
npm pack
20+
21+
version=$(node -p "require('./package.json').version")
22+
tarball="instana-core-${version}.tgz"
23+
cp "./${tarball}" $current_dir/core.tgz
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* (c) Copyright IBM Corp. 2025
3+
*/
4+
5+
'use strict';
6+
7+
const os = require('os');
8+
const { expect } = require('chai');
9+
const { execSync } = require('child_process');
10+
const supportedVersion = require('@instana/core').tracing.supportedVersion;
11+
const { retry } = require('../../../../core/test/test_util');
12+
const config = require('../../../../core/test/config');
13+
const ProcessControls = require('../../test_util/ProcessControls');
14+
const { AgentStubControls } = require('../../apps/agentStubControls');
15+
16+
const mochaSuiteFn = supportedVersion(process.versions.node) ? describe : describe.skip;
17+
18+
mochaSuiteFn('tracing/autoprofiler: not available', function () {
19+
this.timeout(config.getTestTimeout());
20+
21+
const agentControls = new AgentStubControls();
22+
let controls;
23+
let tmpDir;
24+
25+
before(async () => {
26+
tmpDir = os.tmpdir();
27+
28+
execSync('./prepare.sh', { cwd: __dirname, stdio: 'inherit' });
29+
execSync(`mv ./*.tgz ${tmpDir}`, { cwd: __dirname, stdio: 'inherit' });
30+
execSync(`cp app.js ${tmpDir}`, { cwd: __dirname, stdio: 'inherit' });
31+
32+
execSync('npm install --no-save --no-package-lock --prefix ./ ./core.tgz', {
33+
cwd: tmpDir,
34+
stdio: 'inherit'
35+
});
36+
37+
execSync('npm install --no-save --no-package-lock --prefix ./ ./collector.tgz', {
38+
cwd: tmpDir,
39+
stdio: 'inherit'
40+
});
41+
42+
execSync('rm -rf node_modules/@instana/autoprofile', { cwd: tmpDir, stdio: 'inherit' });
43+
44+
await agentControls.startAgent();
45+
46+
controls = new ProcessControls({
47+
dirname: tmpDir,
48+
agentControls,
49+
env: {
50+
INSTANA_AUTO_PROFILE: true
51+
}
52+
});
53+
54+
await controls.start();
55+
});
56+
57+
after(async () => {
58+
await controls.stop();
59+
await agentControls.stopAgent();
60+
});
61+
62+
it('must fire monitoring event', async () => {
63+
await controls.sendRequest({
64+
method: 'GET',
65+
path: '/dummy'
66+
});
67+
68+
return retry(async () => {
69+
const events = await agentControls.getMonitoringEvents();
70+
expect(events.length).to.be.at.least(1);
71+
expect(events[0].code).to.equal('nodejs_collector_native_addon_autoprofile_missing');
72+
73+
const profiles = await agentControls.getProfiles();
74+
expect(profiles.length).to.equal(0);
75+
});
76+
});
77+
});

0 commit comments

Comments
 (0)