(app: Hono<E>)
| 30 | * Idempotent: safe to call multiple times on the same instance. |
| 31 | */ |
| 32 | export function patchAppRequest<E extends Env>(app: Hono<E>): void { |
| 33 | if (getOriginalFunction(app.request as unknown as WrappedFunction)) { |
| 34 | DEBUG_BUILD && debug.log('[hono] app.request already patched — skipping.'); |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | const originalRequest = app.request; |
| 39 | |
| 40 | app.request = new Proxy(originalRequest, { |
| 41 | apply(_target, thisArg, args: [string | Request | URL, RequestInit?, ...unknown[]]) { |
| 42 | const [input, requestInit, ...rest] = args; |
| 43 | |
| 44 | if (!getActiveSpan()) { |
| 45 | return Reflect.apply(_target, thisArg, args); |
| 46 | } |
| 47 | |
| 48 | let method = requestInit?.method ?? (input instanceof Request ? input.method : 'GET'); |
| 49 | method = method.toUpperCase(); |
| 50 | |
| 51 | const path = extractPathname(input); |
| 52 | |
| 53 | return startSpan( |
| 54 | { |
| 55 | name: `${method} ${path}`, |
| 56 | op: INTERNAL_REQUEST_OP, |
| 57 | onlyIfParent: true, |
| 58 | attributes: { |
| 59 | [SEMANTIC_ATTRIBUTE_SENTRY_OP]: INTERNAL_REQUEST_OP, |
| 60 | [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: INTERNAL_REQUEST_ORIGIN, |
| 61 | }, |
| 62 | }, |
| 63 | () => Reflect.apply(_target, thisArg, [input, requestInit, ...rest]), |
| 64 | ); |
| 65 | }, |
| 66 | get(target, prop, receiver) { |
| 67 | if (prop === '__sentry_original__') { |
| 68 | return originalRequest; |
| 69 | } |
| 70 | return Reflect.get(target, prop, receiver); |
| 71 | }, |
| 72 | }); |
| 73 | |
| 74 | DEBUG_BUILD && debug.log('[hono] Patched app.request for internal dispatch tracing.'); |
| 75 | } |
no test coverage detected