Skip to content
Merged
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,14 @@
import type { TransactionEvent } from '@sentry/core';
import {
DB_COLLECTION_NAME,
DB_NAMESPACE,
DB_OPERATION_NAME,
DB_QUERY_TEXT,
DB_SYSTEM_NAME,
SENTRY_OP,
SENTRY_ORIGIN,
SENTRY_TRACE_LIFECYCLE,
} from '@sentry/conventions/attributes';
import type { SerializedStreamedSpanContainer, TransactionEvent } from '@sentry/core';
import { MongoMemoryServer } from 'mongodb-memory-server-global';
import { afterAll, beforeAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
Expand All @@ -25,19 +35,40 @@ describe('MongoDB v4 auto-instrumentation', () => {
const spanFor = (operation: string): unknown =>
expect.objectContaining({
data: expect.objectContaining({
'sentry.origin': origin,
'sentry.op': 'db',
'db.system.name': 'mongodb',
'db.namespace': 'admin',
'db.collection.name': 'movies',
'db.operation.name': operation,
[SENTRY_ORIGIN]: origin,
[SENTRY_OP]: 'db',
[DB_SYSTEM_NAME]: 'mongodb',
[DB_NAMESPACE]: 'admin',
[DB_COLLECTION_NAME]: 'movies',
[DB_OPERATION_NAME]: operation,
// `db.connection_string` has no `@sentry/conventions` constant — it stays inlined to match
// what `@opentelemetry/instrumentation-mongodb` emitted.
'db.connection_string': expect.any(String),
'db.query.text': expect.any(String),
[DB_QUERY_TEXT]: expect.any(String),
}),
op: 'db',
origin,
});

const streamedSpanFor = (operation: string): unknown =>
expect.objectContaining({
name: `${operation} movies`,
is_segment: false,
parent_span_id: expect.stringMatching(/^[\da-f]{16}$/),
status: 'ok',
attributes: expect.objectContaining({
[SENTRY_ORIGIN]: { type: 'string', value: origin },
[SENTRY_OP]: { type: 'string', value: 'db' },
[DB_SYSTEM_NAME]: { type: 'string', value: 'mongodb' },
[DB_NAMESPACE]: { type: 'string', value: 'admin' },
[DB_COLLECTION_NAME]: { type: 'string', value: 'movies' },
[DB_OPERATION_NAME]: { type: 'string', value: operation },
'db.connection_string': { type: 'string', value: expect.any(String) },
[DB_QUERY_TEXT]: { type: 'string', value: expect.any(String) },
[SENTRY_TRACE_LIFECYCLE]: { type: 'string', value: 'stream' },
}),
});

createEsmAndCjsTests(
__dirname,
'scenario.mjs',
Expand All @@ -60,7 +91,7 @@ describe('MongoDB v4 auto-instrumentation', () => {
const pooledFinds = spans.filter(
s =>
s.origin === origin &&
(s.data as Record<string, unknown>)?.['db.operation.name'] === 'find' &&
(s.data as Record<string, unknown>)?.[DB_OPERATION_NAME] === 'find' &&
opIds.has(s.parent_span_id as string),
);
expect(new Set(pooledFinds.map(s => s.parent_span_id)).size).toBe(3);
Expand All @@ -69,6 +100,31 @@ describe('MongoDB v4 auto-instrumentation', () => {
.start()
.completed();
});

test('auto-instruments `mongodb` and parents pooled ops correctly with span streaming enabled.', async () => {
await createTestRunner()
.withEnv({ STREAMED: 'true' })
.expect({
span: (container: SerializedStreamedSpanContainer) => {
const spans = container.items;
expect(spans).toContainEqual(streamedSpanFor('insert'));
expect(spans).toContainEqual(streamedSpanFor('find'));
expect(spans).toContainEqual(streamedSpanFor('update'));

const opIds = new Set(spans.filter(span => /^op-[abc]$/.test(span.name)).map(span => span.span_id));
expect(opIds.size).toBe(3);
const pooledFinds = spans.filter(
span =>
span.attributes[SENTRY_ORIGIN]?.value === origin &&
span.attributes[DB_OPERATION_NAME]?.value === 'find' &&
opIds.has(span.parent_span_id as string),
);
expect(new Set(pooledFinds.map(span => span.parent_span_id)).size).toBe(3);
},
})
.start()
.completed();
});
},
{ additionalDependencies: { mongodb: '4.17.2' } },
);
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
@@ -1,4 +1,14 @@
import type { TransactionEvent } from '@sentry/core';
import {
DB_COLLECTION_NAME,
DB_NAMESPACE,
DB_OPERATION_NAME,
DB_QUERY_TEXT,
DB_SYSTEM_NAME,
SENTRY_OP,
SENTRY_ORIGIN,
SENTRY_TRACE_LIFECYCLE,
} from '@sentry/conventions/attributes';
import type { SerializedStreamedSpanContainer, TransactionEvent } from '@sentry/core';
import { MongoMemoryServer } from 'mongodb-memory-server-global';
import { afterAll, beforeAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
Expand All @@ -25,19 +35,40 @@ describe('MongoDB v5 auto-instrumentation', () => {
const spanFor = (operation: string): unknown =>
expect.objectContaining({
data: expect.objectContaining({
'sentry.origin': origin,
'sentry.op': 'db',
'db.system.name': 'mongodb',
'db.namespace': 'admin',
'db.collection.name': 'movies',
'db.operation.name': operation,
[SENTRY_ORIGIN]: origin,
[SENTRY_OP]: 'db',
[DB_SYSTEM_NAME]: 'mongodb',
[DB_NAMESPACE]: 'admin',
[DB_COLLECTION_NAME]: 'movies',
[DB_OPERATION_NAME]: operation,
// `db.connection_string` has no `@sentry/conventions` constant — it stays inlined to match
// what `@opentelemetry/instrumentation-mongodb` emitted.
'db.connection_string': expect.any(String),
'db.query.text': expect.any(String),
[DB_QUERY_TEXT]: expect.any(String),
}),
op: 'db',
origin,
});

const streamedSpanFor = (operation: string): unknown =>
expect.objectContaining({
name: `${operation} movies`,
is_segment: false,
parent_span_id: expect.stringMatching(/^[\da-f]{16}$/),
status: 'ok',
attributes: expect.objectContaining({
[SENTRY_ORIGIN]: { type: 'string', value: origin },
[SENTRY_OP]: { type: 'string', value: 'db' },
[DB_SYSTEM_NAME]: { type: 'string', value: 'mongodb' },
[DB_NAMESPACE]: { type: 'string', value: 'admin' },
[DB_COLLECTION_NAME]: { type: 'string', value: 'movies' },
[DB_OPERATION_NAME]: { type: 'string', value: operation },
'db.connection_string': { type: 'string', value: expect.any(String) },
[DB_QUERY_TEXT]: { type: 'string', value: expect.any(String) },
[SENTRY_TRACE_LIFECYCLE]: { type: 'string', value: 'stream' },
}),
});

createEsmAndCjsTests(
__dirname,
'scenario.mjs',
Expand All @@ -60,7 +91,7 @@ describe('MongoDB v5 auto-instrumentation', () => {
const pooledFinds = spans.filter(
s =>
s.origin === origin &&
(s.data as Record<string, unknown>)?.['db.operation.name'] === 'find' &&
(s.data as Record<string, unknown>)?.[DB_OPERATION_NAME] === 'find' &&
opIds.has(s.parent_span_id as string),
);
expect(new Set(pooledFinds.map(s => s.parent_span_id)).size).toBe(3);
Expand All @@ -69,6 +100,31 @@ describe('MongoDB v5 auto-instrumentation', () => {
.start()
.completed();
});

test('auto-instruments `mongodb` and parents pooled ops correctly with span streaming enabled.', async () => {
await createTestRunner()
.withEnv({ STREAMED: 'true' })
.expect({
span: (container: SerializedStreamedSpanContainer) => {
const spans = container.items;
expect(spans).toContainEqual(streamedSpanFor('insert'));
expect(spans).toContainEqual(streamedSpanFor('find'));
expect(spans).toContainEqual(streamedSpanFor('update'));

const opIds = new Set(spans.filter(span => /^op-[abc]$/.test(span.name)).map(span => span.span_id));
expect(opIds.size).toBe(3);
const pooledFinds = spans.filter(
span =>
span.attributes[SENTRY_ORIGIN]?.value === origin &&
span.attributes[DB_OPERATION_NAME]?.value === 'find' &&
opIds.has(span.parent_span_id as string),
);
expect(new Set(pooledFinds.map(span => span.parent_span_id)).size).toBe(3);
},
})
.start()
.completed();
});
},
{ additionalDependencies: { mongodb: '5.9.2' } },
);
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
@@ -1,4 +1,14 @@
import type { TransactionEvent } from '@sentry/core';
import {
DB_COLLECTION_NAME,
DB_NAMESPACE,
DB_OPERATION_NAME,
DB_QUERY_TEXT,
DB_SYSTEM_NAME,
SENTRY_OP,
SENTRY_ORIGIN,
SENTRY_TRACE_LIFECYCLE,
} from '@sentry/conventions/attributes';
import type { SerializedStreamedSpanContainer, TransactionEvent } from '@sentry/core';
import { MongoMemoryServer } from 'mongodb-memory-server-global';
import { afterAll, beforeAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
Expand Down Expand Up @@ -28,19 +38,40 @@ describe('MongoDB v6 auto-instrumentation', () => {
const spanFor = (operation: string): unknown =>
expect.objectContaining({
data: expect.objectContaining({
'sentry.origin': origin,
'sentry.op': 'db',
'db.system.name': 'mongodb',
'db.namespace': 'admin',
'db.collection.name': 'movies',
'db.operation.name': operation,
[SENTRY_ORIGIN]: origin,
[SENTRY_OP]: 'db',
[DB_SYSTEM_NAME]: 'mongodb',
[DB_NAMESPACE]: 'admin',
[DB_COLLECTION_NAME]: 'movies',
[DB_OPERATION_NAME]: operation,
// `db.connection_string` has no `@sentry/conventions` constant — it stays inlined to match
// what `@opentelemetry/instrumentation-mongodb` emitted.
'db.connection_string': expect.any(String),
'db.query.text': expect.any(String),
[DB_QUERY_TEXT]: expect.any(String),
}),
op: 'db',
origin,
});

const streamedSpanFor = (operation: string): unknown =>
expect.objectContaining({
name: `${operation} movies`,
is_segment: false,
parent_span_id: expect.stringMatching(/^[\da-f]{16}$/),
status: 'ok',
attributes: expect.objectContaining({
[SENTRY_ORIGIN]: { type: 'string', value: origin },
[SENTRY_OP]: { type: 'string', value: 'db' },
[DB_SYSTEM_NAME]: { type: 'string', value: 'mongodb' },
[DB_NAMESPACE]: { type: 'string', value: 'admin' },
[DB_COLLECTION_NAME]: { type: 'string', value: 'movies' },
[DB_OPERATION_NAME]: { type: 'string', value: operation },
'db.connection_string': { type: 'string', value: expect.any(String) },
[DB_QUERY_TEXT]: { type: 'string', value: expect.any(String) },
[SENTRY_TRACE_LIFECYCLE]: { type: 'string', value: 'stream' },
}),
});

createEsmAndCjsTests(
__dirname,
'scenario.mjs',
Expand All @@ -66,6 +97,30 @@ describe('MongoDB v6 auto-instrumentation', () => {
.start()
.completed();
});

test('auto-instruments modern `mongodb` with span streaming enabled.', async () => {
await createTestRunner()
.withEnv({ STREAMED: 'true' })
.expect({
span: (container: SerializedStreamedSpanContainer) => {
const spans = container.items;
expect(spans).toContainEqual(streamedSpanFor('insert'));
expect(spans).toContainEqual(streamedSpanFor('find'));
expect(spans).toContainEqual(streamedSpanFor('update'));

expect(container.items.find(item => item.is_segment)?.name).toBe('Test Transaction');

const mongoSpans = spans.filter(span => span.attributes[SENTRY_ORIGIN]?.value === origin);
expect(mongoSpans.length).toBeGreaterThan(0);
for (const span of mongoSpans) {
expect(span.is_segment).toBe(false);
expect(span.parent_span_id).toBeTruthy();
}
},
})
.start()
.completed();
});
},
{ additionalDependencies: { mongodb: '6.21.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