feat: enhance API v2 exception filters with user context for improved Axiom observability (#22157)
* feat: enhance API v2 exception filters with user context for improved Axiom observability - Add extractUserContext utility to safely extract user/org/team context from request - Enhance all 5 exception filters (HTTP, TRPC, Prisma, Zod, Calendar) with user context - Include userId, userEmail, organizationId, teamId in Axiom logs when available - Improve observability for debugging and monitoring authenticated requests Co-Authored-By: [email protected] <[email protected]> * chore: update yarn.lock from lint-staged hooks Co-Authored-By: [email protected] <[email protected]> * fix: use request.organization instead of request.organizationId - Address GitHub comment feedback from ThyMinimalDev - Extract organization ID from organization object for consistency - Follows same pattern as user and team extraction Co-Authored-By: [email protected] <[email protected]> * fix: revert to using request.organizationId as requested in GitHub comment - Change back from request.organization to request.organizationId - This aligns with how auth strategies actually populate the request object - Addresses GitHub comment from ThyMinimalDev Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]> Co-authored-by: Morgan <[email protected]>
This commit is contained in:
6 files changed
+49
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import { Request } from "express";
|
||||
|
||||
import { Team } from "@calcom/prisma/client";
|
||||
|
||||
import { ApiAuthGuardUser } from "../modules/auth/strategies/api-auth/api-auth.strategy";
|
||||
|
||||
export interface UserContext {
|
||||
userId?: number;
|
||||
userEmail?: string;
|
||||
organizationId?: number;
|
||||
teamId?: number;
|
||||
}
|
||||
|
||||
export function extractUserContext(request: Request): UserContext {
|
||||
const context: UserContext = {};
|
||||
|
||||
const user = (request as any).user as ApiAuthGuardUser | undefined;
|
||||
if (user) {
|
||||
context.userId = user.id;
|
||||
context.userEmail = user.email;
|
||||
}
|
||||
|
||||
const organizationId = (request as any).organizationId as number | undefined;
|
||||
if (organizationId) {
|
||||
context.organizationId = organizationId;
|
||||
}
|
||||
|
||||
const team = (request as any).team as Team | undefined;
|
||||
if (team) {
|
||||
context.teamId = team.id;
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
Reference in new issue
Block a user