Skip to content

Commit 2c2d1bd

Browse files
committed
fixes
1 parent e1523cd commit 2c2d1bd

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

packages/bun/src/integrations/bunHttpServer.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { errorMonitor } from 'node:events';
12
import http from 'node:http';
23
import https from 'node:https';
3-
import type { IntegrationFn } from '@sentry/core';
4+
import type { HttpIncomingMessage, HttpServerResponse, IntegrationFn, Span } from '@sentry/core';
45
import { defineIntegration, getHttpServerSubscriptions, HTTP_ON_SERVER_REQUEST } from '@sentry/core';
56

67
const INTEGRATION_NAME = 'BunHttpServer' as const;
@@ -43,6 +44,31 @@ interface BunHttpServerOptions {
4344
* @default 'medium'
4445
*/
4546
maxRequestBodySize?: 'none' | 'small' | 'medium' | 'always';
47+
48+
/**
49+
* Do not capture spans for incoming HTTP requests to URLs where the given callback returns `true`.
50+
*
51+
* The `urlPath` param consists of the URL path and query string (if any) of the incoming request.
52+
*/
53+
ignoreIncomingRequests?: (urlPath: string, request: HttpIncomingMessage) => boolean;
54+
55+
/**
56+
* Whether to automatically ignore common static asset requests like favicon.ico, robots.txt, etc.
57+
*
58+
* @default true
59+
*/
60+
ignoreStaticAssets?: boolean;
61+
62+
/**
63+
* A hook that can be used to mutate the span for incoming requests.
64+
* This is triggered after the span is created, but before it is recorded.
65+
*/
66+
onSpanCreated?: (span: Span, request: HttpIncomingMessage, response: HttpServerResponse) => void;
67+
68+
/**
69+
* A hook that can be used to mutate the span one last time when the response is finished.
70+
*/
71+
onSpanEnd?: (span: Span, request: HttpIncomingMessage, response: HttpServerResponse) => void;
4672
}
4773

4874
let hasPatched = false;
@@ -95,7 +121,12 @@ export function instrumentBunHttpServer(options: BunHttpServerOptions = {}): voi
95121
return;
96122
}
97123

98-
const { [HTTP_ON_SERVER_REQUEST]: onServerRequest } = getHttpServerSubscriptions(options);
124+
const { [HTTP_ON_SERVER_REQUEST]: onServerRequest } = getHttpServerSubscriptions({
125+
...options,
126+
// Pass the real `errorMonitor` symbol so core observes `'error'` events without consuming
127+
// them — otherwise it would swallow errors before they reach user-supplied `'error'` handlers.
128+
errorMonitor,
129+
});
99130

100131
// Track which servers we have already handed to core, so we instrument each server exactly once.
101132
// After core instruments a server it installs its own `emit` on the instance, which shadows this

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import http from 'node:http';
22
import { getActiveSpan, getTraceData, spanToJSON } from '@sentry/core';
33
import { beforeAll, describe, expect, test } from 'bun:test';
4-
import { bunHttpServerIntegration, init } from '../../src';
4+
import { init } from '../../src';
55

66
async function startServer(handler: http.RequestListener): Promise<{ port: number; close: () => Promise<void> }> {
77
const server = http.createServer(handler);

0 commit comments

Comments
 (0)