-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): avoided creating standalone exit spans when using the sdk (#…
- Loading branch information
Showing
5 changed files
with
168 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/collector/test/tracing/protocols/http/client/sdkApp1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* (c) Copyright IBM Corp. 2024 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// NOTE: c8 bug https://github.com/bcoe/c8/issues/166 | ||
process.on('SIGTERM', () => { | ||
process.disconnect(); | ||
process.exit(0); | ||
}); | ||
|
||
const instana = require('../../../../..')(); | ||
const { delay } = require('../../../../../../core/test/test_util'); | ||
const nodeFetch = require('node-fetch-v2'); | ||
|
||
const main = async () => { | ||
let err1; | ||
|
||
try { | ||
const req = new nodeFetch.Request('https://example.com'); | ||
await nodeFetch(req); | ||
|
||
await instana.sdk.async.startEntrySpan('my-translation-service'); | ||
await nodeFetch('https://www.ibm.com/products/instana'); | ||
} catch (err) { | ||
err1 = err; | ||
} | ||
|
||
instana.sdk.async.completeEntrySpan(err1); | ||
}; | ||
|
||
const app = async () => { | ||
let count = 0; | ||
|
||
while (count < 2) { | ||
// eslint-disable-next-line no-await-in-loop | ||
await main(); | ||
count += 1; | ||
|
||
// eslint-disable-next-line no-await-in-loop | ||
await delay(500); | ||
} | ||
}; | ||
|
||
app(); |
60 changes: 60 additions & 0 deletions
60
packages/collector/test/tracing/protocols/http/client/sdkApp2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* (c) Copyright IBM Corp. 2024 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// NOTE: c8 bug https://github.com/bcoe/c8/issues/166 | ||
process.on('SIGTERM', () => { | ||
process.disconnect(); | ||
process.exit(0); | ||
}); | ||
|
||
const instana = require('../../../../..')(); | ||
const bodyParser = require('body-parser'); | ||
const express = require('express'); | ||
const morgan = require('morgan'); | ||
const port = require('../../../../test_util/app-port')(); | ||
|
||
const app = express(); | ||
const logPrefix = 'SDK App 2\t'; | ||
|
||
if (process.env.WITH_STDOUT) { | ||
app.use(morgan(`${logPrefix}:method :url :status`)); | ||
} | ||
|
||
app.use(bodyParser.json()); | ||
|
||
app.get('/', (req, res) => res.sendStatus(200)); | ||
|
||
app.get('/deferred-exit', (req, res) => { | ||
/* | ||
We do not support this case, because calling "startExitSpan" calls "skipExitTracing" | ||
and this function does not respect reduced spans. | ||
setTimeout(async () => { | ||
await instana.sdk.async.startExitSpan('deferred-exit'); | ||
instana.sdk.async.completeExitSpan(); | ||
}, 1000); | ||
*/ | ||
|
||
setTimeout(async () => { | ||
await instana.sdk.async.startEntrySpan('deferred-entry'); | ||
await instana.sdk.async.startExitSpan('deferred-exit'); | ||
instana.sdk.async.completeExitSpan(); | ||
instana.sdk.async.completeEntrySpan(); | ||
}, 1000); | ||
|
||
res.sendStatus(200); | ||
}); | ||
|
||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters