Skip to content

Commit aa5fc6a

Browse files
committed
feat(bun): Instrument http module on bun
1 parent bada653 commit aa5fc6a

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

packages/bun/src/sdk.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { channelIntegrations, isOrchestrionInjected } from '@sentry/server-utils
2626
import { bunServerIntegration } from './integrations/bunserver';
2727
import { makeFetchTransport } from './transports';
2828
import type { BunOptions } from './types';
29+
import { bunHttpServerIntegration } from './integrations/bunHttpServer';
2930

3031
/**
3132
* The orchestrion channel-subscriber integrations, listening on the diagnostics
@@ -88,6 +89,7 @@ export function getDefaultIntegrationsWithoutPerformance(): Integration[] {
8889
processSessionIntegration(),
8990
// Bun Specific
9091
bunServerIntegration(),
92+
bunHttpServerIntegration(),
9193
];
9294
}
9395

packages/bun/test/integrations/bunHttpServer.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import http from 'node:http';
2-
import { getCurrentScope } from '@sentry/core';
2+
import { getTraceData } from '@sentry/core';
33
import { beforeAll, describe, expect, test } from 'bun:test';
4-
import { init } from '../../src';
5-
import { instrumentBunHttpServer } from '../../src/integrations/bunHttpServer';
4+
import { bunHttpServerIntegration, init } from '../../src';
65

76
async function startServer(handler: http.RequestListener): Promise<{ port: number; close: () => Promise<void> }> {
87
const server = http.createServer(handler);
@@ -15,23 +14,27 @@ async function startServer(handler: http.RequestListener): Promise<{ port: numbe
1514
};
1615
}
1716

17+
/** Read the trace id the SDK would propagate for the current request. Works in both OTel and non-OTel modes. */
18+
function currentTraceId(): string | undefined {
19+
return getTraceData()['sentry-trace']?.split('-')[0];
20+
}
21+
1822
describe('Bun HTTP Server Integration', () => {
1923
beforeAll(() => {
2024
init({
2125
dsn: 'https://public@dsn.ingest.sentry.io/1337',
2226
tracesSampleRate: 0,
2327
// Avoid sending anything to Sentry
2428
transport: () => ({ send: async () => ({}), flush: async () => true }),
29+
integrations: [bunHttpServerIntegration({ spans: false })],
2530
});
26-
// Only performs isolation + trace reset, no span creation (Next.js emits its own spans).
27-
instrumentBunHttpServer({ spans: false });
2831
});
2932

3033
test('isolates each incoming request with a distinct trace id', async () => {
31-
const traceIds: string[] = [];
34+
const traceIds: Array<string | undefined> = [];
3235

3336
const { port, close } = await startServer((_req, res) => {
34-
traceIds.push(getCurrentScope().getPropagationContext().traceId);
37+
traceIds.push(currentTraceId());
3538
res.end('ok');
3639
});
3740

@@ -51,7 +54,7 @@ describe('Bun HTTP Server Integration', () => {
5154
let observedTraceId: string | undefined;
5255

5356
const { port, close } = await startServer((_req, res) => {
54-
observedTraceId = getCurrentScope().getPropagationContext().traceId;
57+
observedTraceId = currentTraceId();
5558
res.end('ok');
5659
});
5760

0 commit comments

Comments
 (0)