|
| 1 | +/* |
| 2 | + * (c) Copyright IBM Corp. 2025 |
| 3 | + */ |
| 4 | + |
| 5 | +'use strict'; |
| 6 | + |
| 7 | +const semver = require('semver'); |
| 8 | +const path = require('path'); |
| 9 | +const expect = require('chai').expect; |
| 10 | +const supportedVersion = require('@instana/core').tracing.supportedVersion; |
| 11 | +const ProcessControls = require('../../../test_util/ProcessControls'); |
| 12 | +const globalAgent = require('../../../globalAgent'); |
| 13 | +const { retry } = require('../../../../../core/test/test_util'); |
| 14 | + |
| 15 | +const mochaSuiteFn = |
| 16 | + supportedVersion(process.versions.node) && semver.satisfies(process.versions.node, '18') ? describe : describe.skip; |
| 17 | + |
| 18 | +mochaSuiteFn('tracing/cjs-via-esm', function () { |
| 19 | + this.timeout(1000 * 60); |
| 20 | + globalAgent.setUpCleanUpHooks(); |
| 21 | + |
| 22 | + let controls; |
| 23 | + const agentControls = globalAgent.instance; |
| 24 | + |
| 25 | + before(async () => { |
| 26 | + const rootFolder = path.join(__dirname, '..', '..', '..', '..'); |
| 27 | + |
| 28 | + controls = new ProcessControls({ |
| 29 | + useGlobalAgent: true, |
| 30 | + dirname: __dirname, |
| 31 | + enableOtelIntegration: true, |
| 32 | + execArgv: ['--experimental-loader', `${rootFolder}/esm-loader.mjs`] |
| 33 | + }); |
| 34 | + |
| 35 | + await controls.startAndWaitForAgentConnection(); |
| 36 | + }); |
| 37 | + |
| 38 | + beforeEach(async () => { |
| 39 | + await agentControls.clearReceivedTraceData(); |
| 40 | + }); |
| 41 | + |
| 42 | + after(async () => { |
| 43 | + await controls.stop(); |
| 44 | + }); |
| 45 | + |
| 46 | + it('must trace', async () => { |
| 47 | + await controls.sendRequest({ |
| 48 | + path: '/trigger' |
| 49 | + }); |
| 50 | + |
| 51 | + return retry(async () => { |
| 52 | + const spans = await agentControls.getSpans(); |
| 53 | + |
| 54 | + expect(spans.length).to.equal(4); |
| 55 | + |
| 56 | + const pinoSpan = spans.find(span => span.n === 'log.pino'); |
| 57 | + expect(pinoSpan).to.exist; |
| 58 | + |
| 59 | + const httpServerSpan = spans.find(span => span.n === 'node.http.server'); |
| 60 | + expect(httpServerSpan).to.exist; |
| 61 | + |
| 62 | + const httpClientSpan = spans.find(span => span.n === 'node.http.client'); |
| 63 | + expect(httpClientSpan).to.exist; |
| 64 | + expect(httpClientSpan.data).to.exist; |
| 65 | + }); |
| 66 | + }); |
| 67 | +}); |
0 commit comments