Skip to content

Commit

Permalink
Capture otel metrics for OAuth errors and add logging to stderr (#3437)
Browse files Browse the repository at this point in the history
* Add new counters

* Increment error counter for authorize

* Log authorize errors to `stderr`

* Minor formatting

* Add metrics and error logging for token handler

* New counter for idp response path

* Capture metrics for remaining handlers

* Removing logging from npm, let service do it

* Log service error in oidc/saml response paths

* Cleanup

* Simplify metric name

* Use renamed metric and set protocol attribute

* Sync lock file

* Tweak error message

* Add protocol and login_type tags to authorize and response metrics

* Log error for oAuth redirect error responses

* Add protocol and login_type to error metrics inside token/userinfo handlers

* Set attributes earlier in the flow if possible

* Set protocol early in the flow

* Revert lock file changes

* Revert lock file changes

* print err instead of just message

* error -> err in catch blocks for consistency

---------

Co-authored-by: Deepak Prabhakara <[email protected]>
  • Loading branch information
niwsa and deepakprabhakara authored Dec 25, 2024
1 parent b7c37c1 commit 3f586ef
Show file tree
Hide file tree
Showing 24 changed files with 282 additions and 178 deletions.
4 changes: 2 additions & 2 deletions ee/branding/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
res.setHeader('Allow', 'GET');
res.status(405).json({ error: { message: `Method ${method} Not Allowed` } });
}
} catch (error: any) {
const { message, statusCode = 500 } = error;
} catch (err: any) {
const { message, statusCode = 500 } = err;

res.status(statusCode).json({ error: { message } });
}
Expand Down
4 changes: 2 additions & 2 deletions ee/identity-federation/api/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const handleGET = async (req: NextApiRequest, res: NextApiResponse) => {
}

res.status(200).send(metadata.xml);
} catch (error: any) {
const { message, statusCode = 500 } = error;
} catch (err: any) {
const { message, statusCode = 500 } = err;

return res.status(statusCode).json({
error: { message },
Expand Down
4 changes: 2 additions & 2 deletions ee/product/api/[productId].ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
res.setHeader('Allow', 'GET,DELETE');
res.status(405).json({ error: { message: `Method ${req.method} Not Allowed` } });
}
} catch (error: any) {
const { message, statusCode = 500 } = error;
} catch (err: any) {
const { message, statusCode = 500 } = err;
res.status(statusCode).json({ error: { message } });
}
};
Expand Down
4 changes: 2 additions & 2 deletions ee/product/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
res.setHeader('Allow', 'POST');
res.status(405).json({ error: { message: `Method ${req.method} Not Allowed` } });
}
} catch (error: any) {
const { message, statusCode = 500 } = error;
} catch (err: any) {
const { message, statusCode = 500 } = err;
res.status(statusCode).json({ error: { message } });
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export const EditIdentityFederationApp = ({
await fetch(urls.deleteApp, { method: 'DELETE', headers: defaultHeaders });
setDelModalVisible(false);
onDelete?.();
} catch (error: any) {
onError?.(error);
} catch (err: any) {
onError?.(err);
}
};

Expand Down
6 changes: 3 additions & 3 deletions lib/api/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export const defaultHandler = async (req: NextApiRequest, res: NextApiResponse,
// Call the handler
await handler(req, res);
return;
} catch (error: any) {
const message = error.message || 'Internal Server Error';
const status = error.statusCode || 500;
} catch (err: any) {
const message = err.message || 'Internal Server Error';
const status = err.statusCode || 500;

console.error(`${req.method} ${req.url} - ${status} - ${message}`);

Expand Down
4 changes: 2 additions & 2 deletions npm/src/controller/connection/saml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ async function fetchMetadata(resource: string) {
timeout: 8000,
});
return response.data;
} catch (error: any) {
throw new JacksonError("Couldn't fetch XML data", error.response?.status || 400);
} catch (err: any) {
throw new JacksonError("Couldn't fetch XML data", err.response?.status || 400);
}
}

Expand Down
Loading

0 comments on commit 3f586ef

Please sign in to comment.