Skip to content

test(node): otel Express integration tests #10169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 16, 2024
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
6 changes: 5 additions & 1 deletion dev-packages/node-integration-tests/suites/anr/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { conditionalTest } from '../../utils';
import { createRunner } from '../../utils/runner';
import { cleanupChildProcesses, createRunner } from '../../utils/runner';

const EXPECTED_ANR_EVENT = {
// Ensure we have context
Expand Down Expand Up @@ -52,6 +52,10 @@ const EXPECTED_ANR_EVENT = {
};

conditionalTest({ min: 16 })('should report ANR when event loop blocked', () => {
afterAll(() => {
cleanupChildProcesses();
});

// TODO (v8): Remove this old API and this test
test('Legacy API', done => {
createRunner(__dirname, 'legacy.js').expect({ event: EXPECTED_ANR_EVENT }).start(done);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { loggingTransport, startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';
import express from 'express';

Expand All @@ -6,6 +7,7 @@ const app = express();
Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
transport: loggingTransport,
});

app.use(Sentry.Handlers.requestHandler());
Expand All @@ -16,4 +18,4 @@ app.get('/test/express', () => {

app.use(Sentry.Handlers.errorHandler());

export default app;
startExpressServerAndSendPortToRunner(app);
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
import { TestEnv, assertSentryEvent } from '../../../utils/index';
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';

test('should capture and send Express controller error.', async () => {
const env = await TestEnv.init(__dirname, `${__dirname}/server.ts`);
const event = await env.getEnvelopeRequest({ url: `${env.url}/express` });

expect((event[2] as any).exception.values[0].stacktrace.frames.length).toBeGreaterThan(0);
afterAll(() => {
cleanupChildProcesses();
});

assertSentryEvent(event[2] as any, {
exception: {
values: [
{
mechanism: {
type: 'middleware',
handled: false,
},
type: 'Error',
value: 'test_error',
test('should capture and send Express controller error.', done => {
const runner = createRunner(__dirname, 'server.ts')
.ignore('session', 'sessions')
.expect({
event: {
exception: {
values: [
{
mechanism: {
type: 'middleware',
handled: false,
},
type: 'Error',
value: 'test_error',
stacktrace: {
frames: expect.arrayContaining([
expect.objectContaining({
function: expect.any(String),
lineno: expect.any(Number),
colno: expect.any(Number),
}),
]),
},
},
],
},
],
},
});
},
})
.start(done);

expect(() => runner.makeRequest('get', '/test/express')).rejects.toThrow();
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { loggingTransport, startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';
import * as Tracing from '@sentry/tracing';
import cors from 'cors';
Expand All @@ -11,6 +12,7 @@ Sentry.init({
// eslint-disable-next-line deprecation/deprecation
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })],
tracesSampleRate: 1.0,
transport: loggingTransport,
});

app.use(Sentry.Handlers.requestHandler());
Expand All @@ -32,4 +34,4 @@ app.use('/api/v1', APIv1);

app.use(Sentry.Handlers.errorHandler());

export default app;
startExpressServerAndSendPortToRunner(app);
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { TestEnv, assertSentryEvent } from '../../../../utils/index';
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';

test('should construct correct url with common infixes with multiple parameterized routers.', async () => {
const env = await TestEnv.init(__dirname, `${__dirname}/server.ts`);
const event = await env.getEnvelopeRequest({ url: env.url.replace('test', 'api/v1/user/3212') });
afterAll(() => {
cleanupChildProcesses();
});

assertSentryEvent(event[2] as any, {
message: 'Custom Message',
transaction: 'GET /api/v1/user/:userId',
});
test('should construct correct url with common infixes with multiple parameterized routers.', done => {
createRunner(__dirname, 'server.ts')
.ignore('transaction', 'session', 'sessions')
.expect({ event: { message: 'Custom Message', transaction: 'GET /api/v1/user/:userId' } })
.start(done)
.makeRequest('get', '/api/v1/user/3212');
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { loggingTransport, startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';
import * as Tracing from '@sentry/tracing';
import cors from 'cors';
Expand All @@ -11,6 +12,7 @@ Sentry.init({
// eslint-disable-next-line deprecation/deprecation
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })],
tracesSampleRate: 1.0,
transport: loggingTransport,
});

app.use(Sentry.Handlers.requestHandler());
Expand All @@ -32,4 +34,4 @@ app.use('/api2/v1', APIv1);

app.use(Sentry.Handlers.errorHandler());

export default app;
startExpressServerAndSendPortToRunner(app);
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { TestEnv, assertSentryEvent } from '../../../../utils/index';
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';

test('should construct correct url with common infixes with multiple routers.', async () => {
const env = await TestEnv.init(__dirname, `${__dirname}/server.ts`);
const event = await env.getEnvelopeRequest({ url: env.url.replace('test', 'api2/v1/test/') });
afterAll(() => {
cleanupChildProcesses();
});

assertSentryEvent(event[2] as any, {
message: 'Custom Message',
transaction: 'GET /api2/v1/test',
});
test('should construct correct url with common infixes with multiple routers.', done => {
createRunner(__dirname, 'server.ts')
.ignore('transaction', 'session', 'sessions')
.expect({ event: { message: 'Custom Message', transaction: 'GET /api2/v1/test' } })
.start(done)
.makeRequest('get', '/api2/v1/test');
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { loggingTransport, startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';
import * as Tracing from '@sentry/tracing';
import cors from 'cors';
Expand All @@ -11,6 +12,7 @@ Sentry.init({
// eslint-disable-next-line deprecation/deprecation
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })],
tracesSampleRate: 1.0,
transport: loggingTransport,
});

app.use(Sentry.Handlers.requestHandler());
Expand All @@ -32,4 +34,4 @@ app.use('/api', root);

app.use(Sentry.Handlers.errorHandler());

export default app;
startExpressServerAndSendPortToRunner(app);
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { TestEnv, assertSentryEvent } from '../../../../utils/index';
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';

test('should construct correct urls with multiple parameterized routers (use order reversed).', async () => {
const env = await TestEnv.init(__dirname, `${__dirname}/server.ts`);
const event = await env.getEnvelopeRequest({ url: env.url.replace('test', 'api/v1/user/1234/') });
afterAll(() => {
cleanupChildProcesses();
});

assertSentryEvent(event[2] as any, {
message: 'Custom Message',
transaction: 'GET /api/v1/user/:userId',
});
test('should construct correct urls with multiple parameterized routers (use order reversed).', done => {
createRunner(__dirname, 'server.ts')
.ignore('transaction', 'session', 'sessions')
.expect({ event: { message: 'Custom Message', transaction: 'GET /api/v1/user/:userId' } })
.start(done)
.makeRequest('get', '/api/v1/user/1234/');
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { loggingTransport, startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';
import * as Tracing from '@sentry/tracing';
import cors from 'cors';
Expand All @@ -11,6 +12,7 @@ Sentry.init({
// eslint-disable-next-line deprecation/deprecation
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })],
tracesSampleRate: 1.0,
transport: loggingTransport,
});

app.use(Sentry.Handlers.requestHandler());
Expand All @@ -32,4 +34,4 @@ app.use('/api/v1', APIv1);

app.use(Sentry.Handlers.errorHandler());

export default app;
startExpressServerAndSendPortToRunner(app);
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { TestEnv, assertSentryEvent } from '../../../../utils/index';
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';

test('should construct correct urls with multiple parameterized routers.', async () => {
const env = await TestEnv.init(__dirname, `${__dirname}/server.ts`);
const event = await env.getEnvelopeRequest({ url: env.url.replace('test', 'api/v1/user/1234/') });
afterAll(() => {
cleanupChildProcesses();
});

assertSentryEvent(event[2] as any, {
message: 'Custom Message',
transaction: 'GET /api/v1/user/:userId',
});
test('should construct correct urls with multiple parameterized routers.', done => {
createRunner(__dirname, 'server.ts')
.ignore('transaction', 'session', 'sessions')
.expect({ event: { message: 'Custom Message', transaction: 'GET /api/v1/user/:userId' } })
.start(done)
.makeRequest('get', '/api/v1/user/1234/');
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { loggingTransport, startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';
import * as Tracing from '@sentry/tracing';
import cors from 'cors';
Expand All @@ -11,6 +12,7 @@ Sentry.init({
// eslint-disable-next-line deprecation/deprecation
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })],
tracesSampleRate: 1.0,
transport: loggingTransport,
});

app.use(Sentry.Handlers.requestHandler());
Expand All @@ -32,4 +34,4 @@ app.use('/api', root);

app.use(Sentry.Handlers.errorHandler());

export default app;
startExpressServerAndSendPortToRunner(app);
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { TestEnv, assertSentryEvent } from '../../../../utils/index';
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';

test('should construct correct url with multiple parameterized routers of the same length (use order reversed).', async () => {
const env = await TestEnv.init(__dirname, `${__dirname}/server.ts`);
const event = await env.getEnvelopeRequest({ url: env.url.replace('test', 'api/v1/1234/') });
afterAll(() => {
cleanupChildProcesses();
});

assertSentryEvent(event[2] as any, {
message: 'Custom Message',
transaction: 'GET /api/v1/:userId',
});
test('should construct correct url with multiple parameterized routers of the same length (use order reversed).', done => {
createRunner(__dirname, 'server.ts')
.ignore('transaction', 'session', 'sessions')
.expect({ event: { message: 'Custom Message', transaction: 'GET /api/v1/:userId' } })
.start(done)
.makeRequest('get', '/api/v1/1234/');
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { loggingTransport, startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';
import * as Tracing from '@sentry/tracing';
import cors from 'cors';
Expand All @@ -11,6 +12,7 @@ Sentry.init({
// eslint-disable-next-line deprecation/deprecation
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })],
tracesSampleRate: 1.0,
transport: loggingTransport,
});

app.use(Sentry.Handlers.requestHandler());
Expand All @@ -32,4 +34,4 @@ app.use('/api/v1', APIv1);

app.use(Sentry.Handlers.errorHandler());

export default app;
startExpressServerAndSendPortToRunner(app);
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { TestEnv, assertSentryEvent } from '../../../../utils/index';
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';

test('should construct correct url with multiple parameterized routers of the same length.', async () => {
const env = await TestEnv.init(__dirname, `${__dirname}/server.ts`);
const event = await env.getEnvelopeRequest({ url: env.url.replace('test', 'api/v1/1234/') });
afterAll(() => {
cleanupChildProcesses();
});

assertSentryEvent(event[2] as any, {
message: 'Custom Message',
transaction: 'GET /api/v1/:userId',
});
test('should construct correct url with multiple parameterized routers of the same length.', done => {
createRunner(__dirname, 'server.ts')
.ignore('transaction', 'session', 'sessions')
.expect({ event: { message: 'Custom Message', transaction: 'GET /api/v1/:userId' } })
.start(done)
.makeRequest('get', '/api/v1/1234/');
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { loggingTransport, startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';
import * as Tracing from '@sentry/tracing';
import cors from 'cors';
Expand All @@ -11,6 +12,7 @@ Sentry.init({
// eslint-disable-next-line deprecation/deprecation
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })],
tracesSampleRate: 1.0,
transport: loggingTransport,
});

app.use(Sentry.Handlers.requestHandler());
Expand All @@ -32,4 +34,4 @@ app.use('/api/v1', APIv1);

app.use(Sentry.Handlers.errorHandler());

export default app;
startExpressServerAndSendPortToRunner(app);
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { TestEnv, assertSentryEvent } from '../../../../utils/index';
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';

test('should construct correct urls with multiple routers.', async () => {
const env = await TestEnv.init(__dirname, `${__dirname}/server.ts`);
const event = await env.getEnvelopeRequest({ url: env.url.replace('test', 'api/v1/test/') });
afterAll(() => {
cleanupChildProcesses();
});

assertSentryEvent(event[2] as any, {
message: 'Custom Message',
transaction: 'GET /api/v1/test',
});
test('should construct correct urls with multiple routers.', done => {
createRunner(__dirname, 'server.ts')
.ignore('transaction', 'session', 'sessions')
.expect({ event: { message: 'Custom Message', transaction: 'GET /api/v1/test' } })
.start(done)
.makeRequest('get', '/api/v1/test');
});
Loading