diff --git a/packages/collector/test/tracing/database/ioredis/test.js b/packages/collector/test/tracing/database/ioredis/test.js index a3e4093746..bd5a705ab3 100644 --- a/packages/collector/test/tracing/database/ioredis/test.js +++ b/packages/collector/test/tracing/database/ioredis/test.js @@ -27,7 +27,9 @@ const mochaSuiteFn = function checkConnection(span, setupType) { if (setupType === 'cluster') { - expect(span.data.redis.connection).to.equal(process.env.AZURE_REDIS_CLUSTER); + // NOTE: we currently extract the client ip address of the cluster + // TODO: https://jsw.ibm.com/browse/INSTA-14540 + expect(span.data.redis.connection).to.exist; } else { expect(span.data.redis.connection).to.equal(process.env.REDIS); } @@ -347,72 +349,125 @@ function checkConnection(span, setupType) { span => expect(span.data.http.method).to.equal('GET') ]); - // 1 x entry - // 1 x multi containing the sub commands - // 1 x exec span - // 2 x sub commands - // TODO: https://jsw.ibm.com/browse/INSTA-14540 - expect(spans.length).to.equal(5); - - const multiSpan = expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(writeEntrySpan.t), - span => expect(span.p).to.equal(writeEntrySpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.b.s).to.equal(2), - span => expect(span.b.u).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('multi'), - span => expect(span.data.redis.subCommands).to.deep.equal(['hset', 'hget']) - ]); - - expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(writeEntrySpan.t), - span => expect(span.p).to.equal(multiSpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.b).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('exec') - ]); - expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(writeEntrySpan.t), - span => expect(span.p).to.equal(multiSpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.b).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('hset') - ]); - expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(writeEntrySpan.t), - span => expect(span.p).to.equal(multiSpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.b).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('hget') - ]); + if (setupType === 'cluster') { + // 1 x entry + // NO multi + // 1 x exec span + // 2 x sub commands + // TODO: https://jsw.ibm.com/browse/INSTA-14540 + expect(spans.length).to.equal(4); + } else { + // 1 x entry + // 1 x multi containing the sub commands + // 1 x exec span + // 2 x sub commands + expect(spans.length).to.equal(5); + } + + if (setupType !== 'cluster') { + const multiSpan = expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(writeEntrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b.s).to.equal(2), + span => expect(span.b.u).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('multi'), + span => expect(span.data.redis.subCommands).to.deep.equal(['hset', 'hget']) + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(multiSpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('exec') + ]); + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(multiSpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hset') + ]); + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(multiSpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hget') + ]); + } else { + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(writeEntrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('exec') + ]); + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(writeEntrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hset') + ]); + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(writeEntrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hget') + ]); + } }) ) )); @@ -434,70 +489,121 @@ function checkConnection(span, setupType) { span => expect(span.data.http.method).to.equal('GET') ]); - expect(spans).to.have.lengthOf(5); - - const multiSpan = expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(writeEntrySpan.t), - span => expect(span.p).to.equal(writeEntrySpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(2), - span => expect(span.b.s).to.equal(2), - span => expect(span.b.u).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('multi'), - span => expect(span.data.redis.subCommands).to.deep.equal(['hset', 'hget']), - span => expect(span.data.redis.error).to.be.a('string') - ]); - - expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(writeEntrySpan.t), - span => expect(span.p).to.equal(multiSpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(1), - span => expect(span.b).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('exec') - ]); - - expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(writeEntrySpan.t), - span => expect(span.p).to.equal(multiSpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.b).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('hset') - ]); - - expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(writeEntrySpan.t), - span => expect(span.p).to.equal(multiSpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(1), - span => expect(span.b).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('hget') - ]); + // NOTE: no multi span for cluster, see https://jsw.ibm.com/browse/INSTA-14540 + if (setupType === 'cluster') { + expect(spans).to.have.lengthOf(4); + } else { + expect(spans).to.have.lengthOf(5); + } + + if (setupType !== 'cluster') { + const multiSpan = expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(writeEntrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(2), + span => expect(span.b.s).to.equal(2), + span => expect(span.b.u).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('multi'), + span => expect(span.data.redis.subCommands).to.deep.equal(['hset', 'hget']), + span => expect(span.data.redis.error).to.be.a('string') + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(multiSpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(1), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('exec') + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(multiSpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hset') + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(multiSpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(1), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hget') + ]); + } else { + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(writeEntrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hset') + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(writeEntrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(1), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hget') + ]); + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(writeEntrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(1), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('exec') + ]); + } }) ) )); @@ -516,84 +622,151 @@ function checkConnection(span, setupType) { span => expect(span.data.http.method).to.equal('POST') ]); - expect(spans).to.have.lengthOf(6); - - const multiSpan = expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(entrySpan.t), - span => expect(span.p).to.equal(entrySpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.b.s).to.equal(2), - span => expect(span.b.u).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('multi'), - span => expect(span.data.redis.subCommands).to.deep.equal(['hset', 'hget']) - ]); - - expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(entrySpan.t), - span => expect(span.p).to.equal(multiSpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.b).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('exec') - ]); - - expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(entrySpan.t), - span => expect(span.p).to.equal(multiSpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.b).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('hget') - ]); - - expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(entrySpan.t), - span => expect(span.p).to.equal(multiSpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.b).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('hset') - ]); - - expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(entrySpan.t), - span => expect(span.p).to.equal(entrySpan.s), - span => expect(span.n).to.equal('node.http.client'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.data.http.method).to.equal('GET'), - span => expect(span.data.http.url).to.match(/http:\/\/127\.0\.0\.1:/), - span => expect(span.data.http.status).to.equal(200) - ]); + // NOTE: no multi span for cluster, see https://jsw.ibm.com/browse/INSTA-14540 + if (setupType === 'cluster') { + expect(spans).to.have.lengthOf(5); + } else { + expect(spans).to.have.lengthOf(6); + } + + if (setupType !== 'cluster') { + const multiSpan = expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(entrySpan.t), + span => expect(span.p).to.equal(entrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b.s).to.equal(2), + span => expect(span.b.u).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('multi'), + span => expect(span.data.redis.subCommands).to.deep.equal(['hset', 'hget']) + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(entrySpan.t), + span => expect(span.p).to.equal(multiSpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('exec') + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(entrySpan.t), + span => expect(span.p).to.equal(multiSpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hget') + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(entrySpan.t), + span => expect(span.p).to.equal(multiSpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hset') + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(entrySpan.t), + span => expect(span.p).to.equal(entrySpan.s), + span => expect(span.n).to.equal('node.http.client'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.data.http.method).to.equal('GET'), + span => expect(span.data.http.url).to.match(/http:\/\/127\.0\.0\.1:/), + span => expect(span.data.http.status).to.equal(200) + ]); + } else { + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(entrySpan.t), + span => expect(span.p).to.equal(entrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('exec') + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(entrySpan.t), + span => expect(span.p).to.equal(entrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hget') + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(entrySpan.t), + span => expect(span.p).to.equal(entrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hset') + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(entrySpan.t), + span => expect(span.p).to.equal(entrySpan.s), + span => expect(span.n).to.equal('node.http.client'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.data.http.method).to.equal('GET'), + span => expect(span.data.http.url).to.match(/http:\/\/127\.0\.0\.1:/), + span => expect(span.data.http.status).to.equal(200) + ]); + } }) ) )); @@ -612,58 +785,109 @@ function checkConnection(span, setupType) { span => expect(span.data.http.method).to.equal('GET') ]); - // 1 x entry - // 1 x multi containing the sub commands - // NO exec span - // 3 x sub commands - // TODO: https://jsw.ibm.com/browse/INSTA-14540 - expect(spans).to.have.lengthOf(5); - - const pipelineSpan = expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(writeEntrySpan.t), - span => expect(span.p).to.equal(writeEntrySpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.b.s).to.equal(3), - span => expect(span.b.u).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('pipeline'), - span => expect(span.data.redis.subCommands).to.deep.equal(['hset', 'hset', 'hget']) - ]); - - expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(writeEntrySpan.t), - span => expect(span.p).to.equal(pipelineSpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.b).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('hget') - ]); - expectExactlyNMatching(spans, 2, [ - span => expect(span.t).to.equal(writeEntrySpan.t), - span => expect(span.p).to.equal(pipelineSpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.b).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('hset') - ]); + // NOTE: no pipeline span for cluster, see https://jsw.ibm.com/browse/INSTA-14540 + if (setupType === 'cluster') { + expect(spans).to.have.lengthOf(4); + } else { + // 1 x entry + // 1 x pipeline containing the sub commands + // NO exec span + // 3 x sub commands + expect(spans).to.have.lengthOf(5); + } + + if (setupType !== 'cluster') { + const pipelineSpan = expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(writeEntrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b.s).to.equal(3), + span => expect(span.b.u).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('pipeline'), + span => expect(span.data.redis.subCommands).to.deep.equal(['hset', 'hset', 'hget']) + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(pipelineSpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hget') + ]); + expectExactlyNMatching(spans, 2, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(pipelineSpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hset') + ]); + } else { + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(writeEntrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hget') + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(writeEntrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hset') + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(writeEntrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hset') + ]); + } }) ) )); @@ -682,70 +906,122 @@ function checkConnection(span, setupType) { span => expect(span.data.http.method).to.equal('GET') ]); - expect(spans).to.have.lengthOf(5); - - const pipelineSpan = expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(writeEntrySpan.t), - span => expect(span.p).to.equal(writeEntrySpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(1), - span => expect(span.b.s).to.equal(3), - span => expect(span.b.u).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('pipeline'), - span => expect(span.data.redis.subCommands).to.deep.equal(['hset', 'hset', 'hget']), - span => expect(span.data.redis.error).to.be.a('string') - ]); - - expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(writeEntrySpan.t), - span => expect(span.p).to.equal(pipelineSpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(1), - span => expect(span.b).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('hset'), - span => expect(span.data.redis.error).to.exist - ]); - - expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(writeEntrySpan.t), - span => expect(span.p).to.equal(pipelineSpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.b).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('hset') - ]); - expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(writeEntrySpan.t), - span => expect(span.p).to.equal(pipelineSpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.b).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('hget') - ]); + // NOTE: no pipeline span for cluster, see https://jsw.ibm.com/browse/INSTA-14540 + if (setupType === 'cluster') { + expect(spans).to.have.lengthOf(4); + } else { + expect(spans).to.have.lengthOf(5); + } + + if (setupType !== 'cluster') { + const pipelineSpan = expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(writeEntrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(1), + span => expect(span.b.s).to.equal(3), + span => expect(span.b.u).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('pipeline'), + span => expect(span.data.redis.subCommands).to.deep.equal(['hset', 'hset', 'hget']), + span => expect(span.data.redis.error).to.be.a('string') + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(pipelineSpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(1), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hset'), + span => expect(span.data.redis.error).to.exist + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(pipelineSpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hset') + ]); + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(pipelineSpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hget') + ]); + } else { + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(writeEntrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(1), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hset') + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(writeEntrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hget') + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(writeEntrySpan.t), + span => expect(span.p).to.equal(writeEntrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hset') + ]); + } }) ) )); @@ -764,68 +1040,119 @@ function checkConnection(span, setupType) { span => expect(span.data.http.method).to.equal('POST') ]); - expect(spans).to.have.lengthOf(5); - - const pipelineSpan = expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(entrySpan.t), - span => expect(span.p).to.equal(entrySpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.b.s).to.equal(2), - span => expect(span.b.u).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('pipeline'), - span => expect(span.data.redis.subCommands).to.deep.equal(['hset', 'hget']) - ]); - - expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(entrySpan.t), - span => expect(span.p).to.equal(pipelineSpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.b).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('hget') - ]); - expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(entrySpan.t), - span => expect(span.p).to.equal(pipelineSpan.s), - span => expect(span.n).to.equal('redis'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.b).to.not.exist, - span => checkConnection(span, setupType), - span => expect(span.data.redis.command).to.equal('hset') - ]); - - expectAtLeastOneMatching(spans, [ - span => expect(span.t).to.equal(entrySpan.t), - span => expect(span.p).to.equal(entrySpan.s), - span => expect(span.n).to.equal('node.http.client'), - span => expect(span.k).to.equal(constants.EXIT), - span => expect(span.f.e).to.equal(String(controls.getPid())), - span => expect(span.f.h).to.equal('agent-stub-uuid'), - span => expect(span.async).to.not.exist, - span => expect(span.error).to.not.exist, - span => expect(span.ec).to.equal(0), - span => expect(span.data.http.method).to.equal('GET'), - span => expect(span.data.http.url).to.match(/http:\/\/127\.0\.0\.1:/), - span => expect(span.data.http.status).to.equal(200) - ]); + // NOTE: no pipeline span for cluster, see https://jsw.ibm.com/browse/INSTA-14540 + if (setupType === 'cluster') { + expect(spans).to.have.lengthOf(4); + } else { + expect(spans).to.have.lengthOf(5); + } + + if (setupType !== 'cluster') { + const pipelineSpan = expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(entrySpan.t), + span => expect(span.p).to.equal(entrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b.s).to.equal(2), + span => expect(span.b.u).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('pipeline'), + span => expect(span.data.redis.subCommands).to.deep.equal(['hset', 'hget']) + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(entrySpan.t), + span => expect(span.p).to.equal(pipelineSpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hget') + ]); + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(entrySpan.t), + span => expect(span.p).to.equal(pipelineSpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hset') + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(entrySpan.t), + span => expect(span.p).to.equal(entrySpan.s), + span => expect(span.n).to.equal('node.http.client'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.data.http.method).to.equal('GET'), + span => expect(span.data.http.url).to.match(/http:\/\/127\.0\.0\.1:/), + span => expect(span.data.http.status).to.equal(200) + ]); + } else { + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(entrySpan.t), + span => expect(span.p).to.equal(entrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hget') + ]); + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(entrySpan.t), + span => expect(span.p).to.equal(entrySpan.s), + span => expect(span.n).to.equal('redis'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.b).to.not.exist, + span => checkConnection(span, setupType), + span => expect(span.data.redis.command).to.equal('hset') + ]); + + expectAtLeastOneMatching(spans, [ + span => expect(span.t).to.equal(entrySpan.t), + span => expect(span.p).to.equal(entrySpan.s), + span => expect(span.n).to.equal('node.http.client'), + span => expect(span.k).to.equal(constants.EXIT), + span => expect(span.f.e).to.equal(String(controls.getPid())), + span => expect(span.f.h).to.equal('agent-stub-uuid'), + span => expect(span.async).to.not.exist, + span => expect(span.error).to.not.exist, + span => expect(span.ec).to.equal(0), + span => expect(span.data.http.method).to.equal('GET'), + span => expect(span.data.http.url).to.match(/http:\/\/127\.0\.0\.1:/), + span => expect(span.data.http.status).to.equal(200) + ]); + } }) ) )); diff --git a/packages/core/src/tracing/instrumentation/database/ioredis.js b/packages/core/src/tracing/instrumentation/database/ioredis.js index 5e91aa43e1..03f9623dd9 100644 --- a/packages/core/src/tracing/instrumentation/database/ioredis.js +++ b/packages/core/src/tracing/instrumentation/database/ioredis.js @@ -29,37 +29,16 @@ exports.init = function init() { hook.onModuleLoad('ioredis', instrument); }; -let clusterConnectionString; - function instrument(ioredis) { - class InstanaClusterClass extends ioredis.Cluster { - constructor() { - super(...arguments); - - try { - clusterConnectionString = this.startupNodes.map(node => `${node.host}:${node.port}`).join(','); - } catch (e) { - // ignore - } - } - } - - Object.defineProperty(ioredis, 'Cluster', { - value: InstanaClusterClass, - writable: false, - configurable: false, - enumerable: true - }); - - // We cannot register `ioredis.Cluster.prototype.sendCommand` otherwise we produce two spans for the same command. - // Because `ioredis.prototype.sendCommand` is triggerd when using a cluster, but `client.isCluster` is false. - // Thats why we override the Cluster Class and extract the connection string. shimmer.wrap(ioredis.prototype, 'sendCommand', instrumentSendCommand); shimmer.wrap(ioredis.prototype, 'multi', instrumentMultiCommand); shimmer.wrap(ioredis.prototype, 'pipeline', instrumentPipelineCommand); - shimmer.wrap(ioredis.Cluster.prototype, 'multi', instrumentMultiCommand); - shimmer.wrap(ioredis.Cluster.prototype, 'pipeline', instrumentPipelineCommand); + // TODO: https://jsw.ibm.com/browse/INSTA-14540 + // We currently have no multi/pipeline spans for clusters. + // shimmer.wrap(ioredis.Cluster.prototype, 'sendCommand', instrumentSendCommand); + // shimmer.wrap(ioredis.Cluster.prototype, 'multi', instrumentMultiCommand); + // shimmer.wrap(ioredis.Cluster.prototype, 'pipeline', instrumentPipelineCommand); } function instrumentSendCommand(original) { @@ -96,8 +75,15 @@ function instrumentSendCommand(original) { return cls.ns.runAndReturn(() => { const span = cls.startSpan(exports.spanName, constants.EXIT); span.stack = tracingUtil.getStackTrace(wrappedInternalSendCommand); + + const connection = `${client.options.host}:${client.options.port}`; + + // TODO: https://jsw.ibm.com/browse/INSTA-14540 + // if (client.isCluster) { + // connection = client.startupNodes.map(node => `${node.host}:${node.port}`).join(','); + span.data.redis = { - connection: clusterConnectionString || `${client.options.host}:${client.options.port}`, + connection, command: command.name.toLowerCase() }; @@ -147,14 +133,11 @@ function instrumentMultiOrPipelineCommand(commandName, original) { return original.apply(this, arguments); } - let connection; + const connection = `${client.options.host}:${client.options.port}`; - // NOTE: here it works because we register the instrumentation on the cluster prototype - if (client.isCluster) { - connection = clusterConnectionString; - } else { - connection = `${client.options.host}:${client.options.port}`; - } + // TODO: https://jsw.ibm.com/browse/INSTA-14540 + // if (client.isCluster) { + // connection = client.startupNodes.map(node => `${node.host}:${node.port}`).join(','); // create a new cls context parent to track the multi/pipeline child calls const clsContextForMultiOrPipeline = cls.ns.createContext();