Skip to content

Commit

Permalink
feat(ioredis): only serialize first argument in redis command
Browse files Browse the repository at this point in the history
  • Loading branch information
aptomaKetil committed Jun 8, 2022
1 parent 3e2f9c5 commit 6f1528e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
10 changes: 6 additions & 4 deletions plugins/node/opentelemetry-instrumentation-ioredis/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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), () => {
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -663,7 +661,7 @@ describe('ioredis', () => {
SpanKind.CLIENT,
{
...DEFAULT_ATTRIBUTES,
[SemanticAttributes.DB_STATEMENT]: `set ${testKeyName} data`,
[SemanticAttributes.DB_STATEMENT]: `set ${testKeyName}`,
},
[],
unsetStatus
Expand Down

0 comments on commit 6f1528e

Please sign in to comment.