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,6 @@ import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
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,5 +1,6 @@
import {
DB_COLLECTION_NAME,
DB_CONNECTION_STRING,
DB_NAMESPACE,
DB_OPERATION_NAME,
DB_QUERY_TEXT,
Expand All @@ -8,7 +9,7 @@ import {
SENTRY_ORIGIN,
SENTRY_TRACE_LIFECYCLE,
} from '@sentry/conventions/attributes';
import type { SerializedStreamedSpanContainer, TransactionEvent } from '@sentry/core';
import { DB } from '@sentry/conventions/op';
import { MongoMemoryServer } from 'mongodb-memory-server-global';
import { afterAll, beforeAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
Expand All @@ -32,24 +33,6 @@ describe('MongoDB v4 auto-instrumentation', () => {

const origin = 'auto.db.mongo';

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,
// `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),
}),
op: 'db',
origin,
});

const streamedSpanFor = (operation: string): unknown =>
expect.objectContaining({
name: `${operation} movies`,
Expand All @@ -58,12 +41,12 @@ describe('MongoDB v4 auto-instrumentation', () => {
status: 'ok',
attributes: expect.objectContaining({
[SENTRY_ORIGIN]: { type: 'string', value: origin },
[SENTRY_OP]: { type: 'string', value: 'db' },
[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_CONNECTION_STRING]: { type: 'string', value: expect.any(String) },
[DB_QUERY_TEXT]: { type: 'string', value: expect.any(String) },
[SENTRY_TRACE_LIFECYCLE]: { type: 'string', value: 'stream' },
}),
Expand All @@ -77,35 +60,7 @@ describe('MongoDB v4 auto-instrumentation', () => {
test('auto-instruments `mongodb` (>= 4.0 < 6.4 callback command) and parents pooled ops correctly.', async () => {
await createTestRunner()
.expect({
transaction: (event: TransactionEvent) => {
const spans = event.spans || [];
expect(spans).toContainEqual(spanFor('insert'));
expect(spans).toContainEqual(spanFor('find'));
expect(spans).toContainEqual(spanFor('update'));

// Checkout context propagation: each `op-*` span must be the
// parent of its own find command. A lost context would collapse
// them onto one parent (or the transaction).
const opIds = new Set(spans.filter(s => /^op-[abc]$/.test(s.description ?? '')).map(s => s.span_id));
expect(opIds.size).toBe(3);
const pooledFinds = spans.filter(
s =>
s.origin === origin &&
(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);
},
})
.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) => {
span: container => {
const spans = container.items;
expect(spans).toContainEqual(streamedSpanFor('insert'));
expect(spans).toContainEqual(streamedSpanFor('find'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
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,5 +1,6 @@
import {
DB_COLLECTION_NAME,
DB_CONNECTION_STRING,
DB_NAMESPACE,
DB_OPERATION_NAME,
DB_QUERY_TEXT,
Expand All @@ -8,7 +9,7 @@ import {
SENTRY_ORIGIN,
SENTRY_TRACE_LIFECYCLE,
} from '@sentry/conventions/attributes';
import type { SerializedStreamedSpanContainer, TransactionEvent } from '@sentry/core';
import { DB } from '@sentry/conventions/op';
import { MongoMemoryServer } from 'mongodb-memory-server-global';
import { afterAll, beforeAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
Expand All @@ -32,24 +33,6 @@ describe('MongoDB v5 auto-instrumentation', () => {

const origin = 'auto.db.mongo';

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,
// `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),
}),
op: 'db',
origin,
});

const streamedSpanFor = (operation: string): unknown =>
expect.objectContaining({
name: `${operation} movies`,
Expand All @@ -58,12 +41,12 @@ describe('MongoDB v5 auto-instrumentation', () => {
status: 'ok',
attributes: expect.objectContaining({
[SENTRY_ORIGIN]: { type: 'string', value: origin },
[SENTRY_OP]: { type: 'string', value: 'db' },
[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_CONNECTION_STRING]: { type: 'string', value: expect.any(String) },
[DB_QUERY_TEXT]: { type: 'string', value: expect.any(String) },
[SENTRY_TRACE_LIFECYCLE]: { type: 'string', value: 'stream' },
}),
Expand All @@ -77,35 +60,7 @@ describe('MongoDB v5 auto-instrumentation', () => {
test('auto-instruments `mongodb` (>= 4.0 < 6.4 callback command) and parents pooled ops correctly.', async () => {
await createTestRunner()
.expect({
transaction: (event: TransactionEvent) => {
const spans = event.spans || [];
expect(spans).toContainEqual(spanFor('insert'));
expect(spans).toContainEqual(spanFor('find'));
expect(spans).toContainEqual(spanFor('update'));

// Checkout context propagation: each `op-*` span must be the
// parent of its own find command. A lost context would collapse
// them onto one parent (or the transaction).
const opIds = new Set(spans.filter(s => /^op-[abc]$/.test(s.description ?? '')).map(s => s.span_id));
expect(opIds.size).toBe(3);
const pooledFinds = spans.filter(
s =>
s.origin === origin &&
(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);
},
})
.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) => {
span: container => {
const spans = container.items;
expect(spans).toContainEqual(streamedSpanFor('insert'));
expect(spans).toContainEqual(streamedSpanFor('find'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
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,5 +1,6 @@
import {
DB_COLLECTION_NAME,
DB_CONNECTION_STRING,
DB_NAMESPACE,
DB_OPERATION_NAME,
DB_QUERY_TEXT,
Expand All @@ -8,7 +9,7 @@ import {
SENTRY_ORIGIN,
SENTRY_TRACE_LIFECYCLE,
} from '@sentry/conventions/attributes';
import type { SerializedStreamedSpanContainer, TransactionEvent } from '@sentry/core';
import { DB } from '@sentry/conventions/op';
import { MongoMemoryServer } from 'mongodb-memory-server-global';
import { afterAll, beforeAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
Expand All @@ -35,24 +36,6 @@ describe('MongoDB v6 auto-instrumentation', () => {
// `db.statement` (scrubbed full command doc) and `db.connection_string` vary
// by driver version, so assert their presence rather than exact content;
// the operation-identifying attributes are exact.
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,
// `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),
}),
op: 'db',
origin,
});

const streamedSpanFor = (operation: string): unknown =>
expect.objectContaining({
name: `${operation} movies`,
Expand All @@ -61,12 +44,12 @@ describe('MongoDB v6 auto-instrumentation', () => {
status: 'ok',
attributes: expect.objectContaining({
[SENTRY_ORIGIN]: { type: 'string', value: origin },
[SENTRY_OP]: { type: 'string', value: 'db' },
[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_CONNECTION_STRING]: { type: 'string', value: expect.any(String) },
[DB_QUERY_TEXT]: { type: 'string', value: expect.any(String) },
[SENTRY_TRACE_LIFECYCLE]: { type: 'string', value: 'stream' },
}),
Expand All @@ -80,29 +63,7 @@ describe('MongoDB v6 auto-instrumentation', () => {
test('auto-instruments modern `mongodb` (>= 6.4 promise command).', async () => {
await createTestRunner()
.expect({
transaction: (event: TransactionEvent) => {
const spans = event.spans || [];
expect(spans).toContainEqual(spanFor('insert'));
expect(spans).toContainEqual(spanFor('find'));
expect(spans).toContainEqual(spanFor('update'));
// No orphaned handshake/heartbeat spans!
// every command span has a parent.
const mongoSpans = spans.filter(s => s.origin === origin);
expect(mongoSpans.length).toBeGreaterThan(0);
for (const s of mongoSpans) {
expect(s.parent_span_id).toBeTruthy();
}
},
})
.start()
.completed();
});

test('auto-instruments modern `mongodb` with span streaming enabled.', async () => {
await createTestRunner()
.withEnv({ STREAMED: 'true' })
.expect({
span: (container: SerializedStreamedSpanContainer) => {
span: container => {
const spans = container.items;
expect(spans).toContainEqual(streamedSpanFor('insert'));
expect(spans).toContainEqual(streamedSpanFor('find'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
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,5 +1,6 @@
import {
DB_COLLECTION_NAME,
DB_CONNECTION_STRING,
DB_NAMESPACE,
DB_OPERATION_NAME,
DB_QUERY_TEXT,
Expand All @@ -8,7 +9,7 @@ import {
SENTRY_ORIGIN,
SENTRY_TRACE_LIFECYCLE,
} from '@sentry/conventions/attributes';
import type { SerializedStreamedSpanContainer, TransactionEvent } from '@sentry/core';
import { DB } from '@sentry/conventions/op';
import { MongoMemoryServer } from 'mongodb-memory-server-global';
import { afterAll, beforeAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
Expand All @@ -35,24 +36,6 @@ describe('MongoDB v7 auto-instrumentation', () => {
// `db.statement` (scrubbed full command doc) and `db.connection_string` vary
// by driver version, so assert their presence rather than exact content;
// the operation-identifying attributes are exact.
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,
// `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),
}),
op: 'db',
origin,
});

const streamedSpanFor = (operation: string): unknown =>
expect.objectContaining({
name: `${operation} movies`,
Expand All @@ -61,12 +44,12 @@ describe('MongoDB v7 auto-instrumentation', () => {
status: 'ok',
attributes: expect.objectContaining({
[SENTRY_ORIGIN]: { type: 'string', value: origin },
[SENTRY_OP]: { type: 'string', value: 'db' },
[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_CONNECTION_STRING]: { type: 'string', value: expect.any(String) },
[DB_QUERY_TEXT]: { type: 'string', value: expect.any(String) },
[SENTRY_TRACE_LIFECYCLE]: { type: 'string', value: 'stream' },
}),
Expand All @@ -80,29 +63,7 @@ describe('MongoDB v7 auto-instrumentation', () => {
test('auto-instruments modern `mongodb` (>= 6.4 promise command).', async () => {
await createTestRunner()
.expect({
transaction: (event: TransactionEvent) => {
const spans = event.spans || [];
expect(spans).toContainEqual(spanFor('insert'));
expect(spans).toContainEqual(spanFor('find'));
expect(spans).toContainEqual(spanFor('update'));
// No orphaned handshake/heartbeat spans!
// every command span has a parent.
const mongoSpans = spans.filter(s => s.origin === origin);
expect(mongoSpans.length).toBeGreaterThan(0);
for (const s of mongoSpans) {
expect(s.parent_span_id).toBeTruthy();
}
},
})
.start()
.completed();
});

test('auto-instruments modern `mongodb` with span streaming enabled.', async () => {
await createTestRunner()
.withEnv({ STREAMED: 'true' })
.expect({
span: (container: SerializedStreamedSpanContainer) => {
span: container => {
const spans = container.items;
expect(spans).toContainEqual(streamedSpanFor('insert'));
expect(spans).toContainEqual(streamedSpanFor('find'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
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