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
3535 );
3636 });
3737
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+
3844 it("returns unparseable input as-is", () => {
3945 expect(endpointForTelemetry("not a url")).toBe("not a url");
4046 });
packages/core/sdk/src/telemetry-endpoint.ts+6−0
@@ -23,6 +23,12 @@ · 22 unmodified lines
2323 export const endpointForTelemetry = (endpoint: string): string => {
2424 if (!URL.canParse(endpoint)) return endpoint;
2525 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+ }
2632 url.search = "";
2733 url.hash = "";
2834 url.username = "";