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 @@ -8,13 +8,3 @@ Sentry.init({
traceLifecycle: 'stream',
transport: loggingTransport,
});

async function run(): Promise<void> {
await Sentry.startSpan({ name: 'test_transaction' }, async () => {
await fetch(`${process.env.SERVER_URL}/api/v0`);
});

await Sentry.flush();
}

void run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as Sentry from '@sentry/node';

async function run() {
await Sentry.startSpan({ name: 'test_transaction' }, async () => {
await fetch(`${process.env.SERVER_URL}/api/v0`);
});

await Sentry.flush();
}

void run();
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
import { createTestServer } from '@sentry-internal/test-utils';
import { expect, test } from 'vitest';
import { createRunner } from '../../../../utils/runner';
import { afterAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createCjsTests } from '../../../../utils/runner';

test('infers sentry.op for streamed outgoing fetch spans', async () => {
expect.assertions(2);
describe('streamed outgoing fetch spans', () => {
afterAll(() => {
cleanupChildProcesses();
});

const [SERVER_URL, closeTestServer] = await createTestServer()
.get('/api/v0', () => {
expect(true).toBe(true);
})
.start();
createCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
test('infers sentry.op for streamed outgoing fetch spans', async () => {
expect.assertions(2);

await createRunner(__dirname, 'scenario.ts')
.withEnv({ SERVER_URL })
.expect({
span: container => {
const httpClientSpan = container.items.find(
item =>
item.attributes?.['sentry.op']?.type === 'string' && item.attributes['sentry.op'].value === 'http.client',
);
const [SERVER_URL, closeTestServer] = await createTestServer()
.get('/api/v0', () => {
expect(true).toBe(true);
})
.start();

expect(httpClientSpan).toBeDefined();
},
})
.start()
.completed();
closeTestServer();
await createRunner()
.withEnv({ SERVER_URL })
.expect({
span: container => {
const httpClientSpan = container.items.find(
item =>
item.attributes?.['sentry.op']?.type === 'string' &&
item.attributes['sentry.op'].value === 'http.client',
);

expect(httpClientSpan).toBeDefined();
},
})
.start()
.completed();
closeTestServer();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,3 @@ Sentry.init({
tracesSampleRate: 1.0,
transport: loggingTransport,
});

// eslint-disable-next-line @typescript-eslint/no-floating-promises
Sentry.startSpan({ name: 'test_transaction' }, async () => {
await fetch(`${process.env.SERVER_URL}/api/v0/users?id=1#fragment`);
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
});

// eslint-disable-next-line @typescript-eslint/no-floating-promises
Sentry.startSpan({ name: 'test_transaction' }, async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,58 @@
import { createTestServer } from '@sentry-internal/test-utils';
import { expect, test } from 'vitest';
import { createRunner } from '../../../../utils/runner';
import { afterAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createCjsTests } from '../../../../utils/runner';

test('captures spans for outgoing fetch requests', async () => {
expect.assertions(3);
describe('outgoing fetch spans', () => {
afterAll(() => {
cleanupChildProcesses();
});

const [SERVER_URL, closeTestServer] = await createTestServer()
.get('/api/v0', () => {
// Just ensure we're called
expect(true).toBe(true);
})
.get(
'/api/v1',
() => {
// Just ensure we're called
expect(true).toBe(true);
},
404,
)
.start();
createCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
test('captures spans for outgoing fetch requests', async () => {
expect.assertions(3);

await createRunner(__dirname, 'scenario.ts')
.withEnv({ SERVER_URL })
.expect({
transaction: {
transaction: 'test_transaction',
spans: expect.arrayContaining([
expect.objectContaining({
description: expect.stringMatching(/GET .*\/api\/v0/),
op: 'http.client',
origin: 'auto.http.otel.node_fetch',
status: 'ok',
}),
expect.objectContaining({
description: expect.stringMatching(/GET .*\/api\/v1/),
op: 'http.client',
origin: 'auto.http.otel.node_fetch',
status: 'not_found',
data: expect.objectContaining({
'http.response.status_code': 404,
}),
}),
]),
},
})
.start()
.completed();
closeTestServer();
const [SERVER_URL, closeTestServer] = await createTestServer()
.get('/api/v0', () => {
// Just ensure we're called
expect(true).toBe(true);
})
.get(
'/api/v1',
() => {
// Just ensure we're called
expect(true).toBe(true);
},
404,
)
.start();

await createRunner()
.withEnv({ SERVER_URL })
.expect({
transaction: {
transaction: 'test_transaction',
spans: expect.arrayContaining([
expect.objectContaining({
description: expect.stringMatching(/GET .*\/api\/v0/),
op: 'http.client',
origin: 'auto.http.otel.node_fetch',
status: 'ok',
}),
expect.objectContaining({
description: expect.stringMatching(/GET .*\/api\/v1/),
op: 'http.client',
origin: 'auto.http.otel.node_fetch',
status: 'not_found',
data: expect.objectContaining({
'http.response.status_code': 404,
}),
}),
]),
},
})
.start()
.completed();
closeTestServer();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
});
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
import { createServer } from 'http';
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
});

// Bind and immediately release a port so we have an address that reliably refuses the connection.
// A refused outgoing request fires the `undici:request:error` channel, exercising the error path.
function getRefusedPort(): Promise<number> {
/**
* @returns {Promise<number>}
*/
function getRefusedPort() {
return new Promise(resolve => {
const server = createServer();
server.listen(0, () => {
const { port } = server.address() as { port: number };
server.close(() => resolve(port));
const address = /** @type {{ port: number }} */ (server.address());
server.close(() => resolve(address.port));
});
});
}

async function run(): Promise<void> {
async function run() {
const port = await getRefusedPort();

await Sentry.startSpan({ name: 'test_transaction' }, async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import { expect, test } from 'vitest';
import { createRunner } from '../../../../utils/runner';
import { afterAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createCjsTests } from '../../../../utils/runner';

test('captures an errored span for a failed outgoing fetch request', async () => {
await createRunner(__dirname, 'scenario.ts')
.expect({
transaction: {
transaction: 'test_transaction',
spans: expect.arrayContaining([
expect.objectContaining({
description: expect.stringMatching(/GET http:\/\/localhost:\d+\//),
op: 'http.client',
origin: 'auto.http.otel.node_fetch',
status: 'internal_error',
}),
]),
},
})
.start()
.completed();
describe('outgoing fetch spans - error', () => {
afterAll(() => {
cleanupChildProcesses();
});

createCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
test('captures an errored span for a failed outgoing fetch request', async () => {
await createRunner()
.expect({
transaction: {
transaction: 'test_transaction',
spans: expect.arrayContaining([
expect.objectContaining({
description: expect.stringMatching(/GET http:\/\/localhost:\d+\//),
op: 'http.client',
origin: 'auto.http.otel.node_fetch',
status: 'internal_error',
}),
]),
},
})
.start()
.completed();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,3 @@ Sentry.init({
}),
],
});

// eslint-disable-next-line @typescript-eslint/no-floating-promises
Sentry.startSpan({ name: 'test_transaction' }, async () => {
await fetch(`${process.env.SERVER_URL}/api/v0`);
await fetch(`${process.env.SERVER_URL}/api/v1`);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as Sentry from '@sentry/node';

// eslint-disable-next-line @typescript-eslint/no-floating-promises
Sentry.startSpan({ name: 'test_transaction' }, async () => {
await fetch(`${process.env.SERVER_URL}/api/v0`);
await fetch(`${process.env.SERVER_URL}/api/v1`);
});
Loading
Loading