From 6e67c8663878c95bffba2198b164252470f5b78e Mon Sep 17 00:00:00 2001 From: Kaitlyn Date: Fri, 10 Jan 2025 07:54:43 -0500 Subject: [PATCH 1/5] Add cirrus logging errors --- .../functions/server/getExperimentationId.ts | 9 ++++++++ src/app/functions/server/getExperiments.ts | 21 ++++++++++++++++++- src/middleware.ts | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/app/functions/server/getExperimentationId.ts b/src/app/functions/server/getExperimentationId.ts index 6e03a6efcea..0da2fadcf3d 100644 --- a/src/app/functions/server/getExperimentationId.ts +++ b/src/app/functions/server/getExperimentationId.ts @@ -28,6 +28,12 @@ export function getExperimentationId( // If the user is logged in, use the Subscriber ID. const namespace = process.env.NIMBUS_UUID_NAMESPACE; if (!namespace) { + logger.error( + "NIMBUS_UUID_NAMESPACE environment variable is missing. Cannot generate experimentationId.", + { + accountId, + }, + ); throw new Error( "NIMBUS_UUID_NAMESPACE not set, cannot create experimentationId", ); @@ -47,6 +53,9 @@ export function getExperimentationId( ); return "guest-no-experimentation-id-set-by-monitor-middleware"; } + logger.info("Using experimentationId from header for guest user", { + experimentationId, + }); return experimentationId as ExperimentationId; } } diff --git a/src/app/functions/server/getExperiments.ts b/src/app/functions/server/getExperiments.ts index 66dc85ff271..d1bfa29e4c6 100644 --- a/src/app/functions/server/getExperiments.ts +++ b/src/app/functions/server/getExperiments.ts @@ -50,6 +50,12 @@ export async function getExperiments(params: { serverUrl.searchParams.set("nimbus_preview", "true"); } + logger.info("Sending request to Cirrus", { + serverUrl: serverUrl.toString(), + previewMode: params.previewMode, + client_id: params.experimentationId, + }); + const response = await fetch(serverUrl, { headers: { "Content-Type": "application/json", @@ -65,6 +71,14 @@ export async function getExperiments(params: { }), }); + if (!response.ok) { + logger.error("Cirrus request failed", { + status: response.status, + url: serverUrl.toString(), + }); + throw new Error(`Cirrus request failed: ${response.statusText}`); + } + const json = await response.json(); let experimentData; @@ -76,7 +90,12 @@ export async function getExperiments(params: { return (experimentData as ExperimentData) ?? defaultExperimentData; } catch (ex) { - logger.error("Could not connect to Cirrus", { serverUrl, ex }); + logger.error("Could not connect to Cirrus", { + serverUrl, + ex, + flags, + params, + }); captureException(ex); return defaultExperimentData; } diff --git a/src/middleware.ts b/src/middleware.ts index b713ef80b39..a8f4dac7b1e 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -5,6 +5,7 @@ import { NextResponse } from "next/server"; import type { NextRequest } from "next/server"; import nextConfig from "../next.config"; +import { logger } from "./app/functions/server/logging"; // This function can be marked `async` if using `await` inside export function middleware(request: NextRequest) { @@ -49,6 +50,7 @@ export function middleware(request: NextRequest) { value: experimentationId, path: "/", }); + logger.info("Set experimentation ID cookie", { experimentationId }); } return response; From 39a3a29d85eb39e1832f6b707060d362d7378e3e Mon Sep 17 00:00:00 2001 From: Kaitlyn Date: Fri, 10 Jan 2025 08:17:53 -0500 Subject: [PATCH 2/5] remove middleware logging --- src/middleware.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/middleware.ts b/src/middleware.ts index a8f4dac7b1e..836156cd775 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -5,7 +5,6 @@ import { NextResponse } from "next/server"; import type { NextRequest } from "next/server"; import nextConfig from "../next.config"; -import { logger } from "./app/functions/server/logging"; // This function can be marked `async` if using `await` inside export function middleware(request: NextRequest) { @@ -44,15 +43,6 @@ export function middleware(request: NextRequest) { }, }); - if (!existingExperimentationId) { - response.cookies.set({ - name: "experimentationId", - value: experimentationId, - path: "/", - }); - logger.info("Set experimentation ID cookie", { experimentationId }); - } - return response; } From 8c23f7ba33aad40a935de3d2349d56dce90cc58e Mon Sep 17 00:00:00 2001 From: Kaitlyn Date: Mon, 13 Jan 2025 04:19:32 -0500 Subject: [PATCH 3/5] revert code change in middleware --- src/middleware.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/middleware.ts b/src/middleware.ts index 836156cd775..b713ef80b39 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -43,6 +43,14 @@ export function middleware(request: NextRequest) { }, }); + if (!existingExperimentationId) { + response.cookies.set({ + name: "experimentationId", + value: experimentationId, + path: "/", + }); + } + return response; } From cdb32cf8f05af9389a8aa6f1363e52183b9dba68 Mon Sep 17 00:00:00 2001 From: Kaitlyn Date: Mon, 13 Jan 2025 04:21:50 -0500 Subject: [PATCH 4/5] remove logging userId --- src/app/functions/server/getExperimentationId.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/app/functions/server/getExperimentationId.ts b/src/app/functions/server/getExperimentationId.ts index 0da2fadcf3d..5dc635aa34c 100644 --- a/src/app/functions/server/getExperimentationId.ts +++ b/src/app/functions/server/getExperimentationId.ts @@ -30,9 +30,6 @@ export function getExperimentationId( if (!namespace) { logger.error( "NIMBUS_UUID_NAMESPACE environment variable is missing. Cannot generate experimentationId.", - { - accountId, - }, ); throw new Error( "NIMBUS_UUID_NAMESPACE not set, cannot create experimentationId", From 1412e7cdc017ad76c9f335cb198f7c1c6bb7d3d9 Mon Sep 17 00:00:00 2001 From: Kaitlyn Date: Mon, 13 Jan 2025 04:22:57 -0500 Subject: [PATCH 5/5] remove logging experimentId --- src/app/functions/server/getExperiments.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/functions/server/getExperiments.ts b/src/app/functions/server/getExperiments.ts index d1bfa29e4c6..205a036af4f 100644 --- a/src/app/functions/server/getExperiments.ts +++ b/src/app/functions/server/getExperiments.ts @@ -53,7 +53,6 @@ export async function getExperiments(params: { logger.info("Sending request to Cirrus", { serverUrl: serverUrl.toString(), previewMode: params.previewMode, - client_id: params.experimentationId, }); const response = await fetch(serverUrl, {