Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
chore(core): add custom domain host to app insights
  • Loading branch information
wangsijie committed May 13, 2024
commit 95dd58098877d6f4aaeb730e7b2a3fb6168cb257
20 changes: 16 additions & 4 deletions packages/core/src/utils/request.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
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 => {
if ('requestId' in context && typeof context.requestId === 'string') {
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
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
Loading