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
17 changes: 17 additions & 0 deletions dev-packages/e2e-tests/test-applications/hono-4/src/routes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { logger } from '@sentry/core';
import { type Hono as HonoType, Hono } from 'hono';
import { HTTPException } from 'hono/http-exception';
import { failingMiddleware, middlewareA, middlewareB, namedMiddleware } from './middleware';
Expand All @@ -15,6 +16,22 @@ export function addRoutes(app: HonoType<{ Bindings?: { E2E_TEST_DSN: string } }>
return c.json({ paramId: c.req.param('paramId') });
});

app.get('/test-outgoing-fetch', c => {
return fetch(new URL('/test-trace-headers', c.req.url));
});

app.get('/test-trace-headers', c => {
return c.json({
sentryTrace: c.req.header('sentry-trace'),
baggage: c.req.header('baggage'),
});
});

app.get('/test-log', c => {
logger.info('Hono server log', { route: '/test-log' });
return c.text('ok');
});

app.get('/error/:cause', c => {
throw new Error('This is a test error for Sentry!', {
cause: c.req.param('cause'),
Expand Down
24 changes: 24 additions & 0 deletions dev-packages/e2e-tests/test-applications/hono-4/tests/logs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect, test } from '@playwright/test';
import { waitForEnvelopeItem, waitForStreamedSpan } from '@sentry-internal/test-utils';
import type { SerializedLogContainer } from '@sentry/core';
import { APP_NAME } from './constants';

test('sends a structured log correlated with the request trace', async ({ baseURL }) => {
const segmentPromise = waitForStreamedSpan(APP_NAME, span => span.is_segment && span.name === 'GET /test-log');
const logPromise = waitForEnvelopeItem(
APP_NAME,
([header, body]) =>
header.type === 'log' && (body as SerializedLogContainer).items.some(log => log.body === 'Hono server log'),
);

const response = await fetch(`${baseURL}/test-log`);
expect(response.status).toBe(200);

const [segment, [, body]] = await Promise.all([segmentPromise, logPromise]);
const log = (body as SerializedLogContainer).items.find(item => item.body === 'Hono server log');
expect(log).toMatchObject({
level: 'info',
trace_id: segment.trace_id,
attributes: { route: { type: 'string', value: '/test-log' } },
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, test } from '@playwright/test';
import { waitForStreamedSpan, getSpanOp } from '@sentry-internal/test-utils';
import { randomBytes } from 'node:crypto';
import { APP_NAME, RUNTIME, type Runtime } from './constants';

const anyString = expect.any(String) as unknown;
Expand Down Expand Up @@ -72,6 +73,48 @@ const CONN_INFO: Record<Runtime, { added: Record<string, unknown>; baseline: Rec

const connInfo = CONN_INFO[RUNTIME];

test('continues the trace of an incoming request', async ({ baseURL }) => {
const traceId = randomBytes(16).toString('hex');
const parentSpanId = randomBytes(8).toString('hex');
const segmentPromise = waitForStreamedSpan(
APP_NAME,
span => span.is_segment && span.name === 'GET /test-param/:paramId' && span.trace_id === traceId,
);

const response = await fetch(`${baseURL}/test-param/continued`, {
headers: {
'sentry-trace': `${traceId}-${parentSpanId}-1`,
baggage: `sentry-trace_id=${traceId},sentry-public_key=username,sentry-sampled=true`,
},
});
expect(response.status).toBe(200);

expect(await segmentPromise).toMatchObject({ trace_id: traceId, parent_span_id: parentSpanId });
});

test('propagates the trace to an outgoing fetch request', async ({ baseURL }) => {
const downstreamUrl = `${baseURL}/test-trace-headers`;
const segmentPromise = waitForStreamedSpan(
APP_NAME,
span => span.is_segment && span.name === 'GET /test-outgoing-fetch',
);
const fetchSpanPromise = waitForStreamedSpan(
APP_NAME,
span => getSpanOp(span) === 'http.client' && span.attributes['url.full']?.value === downstreamUrl,
);

const response = await fetch(`${baseURL}/test-outgoing-fetch`);
expect(response.status).toBe(200);
const headers = await response.json();

const [segment, fetchSpan] = await Promise.all([segmentPromise, fetchSpanPromise]);
expect(fetchSpan.trace_id).toBe(segment.trace_id);
expect(fetchSpan.parent_span_id).toBe(segment.span_id);
expect(headers.sentryTrace).toBe(`${segment.trace_id}-${fetchSpan.span_id}-1`);
expect(headers.baggage).toContain(`sentry-trace_id=${segment.trace_id}`);
expect(headers.baggage).toContain('sentry-environment=qa');
});

test('sends a span for the index route', async ({ baseURL }) => {
const segmentPromise = waitForStreamedSpan(
APP_NAME,
Expand Down
Loading