Skip to content

Commit

Permalink
chore(core): add custom domain host to app insights
Browse files Browse the repository at this point in the history
  • Loading branch information
wangsijie committed May 13, 2024
1 parent 1fdd28b commit e479b08
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
22 changes: 19 additions & 3 deletions packages/core/src/utils/request.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type ExceptionTelemetry } from '@logto/app-insights/node';
import { type Context } from 'koa';

// eslint-disable-next-line @typescript-eslint/ban-types
const getRequestIdFromContext = (context: object): string | undefined => {
Expand All @@ -9,13 +10,28 @@ const getRequestIdFromContext = (context: object): string | undefined => {
return undefined;
};

const getHostFromContext = (context: Context): string | undefined => {
if ('host' in context.headers && typeof context.headers.host === 'string') {
return context.headers.host;
}

return undefined;
};

// eslint-disable-next-line @typescript-eslint/ban-types
export const buildAppInsightsTelemetry = (context: object): Partial<ExceptionTelemetry> => {
const requestId = getRequestIdFromContext(context);
// eslint-disable-next-line no-restricted-syntax
const host = getHostFromContext(context as Context);

if (requestId) {
return { properties: { requestId } };
if (!requestId && !host) {
return {};
}

return {};
return {
properties: {
...(requestId ? { requestId } : {}),
...(host ? { host } : {}),
},
};
};
1 change: 1 addition & 0 deletions packages/core/src/utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const createContextWithRouteParameters = (
path: ctx.path,
URL: ctx.URL,
params: {},
headers: {},
router: new Router(),
_matchedRoute: undefined,
_matchedRouteName: undefined,
Expand Down

0 comments on commit e479b08

Please sign in to comment.