-
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.
feat: added support for root exit spans (#1297)
refs INSTA-793 --------- Co-authored-by: kirrg001 <[email protected]> Co-authored-by: Arya <[email protected]>
- Loading branch information
1 parent
5647c3f
commit f1e1f30
Showing
35 changed files
with
1,161 additions
and
72 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
packages/collector/test/tracing/database/db2/allowRootExitSpanApp.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,108 @@ | ||
/* | ||
* (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); | ||
}); | ||
|
||
require('../../../..')({ | ||
tracing: { | ||
allowRootExitSpan: true | ||
} | ||
}); | ||
|
||
const { promisify } = require('util'); | ||
const ibmdb = require('ibm_db'); | ||
const { delay } = require('@instana/core/test/test_util'); | ||
|
||
const logPrefix = `DB2 Allow Root Exit Span App (${process.pid}):\t`; | ||
|
||
const DB2_DATABASE_NAME = process.env.DB2_DATABASE_NAME || 'nodedb'; | ||
const connStr1 = process.env.DB2_CONN_STR || 'HOSTNAME=localhost;UID=node;PWD=nodepw;PORT=58885;PROTOCOL=TCPIP'; | ||
let connection; | ||
|
||
const DB2_TABLE_NAME_1 = process.env.DB2_TABLE_NAME_1 || 'table1'; | ||
|
||
let tries = 0; | ||
const MAX_TRIES = 10; | ||
const CONNECT_TIMEOUT_IN_MS = 2000; | ||
|
||
const db2OpenPromisified = promisify(ibmdb.open); | ||
|
||
async function connect(connectionStr) { | ||
log(`Trying to connect to DB2, attempt ${tries} of ${MAX_TRIES}`); | ||
|
||
let conn; | ||
try { | ||
conn = await db2OpenPromisified(connectionStr); | ||
} catch (err) { | ||
log(err); | ||
if (tries > MAX_TRIES) { | ||
throw err; | ||
} | ||
|
||
tries += 1; | ||
log(`Trying to connect to DB2 again in ${CONNECT_TIMEOUT_IN_MS} milliseconds.`); | ||
await delay(CONNECT_TIMEOUT_IN_MS); | ||
return connect(connectionStr); | ||
} | ||
|
||
log('A client has successfully connected.'); | ||
return conn; | ||
} | ||
|
||
(async function openConnections() { | ||
await delay(1000 * 2); | ||
connection = await connect(`${connStr1};DATABASE=${DB2_DATABASE_NAME}`); | ||
|
||
connection.querySync(`drop table ${DB2_TABLE_NAME_1} if exists`); | ||
|
||
const result = connection.querySync( | ||
`create table ${DB2_TABLE_NAME_1} (COLINT INTEGER, COLDATETIME TIMESTAMP, COLTEXT VARCHAR(255))` | ||
); | ||
|
||
if (!(result instanceof Array)) { | ||
throw new Error(result); | ||
} | ||
|
||
log('Clients is successfully connected.'); | ||
|
||
const prepareStmt = connection.prepareSync(`SELECT * FROM ${DB2_TABLE_NAME_1}`); | ||
const executeResult = prepareStmt.executeSync(); | ||
executeResult.closeSync(); | ||
|
||
connection.beginTransaction(function (err) { | ||
if (err) { | ||
log(err); | ||
return; | ||
} | ||
|
||
connection.query(`SELECT * FROM ${DB2_TABLE_NAME_1}`, function (err1) { | ||
if (err1) { | ||
log(err); | ||
return; | ||
} | ||
|
||
connection.endTransaction(false, function (err2) { | ||
if (err2) { | ||
log(err); | ||
return; | ||
} | ||
|
||
log('Transaction has been committed.'); | ||
}); | ||
}); | ||
}); | ||
})(); | ||
|
||
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
54 changes: 54 additions & 0 deletions
54
packages/collector/test/tracing/database/ioredis/allowRootExitSpanApp.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,54 @@ | ||
/* | ||
* (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); | ||
}); | ||
|
||
require('../../../..')({ | ||
tracing: { | ||
allowRootExitSpan: true | ||
} | ||
}); | ||
|
||
const ioredis = require('ioredis'); | ||
const { delay } = require('@instana/core/test/test_util'); | ||
|
||
const logPrefix = `IORedis allowRootExitSpan App (${process.pid}):\t`; | ||
|
||
log(logPrefix); | ||
|
||
(async function connectRedis() { | ||
await delay(1000); | ||
|
||
try { | ||
const client = new ioredis(`//${process.env.REDIS}`); | ||
|
||
client.on('error', err => { | ||
log('IORedis client error:', err); | ||
}); | ||
|
||
client.on('ready', () => { | ||
log(`Connected to client 1 (${process.env.REDIS}).`); | ||
}); | ||
|
||
const multi = await client.multi().set('key', 'value').get('key').exec(); | ||
log('multi result: %s', multi); | ||
|
||
await client.quit(); | ||
} catch (err) { | ||
log('Failed to connect to IORedis:', err); | ||
} | ||
})(); | ||
|
||
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
55 changes: 55 additions & 0 deletions
55
packages/collector/test/tracing/database/redis/allowRootExitSpanApp.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,55 @@ | ||
/* | ||
* (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); | ||
}); | ||
|
||
require('../../../..')({ | ||
tracing: { | ||
allowRootExitSpan: true | ||
} | ||
}); | ||
|
||
const redis = require(process.env.REDIS_PKG); | ||
const { delay } = require('@instana/core/test/test_util'); | ||
|
||
const logPrefix = `Redis allowRootExitSpan App (version: ${process.env.REDIS_VERSION}, | ||
require: ${process.env.REDIS_PKG}):\t`; | ||
|
||
log(logPrefix); | ||
|
||
let client; | ||
|
||
(async function connectRedis() { | ||
await delay(1000); | ||
|
||
try { | ||
client = redis.createClient({ url: `redis://${process.env.REDIS}` }); | ||
client.on('error', err => { | ||
log('Redis client error:', err); | ||
}); | ||
|
||
await client.connect(); | ||
log('Redis connection established'); | ||
|
||
const result = await client.multi().set('key', 'value').get('key').exec(); | ||
log('value:', result); | ||
|
||
await client.quit(); | ||
} catch (err) { | ||
log('Failed to connect to Redis:', err); | ||
} | ||
})(); | ||
|
||
function log() { | ||
/* eslint-disable no-console */ | ||
const args = Array.prototype.slice.call(arguments); | ||
args[0] = logPrefix + args[0]; | ||
console.log.apply(console, args); | ||
} |
Oops, something went wrong.