History

Keep clean endpoints byte-identical in span attributes

Rhys Sullivan committed 3 months ago

Commit 2d4f22b1 parent d3cc41d2 files · +12 −0Browse files

Unified · Split

2 files
  1. packages/core/sdk/src/telemetry-endpoint.test.ts +6 −0
  2. packages/core/sdk/src/telemetry-endpoint.ts +6 −0
packages/core/sdk/src/telemetry-endpoint.test.ts+6−0
@@ -35,6 +35,12 @@ describe("endpointForTelemetry", () => { · 34 unmodified lines
35 );35 );
36 });36 });
37 37
38 it("does not URL-normalize a credential-free endpoint", () => {
39 // A bare origin round-tripped through URL gains a trailing slash; the
40 // stamped attribute must stay byte-identical to the configured endpoint.
41 expect(endpointForTelemetry("http://127.0.0.1:55003")).toBe("http://127.0.0.1:55003");
42 });
43
38 it("returns unparseable input as-is", () => {44 it("returns unparseable input as-is", () => {
39 expect(endpointForTelemetry("not a url")).toBe("not a url");45 expect(endpointForTelemetry("not a url")).toBe("not a url");
40 });46 });
packages/core/sdk/src/telemetry-endpoint.ts+6−0
@@ -23,6 +23,12 @@ · 22 unmodified lines
23export const endpointForTelemetry = (endpoint: string): string => {23export const endpointForTelemetry = (endpoint: string): string => {
24 if (!URL.canParse(endpoint)) return endpoint;24 if (!URL.canParse(endpoint)) return endpoint;
25 const url = new URL(endpoint);25 const url = new URL(endpoint);
26 // A clean endpoint is returned verbatim: round-tripping through URL
27 // normalizes (e.g. appends a trailing slash to an origin), which would make
28 // the stamped attribute diverge from the configured value.
29 if (url.search === "" && url.hash === "" && url.username === "" && url.password === "") {
30 return endpoint;
31 }
26 url.search = "";32 url.search = "";
27 url.hash = "";33 url.hash = "";
28 url.username = "";34 url.username = "";