From 6f1528ec083bbbf012f9052ff4b9b45c4b678a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ketil=20=C3=98vreb=C3=B8?= Date: Wed, 8 Jun 2022 16:20:40 +0200 Subject: [PATCH] feat(ioredis): only serialize first argument in redis command --- .../src/utils.ts | 10 ++++++---- .../test/ioredis.test.ts | 16 +++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/src/utils.ts b/plugins/node/opentelemetry-instrumentation-ioredis/src/utils.ts index dc52e6e4a8..643b7801ab 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-ioredis/src/utils.ts @@ -34,7 +34,9 @@ export const endSpan = ( export const defaultDbStatementSerializer: DbStatementSerializer = ( cmdName, cmdArgs -) => - Array.isArray(cmdArgs) && cmdArgs.length - ? `${cmdName} ${cmdArgs.join(' ')}` - : cmdName; +) => { + if (Array.isArray(cmdArgs) && cmdArgs.length) { + return `${cmdName} ${cmdArgs[0]}`; + } + return cmdName; +} diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts b/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts index b57adcb76b..7549ad581b 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts +++ b/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts @@ -241,9 +241,7 @@ describe('ioredis', () => { it(`should create a child span for cb style ${command.description}`, done => { const attributes = { ...DEFAULT_ATTRIBUTES, - [SemanticAttributes.DB_STATEMENT]: `${ - command.name - } ${command.args.join(' ')}`, + [SemanticAttributes.DB_STATEMENT]: `${command.name} ${command.args[0]}`, }; const span = provider .getTracer('ioredis-test') @@ -273,7 +271,7 @@ describe('ioredis', () => { it('should create a child span for hset promise', async () => { const attributes = { ...DEFAULT_ATTRIBUTES, - [SemanticAttributes.DB_STATEMENT]: `hset ${hashKeyName} random random`, + [SemanticAttributes.DB_STATEMENT]: `hset ${hashKeyName}`, }; const span = provider.getTracer('ioredis-test').startSpan('test span'); await context.with(trace.setSpan(context.active(), span), async () => { @@ -335,7 +333,7 @@ describe('ioredis', () => { it('should create a child span for streamify scanning', done => { const attributes = { ...DEFAULT_ATTRIBUTES, - [SemanticAttributes.DB_STATEMENT]: 'scan 0 MATCH test-* COUNT 1000', + [SemanticAttributes.DB_STATEMENT]: 'scan 0', }; const span = provider.getTracer('ioredis-test').startSpan('test span'); context.with(trace.setSpan(context.active(), span), () => { @@ -411,7 +409,7 @@ describe('ioredis', () => { const attributes = { ...DEFAULT_ATTRIBUTES, - [SemanticAttributes.DB_STATEMENT]: 'subscribe news music', + [SemanticAttributes.DB_STATEMENT]: 'subscribe news', }; testUtils.assertSpan( endedSpans[4], @@ -466,7 +464,7 @@ describe('ioredis', () => { it('should create a child span for pipeline', done => { const attributes = { ...DEFAULT_ATTRIBUTES, - [SemanticAttributes.DB_STATEMENT]: 'set foo bar', + [SemanticAttributes.DB_STATEMENT]: 'set foo', }; const span = provider.getTracer('ioredis-test').startSpan('test span'); @@ -563,7 +561,7 @@ describe('ioredis', () => { const attributes = { ...DEFAULT_ATTRIBUTES, - [SemanticAttributes.DB_STATEMENT]: `evalsha bfbf458525d6a0b19200bfd6db3af481156b367b 1 ${testKeyName}`, + [SemanticAttributes.DB_STATEMENT]: `evalsha bfbf458525d6a0b19200bfd6db3af481156b367b`, }; const span = provider.getTracer('ioredis-test').startSpan('test span'); @@ -663,7 +661,7 @@ describe('ioredis', () => { SpanKind.CLIENT, { ...DEFAULT_ATTRIBUTES, - [SemanticAttributes.DB_STATEMENT]: `set ${testKeyName} data`, + [SemanticAttributes.DB_STATEMENT]: `set ${testKeyName}`, }, [], unsetStatus