Skip to content

Commit 0ea0448

Browse files
committed
chore: fine tuning
1 parent c7a8a5a commit 0ea0448

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

packages/collector/test/tracing/database/redis/allowRootExitSpanApp.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ require('../../../..')({
1919
const redis = require(process.env.REDIS_PKG);
2020
const { delay } = require('@instana/core/test/test_util');
2121

22-
const logPrefix = `Redis allowRootExitSpan App (version: ${process.env.REDIS_VERSION},
22+
const redisVersion = process.env.REDIS_VERSION;
23+
const logPrefix = `Redis allowRootExitSpan App (version: ${redisVersion},
2324
require: ${process.env.REDIS_PKG}):\t`;
2425

2526
log(logPrefix);
@@ -41,7 +42,12 @@ let client;
4142
const result = await client.multi().set('key', 'value').get('key').exec();
4243
log('value:', result);
4344

44-
await client.close();
45+
// In v5, the quit is replaced by close
46+
if (redisVersion === 'latest') {
47+
await client.close();
48+
} else {
49+
await client.quit();
50+
}
4551
} catch (err) {
4652
log('Failed to connect to Redis:', err);
4753
}

packages/collector/test/tracing/database/redis/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ app.get('/blocking', async (req, res) => {
149149

150150
app.get('/scan-iterator', async (req, res) => {
151151
if (redisVersion === 'latest') {
152-
// Redis v5: SCAN iterators return batches of keys, enabling multi-key commands like mGet
152+
// v5: SCAN iterators return batches of keys, enabling multi-key commands like mGet
153153
// eslint-disable-next-line no-restricted-syntax
154154
for await (const keys of connection.scanIterator()) {
155155
try {
@@ -159,7 +159,7 @@ app.get('/scan-iterator', async (req, res) => {
159159
}
160160
}
161161
} else {
162-
// Redis v4: SCAN iterators return individual keys
162+
// v4: SCAN iterators return individual keys
163163
// eslint-disable-next-line no-restricted-syntax
164164
for await (const key of connection.scanIterator()) {
165165
try {

packages/collector/test/tracing/database/redis/mockVersion.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ let mockedModuleName;
1515
if (REDIS_PKG === 'redis') {
1616
mockedModuleName = REDIS_VERSION === 'latest' ? 'redis' : `redis-${REDIS_VERSION}`;
1717
} else if (REDIS_PKG === '@redis/client') {
18-
// NOTE: The @redis/client package was introduced with Redis v4 (client v1).
19-
// In Redis v5, the versioning of @redis/client was aligned with Redis itself,
20-
// so @redis/client v5 corresponds to Redis v5.
18+
// NOTE: The '@redis/client' package was introduced with Redis v4 (client v1).
19+
// In Redis v5, the versioning of '@redis/client' was aligned with Redis itself,
20+
// so '@redis/client' v5 corresponds to Redis v5.
2121
mockedModuleName = REDIS_VERSION === 'latest' ? '@redis/client' : `@redis/client-${REDIS_VERSION}`;
2222
}
2323

packages/collector/test/tracing/database/redis/test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const legacyVersion = 'v3';
9090
// In v5, Redis moved “Isolation Pool” into RedisClientPool.
9191
// see: //github.com/redis/node-redis/blob/master/docs/pool.md
9292
if (redisVersion === 'latest') {
93-
mochaSuiteFn('When clientpool is used', function () {
93+
mochaSuiteFn('When connected via clientpool', function () {
9494
globalAgent.setUpCleanUpHooks();
9595
let controls;
9696

@@ -771,7 +771,7 @@ const legacyVersion = 'v3';
771771
span => expect(span.n).to.equal('node.http.server'),
772772
span => expect(span.data.http.method).to.equal('GET')
773773
]);
774-
// NOTE: Redis v5 SCAN iterators yield batches of keys, enabling multi-key commands like MGET.
774+
// NOTE: v5 SCAN iterators yield batches of keys, enabling multi-key commands like MGET.
775775
// See: https://github.com/redis/node-redis/blob/master/docs/v4-to-v5.md#scan-iterators
776776
const expectedSpanCount = redisVersion === 'latest' ? 1 : 4;
777777
const expectedRedisCommand = redisVersion === 'latest' ? 'mGet' : 'get';
@@ -797,8 +797,8 @@ const legacyVersion = 'v3';
797797
}
798798

799799
// See https://redis.js.org/#node-redis-usage-basic-example blocking commands
800-
// In Redis v5, the "Isolation Pool" was introduced via RedisClientPool.
801-
// Since it requires a new type of pool connection, a separate test suite created starting from v5.
800+
// In v5, the "Isolation Pool" was introduced via RedisClientPool.
801+
// Since it requires a new type of pool connection, skipping the test.
802802
if (redisVersion !== 'latest') {
803803
it('blocking', () => testBlockingCommand(controls, setupType));
804804
}

packages/core/src/tracing/instrumentation/database/redis.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ exports.deactivate = function deactivate() {
2626
};
2727

2828
exports.init = function init() {
29-
// In v5, the location of the commands module has changed.
30-
hook.onFileLoad(/\/@redis\/client\/dist\/lib\/commands\/index.js/, captureCommands);
3129
// v4 commands, "redis-commands" is outdated and no longer compatible with it
3230
hook.onFileLoad(/\/@redis\/client\/dist\/lib\/cluster\/commands.js/, captureCommands);
3331

32+
// In v5, the location of the commands module has changed.
33+
hook.onFileLoad(/\/@redis\/client\/dist\/lib\/commands\/index.js/, captureCommands);
3434
hook.onModuleLoad('redis', instrument);
3535
hook.onModuleLoad('@redis/client', instrument);
3636
};

0 commit comments

Comments
 (0)