Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/collector/src/announceCycle/agentready.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ function enter(_ctx) {
}

logger.info('The Instana Node.js collector is now fully initialized and connected to the Instana host agent.');

// CASE: This is an IPC message only for a parent process.
// TODO: Add an EventEmitter functionality for the current process
// such as `instana.on('instana.collector.initialized')`.
Expand Down
42 changes: 42 additions & 0 deletions packages/collector/test/tracing/misc/cjs-via-esm/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* (c) Copyright IBM Corp. 2025
*/

'use strict';

// NOTE: c8 bug https://github.com/bcoe/c8/issues/166
process.on('SIGTERM', () => {
process.disconnect();
process.exit(0);
});

const logPrefix = `CJS via ESM (${process.pid}):\t`;
const port = require('../../../test_util/app-port')();
const express = require('express');
const bodyParser = require('body-parser');
const pinoLogger = require('pino')();

const app = express();
app.use(bodyParser.json());

app.get('/', (req, res) => {
res.sendStatus(200);
});

app.get('/trigger', async (req, res) => {
log('Received request');
await fetch(`http://localhost:${port}`);
pinoLogger.error('wtf');
res.json({ success: true });
});

app.listen(port, () => {
log(`Listening on port: ${port}`);
});

function log() {
/* eslint-disable no-console */
const args = Array.prototype.slice.call(arguments);
args[0] = logPrefix + args[0];
console.log.apply(console, args);
}
67 changes: 67 additions & 0 deletions packages/collector/test/tracing/misc/cjs-via-esm/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* (c) Copyright IBM Corp. 2025
*/

'use strict';

const semver = require('semver');
const path = require('path');
const expect = require('chai').expect;
const supportedVersion = require('@instana/core').tracing.supportedVersion;
const ProcessControls = require('../../../test_util/ProcessControls');
const globalAgent = require('../../../globalAgent');
const { retry } = require('../../../../../core/test/test_util');

const mochaSuiteFn =
supportedVersion(process.versions.node) && semver.gte(process.versions.node, '18.19.0') ? describe : describe.skip;

mochaSuiteFn('tracing/cjs-via-esm', function () {
this.timeout(1000 * 60);
globalAgent.setUpCleanUpHooks();

let controls;
const agentControls = globalAgent.instance;

before(async () => {
const rootFolder = path.join(__dirname, '..', '..', '..', '..');

controls = new ProcessControls({
useGlobalAgent: true,
dirname: __dirname,
enableOtelIntegration: true,
execArgv: ['--import', `${rootFolder}/esm-register.mjs`]
});

await controls.startAndWaitForAgentConnection();
});

beforeEach(async () => {
await agentControls.clearReceivedTraceData();
});

after(async () => {
await controls.stop();
});

it('must trace', async () => {
await controls.sendRequest({
path: '/trigger'
});

return retry(async () => {
const spans = await agentControls.getSpans();

expect(spans.length).to.equal(4);

const pinoSpan = spans.find(span => span.n === 'log.pino');
expect(pinoSpan).to.exist;

const httpServerSpan = spans.find(span => span.n === 'node.http.server');
expect(httpServerSpan).to.exist;

const httpClientSpan = spans.find(span => span.n === 'node.http.client');
expect(httpClientSpan).to.exist;
expect(httpClientSpan.data).to.exist;
});
});
});