add opentelemetry log function and telemetry for primary_email_auth_enabled usage (#523)

Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
This commit is contained in:
Moritz Schneider 2025-03-10 08:46:36 -07:00 committed by GitHub
parent 6794a77e45
commit da79285e7f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import { PrismaTransaction } from "@/lib/types";
import { sendTeamMembershipDeletedWebhook, sendUserCreatedWebhook, sendUserDeletedWebhook, sendUserUpdatedWebhook } from "@/lib/webhooks";
import { RawQuery, prismaClient, rawQuery, retryTransaction } from "@/prisma-client";
import { createCrudHandlers } from "@/route-handlers/crud-handler";
import { log } from "@/utils/telemetry";
import { runAsynchronouslyAndWaitUntil } from "@/utils/vercel";
import { BooleanTrue, Prisma } from "@prisma/client";
import { KnownErrors } from "@stackframe/stack-shared";
@ -536,6 +537,10 @@ export const usersCrudHandlers = createLazyProxy(() => createCrudHandlers(usersC
};
},
onCreate: async ({ auth, data }) => {
log("create_user_endpoint_primaryAuthEnabled", {
value: data.primary_email_auth_enabled,
email: data.primary_email ?? undefined,
});
const result = await retryTransaction(async (tx) => {
const passwordHash = await getPasswordHashFromData(data);
await checkAuthData(tx, {

View File

@ -1,5 +1,5 @@
import { AttributeValue, Span, trace } from "@opentelemetry/api";
import { Attributes, AttributeValue, Span, trace } from "@opentelemetry/api";
import { StackAssertionError } from "@stackframe/stack-shared/dist/utils/errors";
const tracer = trace.getTracer('stack-backend');
export function withTraceSpan<P extends any[], T>(optionsOrDescription: string | { description: string, attributes?: Record<string, AttributeValue> }, fn: (...args: P) => Promise<T>): (...args: P) => Promise<T> {
@ -24,6 +24,11 @@ export async function traceSpan<T>(optionsOrDescription: string | { description:
});
}
export function log(message: string, ...args: any[]) {
console.log(`[${new Date().toISOString()}] ${message}`, ...args);
export function log(message: string, attributes: Attributes) {
const span = trace.getActiveSpan();
if (span) {
span.addEvent(message, attributes);
} else {
throw new StackAssertionError('No active span found');
}
}