Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ test('ioredis GET emits an http.server transaction containing a db.redis child s
expect(redisSpan).toBeDefined();
// ioredis publishes lowercase command names; node-redis publishes uppercase.
expect(redisSpan!.description).toBe('redis-get');
expect(redisSpan!.data?.['db.system']).toBe('redis');
expect(redisSpan!.data?.['db.statement']).toBe('get iocache:user:42');
expect(redisSpan!.data?.['db.system.name']).toBe('redis');
expect(redisSpan!.data?.['db.query.text']).toBe('get iocache:user:42');
});

test('ioredis SET then GET emit two db.redis child spans on the same transaction', async ({ baseURL }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ test('GET command emits an http.server transaction containing a db.redis child s
const redisSpan = transaction.spans!.find(span => span.op === 'db.redis');
expect(redisSpan).toBeDefined();
expect(redisSpan!.description).toBe('redis-GET');
expect(redisSpan!.data?.['db.system']).toBe('redis');
expect(redisSpan!.data?.['db.system.name']).toBe('redis');
// Statement omits the value; for GET the only allowed arg is the key.
expect(redisSpan!.data?.['db.statement']).toBe('GET cache:user:42');
expect(redisSpan!.data?.['net.peer.port']).toBe(6379);
expect(redisSpan!.data?.['db.query.text']).toBe('GET cache:user:42');
expect(redisSpan!.data?.['server.port']).toBe(6379);
});

test('SET then GET emit two db.redis child spans on the same transaction', async ({ baseURL }) => {
Expand Down Expand Up @@ -65,7 +65,7 @@ test('MULTI batch emits a PIPELINE/MULTI batch span', async ({ baseURL }) => {
const batchSpan = transaction.spans!.find(span => span.description === 'MULTI' || span.description === 'PIPELINE');
expect(batchSpan).toBeDefined();
expect(batchSpan!.op).toBe('db.redis');
expect(batchSpan!.data?.['db.system']).toBe('redis');
expect(batchSpan!.data?.['db.system.name']).toBe('redis');
});

test('shut down redis client', async ({ baseURL }) => {
Expand Down
16 changes: 8 additions & 8 deletions packages/deno/test/deno-redis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ Deno.test('denoRedisIntegration: node-redis:command channel produces a db.redis
const redisSpan = parent.spans?.find(s => s.op === 'db.redis');
assertExists(redisSpan, `expected a db.redis child span, got ops: ${parent.spans?.map(s => s.op).join(', ')}`);
assertEquals(redisSpan!.description, 'redis-GET');
assertEquals(redisSpan!.data?.['db.system'], 'redis');
assertEquals(redisSpan!.data?.['db.statement'], 'GET cache:key');
assertEquals(redisSpan!.data?.['net.peer.name'], '127.0.0.1');
assertEquals(redisSpan!.data?.['net.peer.port'], 6379);
assertEquals(redisSpan!.data?.['db.system.name'], 'redis');
assertEquals(redisSpan!.data?.['db.query.text'], 'GET cache:key');
assertEquals(redisSpan!.data?.['server.address'], '127.0.0.1');
assertEquals(redisSpan!.data?.['server.port'], 6379);
});

Deno.test('denoRedisIntegration: errors on the command channel set span status', async () => {
Expand Down Expand Up @@ -165,8 +165,8 @@ Deno.test('denoRedisIntegration: ioredis:command channel produces a db.redis chi
const redisSpan = parent.spans?.find(s => s.op === 'db.redis');
assertExists(redisSpan, `expected a db.redis child span, got ops: ${parent.spans?.map(s => s.op).join(', ')}`);
assertEquals(redisSpan!.description, 'redis-get');
assertEquals(redisSpan!.data?.['db.system'], 'redis');
assertEquals(redisSpan!.data?.['db.statement'], 'get cache:key');
assertEquals(redisSpan!.data?.['net.peer.name'], '127.0.0.1');
assertEquals(redisSpan!.data?.['net.peer.port'], 6379);
assertEquals(redisSpan!.data?.['db.system.name'], 'redis');
assertEquals(redisSpan!.data?.['db.query.text'], 'get cache:key');
assertEquals(redisSpan!.data?.['server.address'], '127.0.0.1');
assertEquals(redisSpan!.data?.['server.port'], 6379);
});
43 changes: 24 additions & 19 deletions packages/server-utils/src/redis/redis-dc-subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ export const IOREDIS_DC_CHANNEL_CONNECT = 'ioredis:connect';

const ORIGIN = 'auto.db.redis.diagnostic_channel';

// Inlined semconv attribute keys — these are plain strings, no need to depend
// on @opentelemetry/semantic-conventions for them.
const ATTR_DB_STATEMENT = 'db.statement';
const ATTR_DB_SYSTEM = 'db.system';
const ATTR_NET_PEER_NAME = 'net.peer.name';
const ATTR_NET_PEER_PORT = 'net.peer.port';
const DB_SYSTEM_VALUE_REDIS = 'redis';
// Inlined stable semconv attribute keys — these are plain strings, no need to
// depend on @opentelemetry/semantic-conventions for them. We use the stable
// OTel names (matching `@sentry/core`'s postgresjs integration) rather than the
// deprecated `db.statement`/`db.system`/`net.peer.*` forms.
const ATTR_DB_QUERY_TEXT = 'db.query.text';
const ATTR_DB_SYSTEM_NAME = 'db.system.name';
const ATTR_DB_OPERATION_BATCH_SIZE = 'db.operation.batch.size';
const ATTR_SERVER_ADDRESS = 'server.address';
const ATTR_SERVER_PORT = 'server.port';
const DB_SYSTEM_NAME_VALUE_REDIS = 'redis';

const NOOP = (): void => {};

Expand All @@ -37,7 +40,7 @@ const NOOP = (): void => {};
* `sanitizeArgs` in @redis/client) using the OTel `redis-common` rules. The
* arg array is `[<command>, <safe arg>, ..., '?', ...]` — `?` replaces any
* value the library considers sensitive. Subscribers can emit `args` directly
* as `db.statement` without further serialization.
* as `db.query.text` without further serialization.
*/
export interface RedisCommandData {
command: string;
Expand Down Expand Up @@ -203,10 +206,10 @@ function setupCommandChannel<T extends RedisCommandData | IORedisCommandData>(
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'db.redis',
[ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_REDIS,
[ATTR_DB_STATEMENT]: statement,
...(data.serverAddress != null ? { [ATTR_NET_PEER_NAME]: data.serverAddress } : {}),
...(data.serverPort != null ? { [ATTR_NET_PEER_PORT]: data.serverPort } : {}),
[ATTR_DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_REDIS,
[ATTR_DB_QUERY_TEXT]: statement,
Comment thread
cursor[bot] marked this conversation as resolved.
...(data.serverAddress != null ? { [ATTR_SERVER_ADDRESS]: data.serverAddress } : {}),
...(data.serverPort != null ? { [ATTR_SERVER_PORT]: data.serverPort } : {}),
},
},
span => span,
Expand Down Expand Up @@ -247,10 +250,12 @@ function setupBatchChannel(
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'db.redis',
[ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_REDIS,
...(data.batchSize != null ? { 'db.redis.batch_size': data.batchSize } : {}),
...(data.serverAddress != null ? { [ATTR_NET_PEER_NAME]: data.serverAddress } : {}),
...(data.serverPort != null ? { [ATTR_NET_PEER_PORT]: data.serverPort } : {}),
[ATTR_DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_REDIS,
// should only include batch size greater than 1,
// or else it isn't properly considered a "batch"
...(Number(data.batchSize) > 1 ? { [ATTR_DB_OPERATION_BATCH_SIZE]: data.batchSize } : {}),
...(data.serverAddress != null ? { [ATTR_SERVER_ADDRESS]: data.serverAddress } : {}),
...(data.serverPort != null ? { [ATTR_SERVER_PORT]: data.serverPort } : {}),
},
},
span => span,
Comment on lines 251 to 261
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Node integration tests for redis-dc and ioredis-dc assert old attribute names (db.system, db.statement), which will cause test failures against the updated subscriber code.
Severity: HIGH

Suggested Fix

Update the assertions in dev-packages/node-integration-tests/suites/tracing/redis-dc/test.ts and dev-packages/node-integration-tests/suites/tracing/ioredis-dc/test.ts to use the new attribute names, db.system.name and db.query.text, instead of db.system and db.statement.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/server-utils/src/redis/redis-dc-subscriber.ts#L250-L261

Potential issue: The subscriber code in `redis-dc-subscriber.ts` was updated to emit
spans with the new attribute names `db.system.name` and `db.query.text`, replacing
`db.system` and `db.statement`. However, the corresponding node integration tests in
`dev-packages/node-integration-tests/suites/tracing/redis-dc/test.ts` and
`dev-packages/node-integration-tests/suites/tracing/ioredis-dc/test.ts` were not
updated. These tests continue to assert the presence of the old attribute names, which
will cause them to fail when run against the new code, breaking the CI pipeline.

Also affects:

  • dev-packages/node-integration-tests/suites/tracing/redis-dc/test.ts
  • dev-packages/node-integration-tests/suites/tracing/ioredis-dc/test.ts

Did we get this right? 👍 / 👎 to inform future reviews.

Expand Down Expand Up @@ -283,9 +288,9 @@ function setupConnectChannel(tracingChannel: RedisTracingChannelFactory, channel
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'db.redis.connect',
[ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_REDIS,
...(data.serverAddress != null ? { [ATTR_NET_PEER_NAME]: data.serverAddress } : {}),
...(data.serverPort != null ? { [ATTR_NET_PEER_PORT]: data.serverPort } : {}),
[ATTR_DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_REDIS,
...(data.serverAddress != null ? { [ATTR_SERVER_ADDRESS]: data.serverAddress } : {}),
...(data.serverPort != null ? { [ATTR_SERVER_PORT]: data.serverPort } : {}),
},
},
span => span,
Expand Down
Loading