mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
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:
parent
6794a77e45
commit
da79285e7f
@ -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, {
|
||||
|
||||
@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user