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

Sentry.init({
traceLifecycle: 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
tracesSampleRate: 1.0,
transport: loggingTransport,
Expand Down
65 changes: 31 additions & 34 deletions dev-packages/node-integration-tests/suites/hono-sdk/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,36 @@ describe('hono-sdk (Node)', () => {
});

createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
test('creates a transaction for a basic GET request', async () => {
test('creates a segment span for a basic GET request', async () => {
const runner = createRunner()
.expect({
transaction: {
transaction: 'GET /',
contexts: {
trace: {
op: 'http.server',
status: 'ok',
},
},
span: container => {
expect(container.items.find(item => item.is_segment)).toMatchObject({
name: 'GET /',
status: 'ok',
attributes: expect.objectContaining({
'sentry.op': { type: 'string', value: 'http.server' },
}),
});
},
})
.start();
runner.makeRequest('get', '/');
await runner.completed();
});

test('creates a transaction with a parametrized route name', async () => {
test('creates a segment span with a parametrized route name', async () => {
const runner = createRunner()
.expect({
transaction: {
transaction: 'GET /hello/:name',
transaction_info: {
source: 'route',
},
contexts: {
trace: {
op: 'http.server',
status: 'ok',
},
},
span: container => {
expect(container.items.find(item => item.is_segment)).toMatchObject({
name: 'GET /hello/:name',
status: 'ok',
attributes: expect.objectContaining({
'sentry.op': { type: 'string', value: 'http.server' },
'sentry.segment.name.source': { type: 'string', value: 'route' },
}),
});
},
})
.start();
Expand All @@ -48,7 +46,7 @@ describe('hono-sdk (Node)', () => {

test('captures an error with the correct mechanism', async () => {
const runner = createRunner()
.ignore('transaction')
.ignore('span')
.expect({
event: {
exception: {
Expand All @@ -71,21 +69,20 @@ describe('hono-sdk (Node)', () => {
await runner.completed();
});

test('creates a transaction with internal_error status when an error occurs', async () => {
test('creates a segment span with error status when an error occurs', async () => {
const runner = createRunner()
.ignore('event')
.expect({
transaction: {
transaction: 'GET /error/:param',
contexts: {
trace: {
op: 'http.server',
status: 'internal_error',
data: expect.objectContaining({
'http.response.status_code': 500,
}),
},
},
span: container => {
expect(container.items.find(item => item.is_segment)).toMatchObject({
name: 'GET /error/:param',
status: 'error',
attributes: expect.objectContaining({
'sentry.op': { type: 'string', value: 'http.server' },
'sentry.status.message': { type: 'string', value: 'internal_error' },
'http.response.status_code': { type: 'integer', value: 500 },
}),
});
},
})
.start();
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: '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,6 @@ import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
traceLifecycle: 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
transport: loggingTransport,
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: process.env.STREAMED === 'true' ? 'stream' : 'static',
traceLifecycle: 'stream',
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 @@ -7,85 +7,67 @@ describe('fastify v5 auto-instrumentation', () => {
});

createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
test('creates transaction with fastify hook, request-handler and manual spans', async () => {
test('creates segment span with fastify hook, request-handler and manual spans', async () => {
const runner = createRunner()
.expect({
transaction: {
transaction: 'GET /test-transaction',
spans: expect.arrayContaining([
expect.objectContaining({
op: 'middleware',
origin: 'auto.http.fastify',
data: expect.objectContaining({
'fastify.type': 'hook',
'sentry.op': 'middleware',
'sentry.origin': 'auto.http.fastify',
}),
}),
// Route-level hooks have no `op`, so the span name falls back to `${hook} - ${handler}`
// using the original hook identifier (not the prefixed `hook.name` attribute).
span: container => {
expect(container.items.find(item => item.is_segment)?.name).toBe('GET /test-transaction');

expect(container.items).toContainEqual(
expect.objectContaining({
description: 'preHandler - routePreHandler',
origin: 'auto.http.fastify',
data: expect.objectContaining({
'fastify.type': 'route-hook',
'hook.callback.name': 'routePreHandler',
'sentry.origin': 'auto.http.fastify',
attributes: expect.objectContaining({
'fastify.type': { type: 'string', value: 'hook' },
'sentry.op': { type: 'string', value: 'middleware' },
'sentry.origin': { type: 'string', value: 'auto.http.fastify' },
}),
}),
);

// Route-level hooks have no `op`, so the span name falls back to `${hook} - ${handler}`
// using the original hook identifier (not the prefixed `hook.name` attribute).
expect(container.items).toContainEqual(
expect.objectContaining({
op: 'handler',
origin: 'auto.http.fastify',
data: expect.objectContaining({
'sentry.op': 'handler',
'sentry.origin': 'auto.http.fastify',
name: 'preHandler - routePreHandler',
attributes: expect.objectContaining({
'fastify.type': { type: 'string', value: 'route-hook' },
'hook.callback.name': { type: 'string', value: 'routePreHandler' },
'sentry.origin': { type: 'string', value: 'auto.http.fastify' },
}),
}),
expect.objectContaining({
description: 'test-span',
origin: 'manual',
}),
expect.objectContaining({
description: 'child-span',
origin: 'manual',
}),
]),
},
})
.start();
runner.makeRequest('get', '/test-transaction');
await runner.completed();
});
);

test('names request handler spans after their route when span streaming is enabled', async () => {
const runner = createRunner()
.withEnv({ STREAMED: 'true' })
.expect({
span: container => {
// The request span and the route handler span are both named after the route.
const handlerSpans = container.items.filter(item => item.attributes['sentry.op']?.value === 'handler');

// The request span and the route handler span.
expect(handlerSpans).toHaveLength(2);
for (const span of handlerSpans) {
expect(span.name).toBe('/test-transaction');
// The name has to stay in step with the attribute it comes from.
expect(span.attributes['http.route']?.value).toBe('/test-transaction');
expect(span.attributes['sentry.origin']?.value).toBe('auto.http.fastify');
}

// Spans of other ops keep their names.
expect(container.items.find(item => item.name === 'preHandler - routePreHandler')).toBeDefined();
expect(container.items).toContainEqual(
expect.objectContaining({
name: 'test-span',
attributes: expect.objectContaining({ 'sentry.origin': { type: 'string', value: 'manual' } }),
}),
);
expect(container.items).toContainEqual(
expect.objectContaining({
name: 'child-span',
attributes: expect.objectContaining({ 'sentry.origin': { type: 'string', value: 'manual' } }),
}),
);
},
})
.start();

await runner.makeRequest('get', '/test-transaction');

runner.makeRequest('get', '/test-transaction');
await runner.completed();
});

test('captures errors thrown in route handlers', async () => {
const runner = createRunner()
.ignore('transaction')
.ignore('span')
.expect({
event: {
exception: {
Expand Down Expand Up @@ -133,7 +115,7 @@ describe('fastify v5 auto-instrumentation', () => {
(createRunner, test) => {
test('shouldHandleError override works', async () => {
const runner = createRunner()
.ignore('transaction')
.ignore('span')
.expect({
event: {
exception: {
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: '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: process.env.STREAMED === 'true' ? 'stream' : 'static',
traceLifecycle: 'stream',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
Expand Down
Loading
Loading