Skip to content

Commit

Permalink
Add more detailed logss to investigate Cirrus connection error
Browse files Browse the repository at this point in the history
  • Loading branch information
codemist committed Jan 10, 2025
1 parent d1bdd56 commit f040227
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/app/functions/server/getExperimentationId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
Expand All @@ -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;
}
}
21 changes: 20 additions & 1 deletion src/app/functions/server/getExperiments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -49,6 +50,7 @@ export function middleware(request: NextRequest) {
value: experimentationId,
path: "/",
});
logger.info("Set experimentation ID cookie", { experimentationId });
}

return response;
Expand Down

0 comments on commit f040227

Please sign in to comment.