-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathmiddlewareHandlers.ts
More file actions
50 lines (43 loc) · 1.55 KB
/
middlewareHandlers.ts
File metadata and controls
50 lines (43 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import {
getActiveSpan,
getClient,
getDefaultIsolationScope,
getIsolationScope,
getRootSpan,
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
updateSpanName,
winterCGRequestToRequestData,
} from '@sentry/core';
import type { Context } from 'hono';
import { routePath } from 'hono/route';
import { hasFetchEvent } from '../utils/hono-context';
/**
* Request handler for Hono framework
*/
export function requestHandler(context: Context): void {
const defaultScope = getDefaultIsolationScope();
const currentIsolationScope = getIsolationScope();
const isolationScope = defaultScope === currentIsolationScope ? defaultScope : currentIsolationScope;
isolationScope.setSDKProcessingMetadata({
normalizedRequest: winterCGRequestToRequestData(hasFetchEvent(context) ? context.event.request : context.req.raw),
});
}
/**
* Response handler for Hono framework
*/
export function responseHandler(context: Context): void {
const activeSpan = getActiveSpan();
if (activeSpan) {
activeSpan.updateName(`${context.req.method} ${routePath(context)}`);
activeSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
const rootSpan = getRootSpan(activeSpan);
updateSpanName(rootSpan, `${context.req.method} ${routePath(context)}`);
rootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
}
getIsolationScope().setTransactionName(`${context.req.method} ${routePath(context)}`);
if (context.error) {
getClient()?.captureException(context.error, {
mechanism: { handled: false, type: 'auto.faas.hono.error_handler' },
});
}
}