mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
refactor(server): add debug info on global exception log (#10118)
before  after 
This commit is contained in:
@@ -84,16 +84,17 @@ export function parseCookies(
|
||||
* Request type
|
||||
*
|
||||
* @description
|
||||
* - `req`: http request
|
||||
* - `graphql`: graphql request
|
||||
* - `http`: http request
|
||||
* - `ws`: websocket request
|
||||
* - `se`: server event
|
||||
* - `job`: cron job
|
||||
* - `rpc`: rpc request
|
||||
*/
|
||||
export type RequestType = 'req' | 'ws' | 'se' | 'job' | 'rpc';
|
||||
export type RequestType = GqlContextType | 'se' | 'job';
|
||||
|
||||
export function genRequestId(type: RequestType) {
|
||||
return `${AFFiNE.flavor.type}:${type}-${randomUUID()}`;
|
||||
return `${AFFiNE.flavor.type}:${type}/${randomUUID()}`;
|
||||
}
|
||||
|
||||
export function getOrGenRequestId(type: RequestType) {
|
||||
@@ -101,3 +102,16 @@ export function getOrGenRequestId(type: RequestType) {
|
||||
// but it can be lost in unexpected scenarios, such as unit tests, where it is automatically generated.
|
||||
return ClsServiceManager.getClsService()?.getId() ?? genRequestId(type);
|
||||
}
|
||||
|
||||
export function getRequestIdFromRequest(req: Request, type: RequestType) {
|
||||
const traceContext = req.headers['x-cloud-trace-context'] as string;
|
||||
const traceId = traceContext ? traceContext.split('/', 1)[0] : undefined;
|
||||
if (traceId) return traceId;
|
||||
return genRequestId(type);
|
||||
}
|
||||
|
||||
export function getRequestIdFromHost(host: ArgumentsHost) {
|
||||
const type = host.getType<GqlContextType>();
|
||||
const req = getRequestFromHost(host);
|
||||
return getRequestIdFromRequest(req, type);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user