diff --git a/package.json b/package.json index 449bf79c5e..afce606580 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "codecov:ci:changed": "lerna run codecov --since origin/main --parallel", "codecov:browser": "lerna run codecov:browser", "changelog": "lerna-changelog", + "lerna:link": "lerna link", "lint": "lerna run lint", "lint:fix": "lerna run lint:fix", "lint:examples": "eslint ./examples/**/*.js", diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/.tav.yml b/plugins/node/opentelemetry-instrumentation-ioredis/.tav.yml new file mode 100644 index 0000000000..b7f91b0bef --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-ioredis/.tav.yml @@ -0,0 +1,7 @@ +ioredis: + # Ignoring v4.19.0. Tests never ends. Caused by https://github.com/luin/ioredis/pull/1219 + versions: ">1 < 4.19.0 || > 4.19.0 < 5" + commands: npm run test + + # Fix missing `test-utils` package + pretest: npm run --prefix ../../../ lerna:link diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/package.json b/plugins/node/opentelemetry-instrumentation-ioredis/package.json index b96308056c..d1220af746 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/package.json +++ b/plugins/node/opentelemetry-instrumentation-ioredis/package.json @@ -9,6 +9,8 @@ "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", "test:debug": "cross-env RUN_REDIS_TESTS_LOCAL=true ts-mocha --inspect-brk --no-timeouts -p tsconfig.json 'test/**/*.test.ts'", "test:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test", + "test-all-versions": "tav", + "test-all-versions:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test-all-versions", "tdd": "npm run test -- --watch-extensions ts --watch", "clean": "rimraf build/*", "lint": "eslint . --ext .ts", @@ -62,6 +64,7 @@ "mocha": "7.2.0", "nyc": "15.1.0", "rimraf": "3.0.2", + "test-all-versions": "5.0.1", "ts-mocha": "8.0.0", "typescript": "4.3.5" }, diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts b/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts index 6dfb4e63b0..8605b6bab6 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts +++ b/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts @@ -387,7 +387,7 @@ describe('ioredis', () => { assert.strictEqual(endedSpans.length, 10); span.end(); assert.strictEqual(endedSpans.length, 11); - const spanNames = [ + const expectedSpanNames = [ 'connect', 'info', 'connect', @@ -400,11 +400,12 @@ describe('ioredis', () => { 'quit', 'test span', ]; - let i = 0; - while (i < 11) { - assert.strictEqual(endedSpans[i].name, spanNames[i]); - i++; - } + + const actualSpanNames = endedSpans.map(s => s.name); + assert.deepStrictEqual( + actualSpanNames.sort(), + expectedSpanNames.sort() + ); const attributes = { ...DEFAULT_ATTRIBUTES, @@ -424,74 +425,6 @@ describe('ioredis', () => { }); }); - it('should create a child span for lua', done => { - const attributes = { - ...DEFAULT_ATTRIBUTES, - [SemanticAttributes.DB_STATEMENT]: `evalsha bfbf458525d6a0b19200bfd6db3af481156b367b 1 ${testKeyName}`, - }; - - const span = provider.getTracer('ioredis-test').startSpan('test span'); - context.with(trace.setSpan(context.active(), span), () => { - // This will define a command echo: - client.defineCommand('echo', { - numberOfKeys: 1, - lua: 'return {KEYS[1],ARGV[1]}', - }); - // Now `echo` can be used just like any other ordinary command, - // and ioredis will try to use `EVALSHA` internally when possible for better performance. - client.echo(testKeyName, (err, result) => { - assert.ifError(err); - - span.end(); - const endedSpans = memoryExporter.getFinishedSpans(); - const evalshaSpan = endedSpans[0]; - // the script may be already cached on server therefore we get either 2 or 3 spans - if (endedSpans.length === 3) { - assert.strictEqual(endedSpans[2].name, 'test span'); - assert.strictEqual(endedSpans[1].name, 'eval'); - assert.strictEqual(endedSpans[0].name, 'evalsha'); - // in this case, server returns NOSCRIPT error for evalsha, - // telling the client to use EVAL instead - sanitizeEventForAssertion(evalshaSpan); - testUtils.assertSpan( - evalshaSpan, - SpanKind.CLIENT, - attributes, - [ - { - attributes: { - [SemanticAttributes.EXCEPTION_MESSAGE]: - 'NOSCRIPT No matching script. Please use EVAL.', - [SemanticAttributes.EXCEPTION_STACKTRACE]: - predictableStackTrace, - [SemanticAttributes.EXCEPTION_TYPE]: 'ReplyError', - }, - name: 'exception', - time: [0, 0], - }, - ], - { - code: SpanStatusCode.ERROR, - } - ); - } else { - assert.strictEqual(endedSpans.length, 2); - assert.strictEqual(endedSpans[1].name, 'test span'); - assert.strictEqual(endedSpans[0].name, 'evalsha'); - testUtils.assertSpan( - evalshaSpan, - SpanKind.CLIENT, - attributes, - [], - unsetStatus - ); - } - testUtils.assertPropagation(evalshaSpan, span); - done(); - }); - }); - }); - it('should create a child span for multi/transaction', done => { const attributes = { ...DEFAULT_ATTRIBUTES, @@ -619,11 +552,90 @@ describe('ioredis', () => { } }); }); + + it('should create a child span for lua', done => { + instrumentation = new IORedisInstrumentation({ + requireParentSpan: false, + }); + instrumentation.setTracerProvider(provider); + require('ioredis'); + + const attributes = { + ...DEFAULT_ATTRIBUTES, + [SemanticAttributes.DB_STATEMENT]: `evalsha bfbf458525d6a0b19200bfd6db3af481156b367b 1 ${testKeyName}`, + }; + + const span = provider.getTracer('ioredis-test').startSpan('test span'); + context.with(trace.setSpan(context.active(), span), () => { + // This will define a command echo: + client.defineCommand('echo', { + numberOfKeys: 1, + lua: 'return {KEYS[1],ARGV[1]}', + }); + // Now `echo` can be used just like any other ordinary command, + // and ioredis will try to use `EVALSHA` internally when possible for better performance. + client.echo(testKeyName, (err, result) => { + assert.ifError(err); + + span.end(); + const endedSpans = memoryExporter.getFinishedSpans(); + const evalshaSpan = endedSpans[0]; + // the script may be already cached on server therefore we get either 2 or 3 spans + if (endedSpans.length === 3) { + assert.strictEqual(endedSpans[2].name, 'test span'); + assert.strictEqual(endedSpans[1].name, 'eval'); + assert.strictEqual(endedSpans[0].name, 'evalsha'); + // in this case, server returns NOSCRIPT error for evalsha, + // telling the client to use EVAL instead + sanitizeEventForAssertion(evalshaSpan); + testUtils.assertSpan( + evalshaSpan, + SpanKind.CLIENT, + attributes, + [ + { + attributes: { + [SemanticAttributes.EXCEPTION_MESSAGE]: + 'NOSCRIPT No matching script. Please use EVAL.', + [SemanticAttributes.EXCEPTION_STACKTRACE]: + predictableStackTrace, + [SemanticAttributes.EXCEPTION_TYPE]: 'ReplyError', + }, + name: 'exception', + time: [0, 0], + }, + ], + { + code: SpanStatusCode.ERROR, + } + ); + } else { + assert.strictEqual(endedSpans.length, 2); + assert.strictEqual(endedSpans[1].name, 'test span'); + assert.strictEqual(endedSpans[0].name, 'evalsha'); + testUtils.assertSpan( + evalshaSpan, + SpanKind.CLIENT, + attributes, + [], + unsetStatus + ); + } + testUtils.assertPropagation(evalshaSpan, span); + done(); + }); + }); + }); }); describe('Instrumenting without parent span', () => { before(() => { instrumentation.disable(); + instrumentation = new IORedisInstrumentation({ + requireParentSpan: true, + }); + instrumentation.setTracerProvider(provider); + require('ioredis'); instrumentation.enable(); }); it('should not create child span', async () => { diff --git a/plugins/node/opentelemetry-instrumentation-redis/.tav.yml b/plugins/node/opentelemetry-instrumentation-redis/.tav.yml new file mode 100644 index 0000000000..9c8d1f239e --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-redis/.tav.yml @@ -0,0 +1,6 @@ +redis: + versions: ^2.6.0 || ^3.0.0 + commands: npm run test + + # Fix missing `test-utils` package + pretest: npm run --prefix ../../../ lerna:link diff --git a/plugins/node/opentelemetry-instrumentation-redis/package.json b/plugins/node/opentelemetry-instrumentation-redis/package.json index 396ad1184a..52f8193b22 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/package.json +++ b/plugins/node/opentelemetry-instrumentation-redis/package.json @@ -9,6 +9,8 @@ "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", "test:debug": "cross-env RUN_REDIS_TESTS_LOCAL=true ts-mocha --inspect-brk --no-timeouts -p tsconfig.json 'test/**/*.test.ts'", "test:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test", + "test-all-versions": "tav", + "test-all-versions:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test-all-versions", "tdd": "npm run test -- --watch-extensions ts --watch", "clean": "rimraf build/*", "lint": "eslint . --ext .ts", @@ -61,6 +63,7 @@ "nyc": "15.1.0", "redis": "3.1.2", "rimraf": "3.0.2", + "test-all-versions": "5.0.1", "ts-mocha": "8.0.0", "typescript": "4.3.5" },