0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

chore(core): add custom domain host to app insights (#5852)

This commit is contained in:
wangsijie 2024-05-13 21:04:18 +08:00 committed by GitHub
parent 1fdd28b2b3
commit 062d21764c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 4 deletions

View file

@ -1,21 +1,33 @@
import { type ExceptionTelemetry } from '@logto/app-insights/node'; import { type ExceptionTelemetry } from '@logto/app-insights/node';
import { type Context } from 'koa';
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types
const getRequestIdFromContext = (context: object): string | undefined => { const getRequestIdFromContext = (context: object): string | undefined => {
if ('requestId' in context && typeof context.requestId === 'string') { if ('requestId' in context && typeof context.requestId === 'string') {
return context.requestId; return context.requestId;
} }
};
return undefined; const getHostFromContext = (context: Context): string | undefined => {
if ('host' in context.headers && typeof context.headers.host === 'string') {
return context.headers.host;
}
}; };
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types
export const buildAppInsightsTelemetry = (context: object): Partial<ExceptionTelemetry> => { export const buildAppInsightsTelemetry = (context: object): Partial<ExceptionTelemetry> => {
const requestId = getRequestIdFromContext(context); const requestId = getRequestIdFromContext(context);
// eslint-disable-next-line no-restricted-syntax
const host = getHostFromContext(context as Context);
if (requestId) { if (!requestId && !host) {
return { properties: { requestId } }; return {};
} }
return {}; return {
properties: {
...(requestId ? { requestId } : {}),
...(host ? { host } : {}),
},
};
}; };

View file

@ -97,6 +97,7 @@ export const createContextWithRouteParameters = (
path: ctx.path, path: ctx.path,
URL: ctx.URL, URL: ctx.URL,
params: {}, params: {},
headers: {},
router: new Router(), router: new Router(),
_matchedRoute: undefined, _matchedRoute: undefined,
_matchedRouteName: undefined, _matchedRouteName: undefined,