Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
__getClientOtelConfigForTests,
|
||||
__resetClientOtelForTests,
|
||||
initClientOtel,
|
||||
readClientOtelConfig,
|
||||
} from "./otel.client";
|
||||
|
||||
afterEach(() => {
|
||||
__resetClientOtelForTests();
|
||||
});
|
||||
|
||||
describe("readClientOtelConfig", () => {
|
||||
it("defaults service.name to boilerplate-web", () => {
|
||||
expect(readClientOtelConfig({}).serviceName).toBe("boilerplate-web");
|
||||
});
|
||||
|
||||
it("respects VITE_OTEL_SERVICE_NAME override", () => {
|
||||
expect(readClientOtelConfig({ VITE_OTEL_SERVICE_NAME: "web-canary" }).serviceName).toBe("web-canary");
|
||||
});
|
||||
|
||||
it("treats an empty endpoint as undefined", () => {
|
||||
expect(readClientOtelConfig({ VITE_OTEL_EXPORTER_OTLP_ENDPOINT: "" }).endpoint).toBeUndefined();
|
||||
});
|
||||
|
||||
it("prefers VITE_SENTRY_ENVIRONMENT, falling back to MODE, for deployment.environment", () => {
|
||||
expect(readClientOtelConfig({ MODE: "production", VITE_SENTRY_ENVIRONMENT: "canary" }).deploymentEnvironment).toBe("canary");
|
||||
expect(readClientOtelConfig({ MODE: "production" }).deploymentEnvironment).toBe("production");
|
||||
});
|
||||
|
||||
it("always allowlists same-origin trace-header propagation", () => {
|
||||
const { propagateTraceHeaderCorsUrls } = readClientOtelConfig({});
|
||||
expect(propagateTraceHeaderCorsUrls).toHaveLength(1);
|
||||
expect(propagateTraceHeaderCorsUrls[0]?.test("/api/v1/foo")).toBe(true);
|
||||
});
|
||||
|
||||
it("appends the configured API host to the cross-origin allowlist", () => {
|
||||
const { propagateTraceHeaderCorsUrls } = readClientOtelConfig({ VITE_API_HOST: "api.example.com" });
|
||||
expect(propagateTraceHeaderCorsUrls).toHaveLength(2);
|
||||
expect(propagateTraceHeaderCorsUrls[1]?.test("https://api.example.com/v1")).toBe(true);
|
||||
expect(propagateTraceHeaderCorsUrls[1]?.test("https://evil.com/api.example.com")).toBe(false);
|
||||
});
|
||||
|
||||
it("prefers VITE_SENTRY_RELEASE, falling back to VITE_APP_REVISION, for service.version", () => {
|
||||
expect(readClientOtelConfig({ VITE_SENTRY_RELEASE: "sha-1" }).serviceVersion).toBe("sha-1");
|
||||
expect(readClientOtelConfig({ VITE_APP_REVISION: "sha-2" }).serviceVersion).toBe("sha-2");
|
||||
});
|
||||
});
|
||||
|
||||
describe("initClientOtel", () => {
|
||||
it("is a no-op when VITE_OTEL_EXPORTER_OTLP_ENDPOINT is unset", () => {
|
||||
const result = initClientOtel({
|
||||
endpoint: undefined,
|
||||
serviceName: "test",
|
||||
serviceVersion: undefined,
|
||||
deploymentEnvironment: undefined,
|
||||
serviceNamespace: "toolctrl",
|
||||
propagateTraceHeaderCorsUrls: [],
|
||||
});
|
||||
expect(result).toBe(false);
|
||||
// The config is still cached so callers can read it back during testing.
|
||||
expect(__getClientOtelConfigForTests()?.serviceName).toBe("test");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user