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

feat(core): report oidc exceptions to the appInsights #5978

Merged
merged 1 commit into from
Jun 3, 2024
Merged
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
feat(core): report oidc exceptions to the appInsights
report oidc exceptions to the appInsights
  • Loading branch information
simeng-li committed Jun 3, 2024
commit 9721ca3a227e7eab76fb36345c07e980eeea5dda
5 changes: 5 additions & 0 deletions packages/core/src/middleware/koa-oidc-error-handler.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { appInsights } from '@logto/app-insights/node';
import { condObject, isObject } from '@silverhand/essentials';
import i18next from 'i18next';
import type { Middleware } from 'koa';
Expand All @@ -6,6 +7,7 @@ import { z } from 'zod';

import { EnvSet } from '#src/env-set/index.js';
import { getConsoleLogFromContext } from '#src/utils/console.js';
import { buildAppInsightsTelemetry } from '#src/utils/request.js';

/**
* Supplementary URIs for oidc-provider errors.
Expand Down Expand Up @@ -88,6 +90,9 @@ export default function koaOidcErrorHandler<StateT, ContextT>(): Middleware<Stat
throw error;
}

// Report oidc exceptions to ApplicationInsights
void appInsights.trackException(error, buildAppInsightsTelemetry(ctx));

// Mimic oidc-provider's error handling, thus we can use the unified logic below.
// See https://github.com/panva/node-oidc-provider/blob/37d0a6cfb3c618141a44cbb904ce45659438f821/lib/shared/error_handler.js
ctx.status = error.statusCode || 500;
Expand Down
Loading