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

[#IOPID-1453] Add event for Zendesk jwt errors #1101

Merged
merged 1 commit into from
Feb 1, 2024
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
9 changes: 6 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,8 @@ export async function newApp({
allowZendeskIPSourceRange,
PROFILE_SERVICE,
TOKEN_SERVICE,
authMiddlewares.bearerZendesk
authMiddlewares.bearerZendesk,
appInsightsClient
);
return { acsController, app };
},
Expand Down Expand Up @@ -953,11 +954,13 @@ function registerZendeskRoutes(
profileService: ProfileService,
tokenService: TokenService,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
bearerZendeskTokenAuth: any
bearerZendeskTokenAuth: any,
appInsightsClient?: appInsights.TelemetryClient
): void {
const zendeskController: ZendeskController = new ZendeskController(
profileService,
tokenService
tokenService,
appInsightsClient
gquadrati marked this conversation as resolved.
Show resolved Hide resolved
);

app.post(
Expand Down
17 changes: 16 additions & 1 deletion src/controllers/zendeskController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* to zendesk support
*/

import * as appInsights from "applicationinsights";
import * as express from "express";
import * as TE from "fp-ts/TaskEither";
import * as E from "fp-ts/Either";
Expand All @@ -21,6 +22,7 @@ import {
import ProfileService from "src/services/profileService";
import * as t from "io-ts/lib";
import { pipe } from "fp-ts/lib/function";
import { sha256 } from "@pagopa/io-functions-commons/dist/src/utils/crypto";
import { ZendeskToken } from "../../generated/zendesk/ZendeskToken";
import {
JWT_ZENDESK_SUPPORT_TOKEN_EXPIRATION,
Expand All @@ -43,7 +45,8 @@ type ValidZendeskProfile = t.TypeOf<typeof ValidZendeskProfile>;
export default class ZendeskController {
constructor(
private readonly profileService: ProfileService,
private readonly tokenService: TokenService
private readonly tokenService: TokenService,
private readonly appInsightsTelemetryClient?: appInsights.TelemetryClient
) {}

public readonly getZendeskSupportToken = (
Expand Down Expand Up @@ -92,6 +95,18 @@ export default class ZendeskController {
jwt: token,
})
),
TE.mapLeft((err) => {
gquadrati marked this conversation as resolved.
Show resolved Hide resolved
this.appInsightsTelemetryClient?.trackEvent({
name: "appbackend.zendesk.error",
properties: {
fiscal_code: sha256(user.fiscal_code),
message: err.detail,
},
tagOverrides: { samplingEnabled: "false" },
});

return err;
}),
TE.map(ResponseSuccessJson),
TE.toUnion
)()
Expand Down
Loading