-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathutil.ts
More file actions
53 lines (48 loc) · 1.78 KB
/
util.ts
File metadata and controls
53 lines (48 loc) · 1.78 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
51
52
53
/**
* Gets the op name for a request based on whether it's a loader or action request.
* @param pathName The URL pathname to check
* @param requestMethod The HTTP request method
*/
export function getOpName(pathName: string, requestMethod: string): string {
return isLoaderRequest(pathName, requestMethod)
? 'function.react_router.loader'
: isActionRequest(pathName, requestMethod)
? 'function.react_router.action'
: 'function.react_router';
}
/**
* Gets the span name for a request based on whether it's a loader or action request.
* @param pathName The URL pathname to check
* @param requestMethod The HTTP request method
*/
export function getSpanName(pathName: string, requestMethod: string): string {
return isLoaderRequest(pathName, requestMethod)
? 'Executing Server Loader'
: isActionRequest(pathName, requestMethod)
? 'Executing Server Action'
: 'Unknown Data Request';
}
/**
* Checks if the request is a server loader request
* @param pathname The URL pathname to check
* @param requestMethod The HTTP request method
*/
export function isLoaderRequest(pathname: string, requestMethod: string): boolean {
return isDataRequest(pathname) && requestMethod === 'GET';
}
/**
* Checks if the request is a server action request
* @param pathname The URL pathname to check
* @param requestMethod The HTTP request method
*/
export function isActionRequest(pathname: string, requestMethod: string): boolean {
return isDataRequest(pathname) && requestMethod === 'POST';
}
/**
* Checks if the request is a react-router data request
* @param pathname The URL pathname to check
*/
export function isDataRequest(pathname: string): boolean {
return pathname.endsWith('.data');
}
export const SEMANTIC_ATTRIBUTE_SENTRY_OVERWRITE = 'sentry.overwrite-route';