Skip to content

Commit

Permalink
test: updated failing tests for root exit span (#1517)
Browse files Browse the repository at this point in the history
  • Loading branch information
aryamohanan authored Jan 16, 2025
1 parent ae09b14 commit d981bf2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ require('../../../../src')({

const fetch = require('node-fetch-v2');

const url = 'https://www.example.com';

function main() {
setTimeout(async () => {
await fetch(url);
await fetch('https://example.com');
}, 100);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,26 @@ const instana = require('../../../../src')({
allowRootExitSpan: true
}
});

const { delay } = require('../../../../../core/test/test_util');
const fetch = require('node-fetch-v2');

const url = 'https://www.example.com';
const executeRequest = async () => {
let error;

try {
await instana.sdk.async.startEntrySpan('my-translation-service');
await fetch('https://example.com');
} catch (err) {
error = err;
} finally {
instana.sdk.async.completeEntrySpan(error);
}
};

// Main function to execute the request with delay
const runApp = async () => {
await delay(200);
await executeRequest(); // Execute the request
};

/* eslint-disable no-console */
function main() {
setTimeout(() => {
instana.sdk.async
.startEntrySpan('test-timeout-span')
.then(async () => {
try {
await fetch(url);
} catch (error) {
console.log(error);
} finally {
instana.sdk.async.completeEntrySpan();
}
})
.catch(err => {
instana.sdk.async.completeEntrySpan(err);
console.log('Error starting test-timeout-span:', err);
});
}, 100);
}
main();
runApp();
34 changes: 19 additions & 15 deletions packages/collector/test/tracing/sdk/allowRootExitSpans/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

'use strict';

const expect = require('chai').expect;
const { expect } = require('chai');
const path = require('path');

const supportedVersion = require('@instana/core').tracing.supportedVersion;
Expand All @@ -19,16 +19,16 @@ const mochaSuiteFn = supportedVersion(process.versions.node) ? describe : descri
mochaSuiteFn('tracing/sdk/rootExitSpans', function () {
this.timeout(config.getTestTimeout());

const agentControls = globalAgent.instance;
globalAgent.setUpCleanUpHooks();

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

// an sdk entry span is wrapped to track the exit span
describe('app with entry span', function () {
let appControls;
const agentControls = globalAgent.instance;

before(async () => {
appControls = new ProcessControls({
Expand All @@ -39,7 +39,7 @@ mochaSuiteFn('tracing/sdk/rootExitSpans', function () {
await appControls.start(null, null, true);
});

it('should collect spans including sdk wrap', async () => {
it('should collect entry and exit spans', async () => {
await delay(200);

await retry(async () => {
Expand All @@ -54,29 +54,24 @@ mochaSuiteFn('tracing/sdk/rootExitSpans', function () {

// no sdk wrap present, exit span stands alone
describe('app without entry span', function () {
let agentControls;
let appControls;

before(async () => {
agentControls = new ProcessControls({
appControls = new ProcessControls({
appPath: path.join(__dirname, 'app_default'),
useGlobalAgent: true
});

await agentControls.start(null, null, true);
await appControls.start(null, null, true);
});

it('should trace single exit span only', async () => {
it('should trace only a single exit span', async () => {
await delay(200);

await retry(async () => {
const spans = await globalAgent.instance.getSpans();
const spans = await agentControls.getSpans();
expect(spans.length).to.equal(1);
expectExactlyOneMatching(spans, span => {
expect(span.t).to.exist;
expect(span.p).to.not.exist;
expect(span.s).to.exist;
expect(span.k).to.equal(constants.EXIT);
});
assertSingleExitSpan(spans);
});
});
});
Expand Down Expand Up @@ -110,4 +105,13 @@ mochaSuiteFn('tracing/sdk/rootExitSpans', function () {

return expectExactlyOneMatching(spans, expectations);
}

function assertSingleExitSpan(spans) {
expectExactlyOneMatching(spans, span => {
expect(span.t).to.exist;
expect(span.p).to.not.exist;
expect(span.s).to.exist;
expect(span.k).to.equal(constants.EXIT);
});
}
});

0 comments on commit d981bf2

Please sign in to comment.