mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-08-30 02:08:40 +01:00
fix: correlate health metrics by session
Include the live Data Explorer session ID on health ingestion requests so backend logs can join directly to Portal telemetry. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 68ccefda-9e7d-4b01-a4db-e390810491ee
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { HttpHeaders } from "../Common/Constants";
|
||||
import { configContext, Platform } from "../ConfigContext";
|
||||
import { userContext } from "../UserContext";
|
||||
import { getAuthorizationHeader } from "../Utils/AuthorizationUtils";
|
||||
import { fetchWithTimeout } from "../Utils/FetchWithTimeout";
|
||||
import { MetricScenario } from "./Constants";
|
||||
@@ -40,11 +42,13 @@ describe("MetricEvents", () => {
|
||||
|
||||
const callArgs = mockFetchWithTimeout.mock.calls[0];
|
||||
expect(callArgs[0]).toContain("/api/dataexplorer/metrics/health");
|
||||
expect(callArgs[1]?.headers).toEqual({
|
||||
expect(callArgs[1]?.headers).toMatchObject({
|
||||
"Content-Type": "application/json",
|
||||
authorization: "Bearer test-token",
|
||||
});
|
||||
|
||||
expect((callArgs[1]?.headers as Record<string, string>)[HttpHeaders.sessionId]).toBe(userContext.sessionId);
|
||||
|
||||
const body = JSON.parse(callArgs[1]?.body as string);
|
||||
expect(body.scenario).toBe(MetricScenario.ApplicationLoad);
|
||||
expect(body.platform).toBe(Platform.Portal);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
// Metrics module: scenario metric emission logic.
|
||||
import { MetricEvent, MetricScenario } from "Metrics/Constants";
|
||||
import { HttpHeaders } from "../Common/Constants";
|
||||
import { createUri } from "../Common/UrlUtility";
|
||||
import { configContext } from "../ConfigContext";
|
||||
import { userContext } from "../UserContext";
|
||||
import { getAuthorizationHeader } from "../Utils/AuthorizationUtils";
|
||||
import { fetchWithTimeout } from "../Utils/FetchWithTimeout";
|
||||
|
||||
@@ -21,7 +23,11 @@ const send = async (event: MetricEvent): Promise<Response> => {
|
||||
|
||||
return await fetchWithTimeout(url, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", [authHeader.header]: authHeader.token },
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
[authHeader.header]: authHeader.token,
|
||||
[HttpHeaders.sessionId]: userContext.sessionId,
|
||||
},
|
||||
body: JSON.stringify(event),
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user