🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
chore: move web-ee logic from console.log to logger (#3400)
Steffen Schmitze8561fb10544
diff --git a/web/src/ee/features/billing/server/stripeWebhookApiHandler.ts b/web/src/ee/features/billing/server/stripeWebhookApiHandler.tsindex 92ed431498..97783a908b 100644--- a/web/src/ee/features/billing/server/stripeWebhookApiHandler.ts+++ b/web/src/ee/features/billing/server/stripeWebhookApiHandler.ts@@ -8,7 +8,7 @@ import { prisma } from "@langfuse/shared/src/db";import { stripeClient } from "@/src/ee/features/billing/utils/stripe";import type Stripe from "stripe";import { CloudConfigSchema, parseDbOrg } from "@langfuse/shared";-import { traceException, redis } from "@langfuse/shared/src/server";+import { traceException, redis, logger } from "@langfuse/shared/src/server";import { ApiAuthService } from "@/src/features/public-api/server/apiAuth";/*@@ -23,14 +23,14 @@ export async function stripeWebhookApiHandler(req: NextRequest) {);if (!env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION || !stripeClient) {- console.error("[Stripe Webhook] Endpoint only available in Langfuse Cloud");+ logger.error("[Stripe Webhook] Endpoint only available in Langfuse Cloud");return NextResponse.json({ message: "Stripe webhook endpoint only available in Langfuse Cloud" },{ status: 500 },);}if (!env.STRIPE_WEBHOOK_SIGNING_SECRET) {- console.error("[Stripe Webhook] Stripe webhook signing key not found");+ logger.error("[Stripe Webhook] Stripe webhook signing key not found");return NextResponse.json({ message: "Stripe secret key not found" },{ status: 500 },@@ -39,9 +39,8 @@ export async function stripeWebhookApiHandler(req: NextRequest) {// check if the request is signed by stripeconst sig = req.headers.get("stripe-signature");- console.log("[Stripe Webhook] Signature", sig);if (!sig) {- console.error("[Stripe Webhook] No signature");+ logger.error("[Stripe Webhook] No signature");return NextResponse.json({ message: "No signature" }, { status: 400 });}let event: Stripe.Event;@@ -52,7 +51,7 @@ export async function stripeWebhookApiHandler(req: NextRequest) {env.STRIPE_WEBHOOK_SIGNING_SECRET,);} catch (err) {- console.error("[Stripe Webhook] Error verifying signature", err);+ logger.error("[Stripe Webhook] Error verifying signature", err);return NextResponse.json({ message: `Webhook Error: ${err}` },{ status: 400 },@@ -64,32 +63,29 @@ export async function stripeWebhookApiHandler(req: NextRequest) {case "customer.subscription.created":// update the active product id on the organization linked to the subscription + customer and subscription id (if null or same)const subscription = event.data.object;- console.log(- "[Stripe Webhook] Start customer.subscription.created",- subscription,- );+ logger.info("[Stripe Webhook] Start customer.subscription.created", {+ payload: subscription,+ });await handleSubscriptionChanged(subscription, "created");break;case "customer.subscription.updated":// update the active product id on the organization linked to the subscription + customer and subscription id (if null or same)const updatedSubscription = event.data.object;- console.log(- "[Stripe Webhook] Start customer.subscription.updated",- updatedSubscription,- );+ logger.info("[Stripe Webhook] Start customer.subscription.updated", {+ payload: updatedSubscription,+ });await handleSubscriptionChanged(updatedSubscription, "updated");break;case "customer.subscription.deleted":// remove the active product id on the organization linked to the subscription + subscription, keep customer idconst deletedSubscription = event.data.object;- console.log(- "[Stripe Webhook] Start customer.subscription.deleted",- deletedSubscription,- );+ logger.info("[Stripe Webhook] Start customer.subscription.deleted", {+ payload: deletedSubscription,+ });await handleSubscriptionChanged(deletedSubscription, "deleted");break;default:- console.log(`Unhandled event type ${event.type}`);+ logger.warn(`Unhandled event type ${event.type}`);}return NextResponse.json({ received: true }, { status: 200 });@@ -107,7 +103,7 @@ async function handleSubscriptionChanged(limit: 1,});if (!checkoutSessionsResponse || checkoutSessionsResponse.data.length !== 1) {- console.error("[Stripe Webhook] No checkout session found");+ logger.error("[Stripe Webhook] No checkout session found");return;}const checkoutSession = checkoutSessionsResponse.data[0];@@ -115,14 +111,14 @@ async function handleSubscriptionChanged(// the client reference is passed to the stripe checkout session via the pricing pageconst clientReference = checkoutSession.client_reference_id;if (!clientReference) {- console.error("[Stripe Webhook] No client reference");+ logger.error("[Stripe Webhook] No client reference");return NextResponse.json({ message: "No client reference" },{ status: 400 },);}if (!isStripeClientReferenceFromCurrentCloudRegion(clientReference)) {- console.log(+ logger.info("[Stripe Webhook] Client reference not from current cloud region",);return;@@ -136,7 +132,7 @@ async function handleSubscriptionChanged(},});if (!organization) {- console.error("[Stripe Webhook] No organization not found");+ logger.error("[Stripe Webhook] Organization not found");return;}const parsedOrg = parseDbOrg(organization);@@ -144,7 +140,7 @@ async function handleSubscriptionChanged(// assert that no other stripe customer id is already set on the orgconst customerId = subscription.customer;if (!customerId || typeof customerId !== "string") {- console.error("[Stripe Webhook] Product ID not found");+ logger.error("[Stripe Webhook] Product ID not found");traceException("[Stripe Webhook] Product ID not found");return;}@@ -157,10 +153,10 @@ async function handleSubscriptionChanged(}// check subscription items- console.log("subscription.items.data", subscription.items.data);+ logger.info("subscription.items.data", { payload: subscription.items.data });if (!subscription.items.data || subscription.items.data.length !== 1) {- console.error(+ logger.error("[Stripe Webhook] Subscription items not found or more than one",);return;@@ -170,7 +166,7 @@ async function handleSubscriptionChanged(const productId = subscriptionItem.price.product;if (!productId || typeof productId !== "string") {- console.error("[Stripe Webhook] Product ID not found");+ logger.error("[Stripe Webhook] Product ID not found");traceException("[Stripe Webhook] Product ID not found");return;}diff --git a/web/src/ee/features/billing/stripeClientReference.ts b/web/src/ee/features/billing/stripeClientReference.tsindex 628f86acf3..56c3fa017d 100644--- a/web/src/ee/features/billing/stripeClientReference.ts+++ b/web/src/ee/features/billing/stripeClientReference.ts@@ -1,9 +1,10 @@import { env } from "@/src/env.mjs";+import { logger } from "@langfuse/shared/src/server";// used server-side to create a stripe customer reference when creating a checkout sessionexport const createStripeClientReference = (orgId: string) => {if (!env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION) {- console.error(+ logger.error("Returning null stripeCustomerReference, you cannot run the checkout page outside of Langfuse Cloud",);return null;diff --git a/web/src/ee/features/evals/server/router.ts b/web/src/ee/features/evals/server/router.tsindex b956a60962..b255ff94fb 100644--- a/web/src/ee/features/evals/server/router.ts+++ b/web/src/ee/features/evals/server/router.ts@@ -10,13 +10,12 @@ import {DEFAULT_TRACE_JOB_DELAY,EvalTargetObject,LLMAdapter,-} from "@langfuse/shared";-import {ZodModelConfig,singleFilter,variableMapping,} from "@langfuse/shared";import { throwIfNoEntitlement } from "@/src/features/entitlements/server/hasEntitlement";+import { logger } from "@langfuse/shared/src/server";export const CreateEvalTemplate = z.object({name: z.string().min(1),@@ -292,7 +291,7 @@ export const evalRouter = createTRPCRouter({});if (!evalTemplate) {- console.log(+ logger.warn(`Template not found for project ${input.projectId} and id ${input.evalTemplateId}`,);throw new Error("Template not found");@@ -319,7 +318,7 @@ export const evalRouter = createTRPCRouter({action: "create",});} catch (e) {- console.log(e);+ logger.error(e);throw e;}}),diff --git a/web/src/ee/features/multi-tenant-sso/createNewSsoConfigHandler.ts b/web/src/ee/features/multi-tenant-sso/createNewSsoConfigHandler.tsindex f316479ee0..5b855089f8 100644--- a/web/src/ee/features/multi-tenant-sso/createNewSsoConfigHandler.ts+++ b/web/src/ee/features/multi-tenant-sso/createNewSsoConfigHandler.ts@@ -4,6 +4,7 @@ import { encrypt } from "@langfuse/shared/encryption";import { SsoProviderSchema } from "./types";import { type NextApiRequest, type NextApiResponse } from "next";import { env } from "@/src/env.mjs";+import { logger } from "@langfuse/shared/src/server";export async function createNewSsoConfigHandler(req: NextApiRequest,@@ -68,7 +69,7 @@ export async function createNewSsoConfigHandler(message: "SSO configuration created successfully",});} catch (e) {- console.log(e);+ logger.error("Failed to create SSO configuration", e);res.status(500).json({ error: "Internal Server Error" });}}diff --git a/web/src/ee/features/multi-tenant-sso/utils.ts b/web/src/ee/features/multi-tenant-sso/utils.tsindex e9af4c4f74..1a0fbd1274 100644--- a/web/src/ee/features/multi-tenant-sso/utils.ts+++ b/web/src/ee/features/multi-tenant-sso/utils.ts@@ -9,7 +9,11 @@ import { isEeEnabled } from "@/src/ee/utils/isEeEnabled";import { type SsoConfig, prisma } from "@langfuse/shared/src/db";import { decrypt } from "@langfuse/shared/encryption";import { SsoProviderSchema } from "./types";-import { CustomSSOProvider, traceException } from "@langfuse/shared/src/server";+import {+ CustomSSOProvider,+ logger,+ traceException,+} from "@langfuse/shared/src/server";// Local cache for SSO configurationslet cachedSsoConfigs: {@@ -50,7 +54,7 @@ async function getSsoConfigs(): Promise<SsoProviderSchema[]> {},);} catch (e) {- console.error("Failed to load SSO configs from the database", e);+ logger.error("Failed to load SSO configs from the database", e);traceException(e);// empty array will be cached to prevent repeated DB queriesfailedToFetch = true;@@ -63,7 +67,7 @@ async function getSsoConfigs(): Promise<SsoProviderSchema[]> {const parsedValue = SsoProviderSchema.parse(v);return parsedValue;} catch (e) {- console.error(+ logger.error(`Failed to parse SSO provider config for domain ${v.domain}`,e,);@@ -190,7 +194,7 @@ const dbToNextAuthProvider = (provider: SsoProviderSchema): Provider | null => {// Type check to ensure we handle all providers// eslint-disable-next-line @typescript-eslint/no-unused-varsconst _: never = provider;- console.error(+ logger.error(`Unrecognized SSO provider for domain ${(provider as any).domain}`,);traceException(diff --git a/web/src/ee/features/playground/server/chatCompletionHandler.ts b/web/src/ee/features/playground/server/chatCompletionHandler.tsindex 6fcde1e971..b6e38b3699 100644--- a/web/src/ee/features/playground/server/chatCompletionHandler.ts+++ b/web/src/ee/features/playground/server/chatCompletionHandler.ts@@ -13,6 +13,7 @@ import { validateChatCompletionBody } from "./validateChatCompletionBody";import { prisma } from "@langfuse/shared/src/db";import { decrypt } from "@langfuse/shared/encryption";+import { logger } from "@langfuse/shared/src/server";export default async function chatCompletionHandler(req: NextRequest) {try {@@ -44,7 +45,7 @@ export default async function chatCompletionHandler(req: NextRequest) {return new StreamingTextResponse(stream);} catch (err) {- console.error(err);+ logger.error("Failed to handle chat completion", err);if (err instanceof BaseError) {return NextResponse.json(