Skip to content
Draft
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 @@ -2,7 +2,7 @@ import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
traceLifecycle: 'static',
traceLifecycle: process.env.STREAMED === 'true' ? 'stream' : 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { afterAll, expect } from 'vitest';
import { SENTRY_TRACE_LIFECYCLE } from '@sentry/conventions/attributes';
import type { SerializedStreamedSpanContainer } from '@sentry/core';
import { afterAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests, describeWithDockerCompose } from '../../../utils/runner';

describeWithDockerCompose(
Expand Down Expand Up @@ -103,5 +105,131 @@ describeWithDockerCompose(
.completed();
});
});

// The same commands as above, asserted on the streamed span container. With span streaming the
// db spans are named after `db.operation.name` (the bare command) instead of `redis-{command}`.
// ioredis reports its commands lowercase, so the name follows suit.
describe('streamed', () => {
const ORIGIN = 'auto.db.redis.diagnostic_channel';
const SEGMENT_NAME = 'Test Span IORedis 5.11 DC';
const HOST = '127.0.0.1';
const PORT = 6382;

const streamAttribute = (value: unknown): { type: string; value: unknown } => ({
type: Array.isArray(value) ? 'array' : Number.isInteger(value) ? 'integer' : typeof value,
value,
});

// Streamed spans carry `{ type, value }` attribute pairs; the expectations below are written
// as plain values and wrapped here.
const streamAttributes = (values: Record<string, unknown>): Record<string, unknown> =>
Object.fromEntries(Object.entries(values).map(([key, value]) => [key, streamAttribute(value)]));

function streamedSpan(name: string, op: string, attributes: Record<string, unknown>): unknown {
return {
name,
attributes: {
...streamAttributes({
'db.system.name': 'redis',
'sentry.environment': 'production',
'sentry.op': op,
'sentry.origin': ORIGIN,
'sentry.release': '1.0',
'sentry.sdk.name': 'sentry.javascript.node',
'sentry.segment.name': SEGMENT_NAME,
'server.address': HOST,
'server.port': PORT,
[SENTRY_TRACE_LIFECYCLE]: 'stream',
...attributes,
}),
'sentry.sdk.version': { type: 'string', value: expect.any(String) },
'sentry.segment.id': { type: 'string', value: expect.stringMatching(/^[\da-f]{16}$/) },
},
end_timestamp: expect.any(Number),
is_segment: false,
parent_span_id: expect.stringMatching(/^[\da-f]{16}$/),
span_id: expect.stringMatching(/^[\da-f]{16}$/),
start_timestamp: expect.any(Number),
status: 'ok',
trace_id: expect.stringMatching(/^[\da-f]{32}$/),
};
}

const PEER = { 'network.peer.address': HOST, 'network.peer.port': PORT };

createEsmAndCjsTests(__dirname, 'scenario-ioredis-5-11.mjs', 'instrument.mjs', (createTestRunner, test) => {
test(
'creates streamed spans for ioredis v5.11 commands via diagnostics_channel',
{ timeout: 75_000 },
async () => {
await createTestRunner()
.withEnv({ STREAMED: 'true' })
.expect({
span: (container: SerializedStreamedSpanContainer) => {
// The connect span opens its own segment but shares the trace with the test span,
// so both segments arrive in the same container.
expect(container.items.filter(item => item.is_segment).map(item => item.name)).toEqual([
'redis-connect',
SEGMENT_NAME,
]);

// ioredis' own handshake commands (`client SETINFO`, `info`) are emitted on the
// channel too, but belong to the connect segment — the test span's children are the
// commands the scenario issues.
const spans = container.items.filter(
item => !item.is_segment && item.attributes['sentry.segment.name']?.value === SEGMENT_NAME,
);

expect(spans).toEqual([
streamedSpan('set', 'db.query', {
'db.operation.name': 'set',
'db.query.text': 'set dc-test-key ?',
}),
streamedSpan('dc-cache:test-key', 'cache.put', {
...PEER,
'db.operation.name': 'set',
'db.query.text': 'set dc-cache:test-key ?',
'cache.key': ['dc-cache:test-key'],
'cache.item_size': 2,
}),
streamedSpan('dc-cache:test-key-ex', 'cache.put', {
...PEER,
'db.operation.name': 'set',
'db.query.text': 'set dc-cache:test-key-ex ? ? ?',
'cache.key': ['dc-cache:test-key-ex'],
'cache.item_size': 2,
}),
streamedSpan('get', 'db.query', {
'db.operation.name': 'get',
'db.query.text': 'get dc-test-key',
}),
streamedSpan('dc-cache:test-key', 'cache.get', {
...PEER,
'db.operation.name': 'get',
'db.query.text': 'get dc-cache:test-key',
'cache.key': ['dc-cache:test-key'],
'cache.hit': true,
'cache.item_size': 10,
}),
streamedSpan('dc-cache:unavailable-data', 'cache.get', {
...PEER,
'db.operation.name': 'get',
'db.query.text': 'get dc-cache:unavailable-data',
'cache.key': ['dc-cache:unavailable-data'],
'cache.hit': false,
}),
streamedSpan('mget', 'db.query', {
'db.operation.name': 'mget',
'db.query.text': 'mget ? ? ?',
}),
]);
},
})
.start()
.completed();
},
);
});
});
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
traceLifecycle: 'static',
traceLifecycle: process.env.STREAMED === 'true' ? 'stream' : 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
traceLifecycle: 'static',
traceLifecycle: process.env.STREAMED === 'true' ? 'stream' : 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
traceLifecycle: 'static',
traceLifecycle: process.env.STREAMED === 'true' ? 'stream' : 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
Expand Down
Loading
Loading