diff --git a/apps/webapp/app/routes/admin.api.v1.snapshot.ts b/apps/webapp/app/routes/admin.api.v1.snapshot.ts index 63362405f..252ffd319 100644 --- a/apps/webapp/app/routes/admin.api.v1.snapshot.ts +++ b/apps/webapp/app/routes/admin.api.v1.snapshot.ts @@ -32,10 +32,11 @@ export async function loader({ request }: DataFunctionArgs) { throw new Response("You must be an admin to perform this action", { status: 403 }); } - const host = request.headers.get("X-Forwarded-Host") ?? request.headers.get("host"); - const tempDir = os.tmpdir(); - const filepath = path.join(tempDir, `${host}-${formatDate(new Date())}.heapsnapshot`); + const filepath = path.join( + tempDir, + `${getTaskIdentifier()}-${formatDate(new Date())}.heapsnapshot` + ); const snapshotPath = v8.writeHeapSnapshot(filepath); if (!snapshotPath) { @@ -57,3 +58,13 @@ export async function loader({ request }: DataFunctionArgs) { }, }); } + +function getTaskIdentifier() { + if (!process.env.ECS_CONTAINER_METADATA_URI) { + return "local"; + } + + const url = new URL(process.env.ECS_CONTAINER_METADATA_URI); + + return url.pathname.split("/")[2].split("-")[0]; +}