Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more portions of the path to r11s request errors #22943

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions packages/drivers/routerlicious-driver/src/errorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,24 +186,37 @@ export const socketIoPath = "socket.io";
* Get a stripped version of a URL safe for r11s telemetry
* @returns undefined if no appropriate hostName is provided
*/
export function getUrlForTelemetry(hostName: string, path?: string): string | undefined {
export function getUrlForTelemetry(hostName: string, path: string = ""): string | undefined {
// Strip off "http://" or "https://"
const hostNameMatch = hostName.match(/^(?:https?:\/\/)?([^/]+)/);
if (!hostNameMatch) {
return undefined;
}
const strippedHostName = hostNameMatch[1];

let extractedPath: string | undefined;
if (path !== undefined) {
// Extract the first portion of the path and explicitly match it to known path names
const pathMatch = path.match(/^\/?([^/]+)/);
if (pathMatch && [socketIoPath, "repos", "deltas", "documents"].includes(pathMatch[1])) {
extractedPath = pathMatch[1];
let extractedPath = "";
// Extract portions of the path and explicitly match them to known path names
for (const portion of path.split("/")) {
if (portion !== "") {
// eslint-disable-next-line unicorn/prefer-ternary
if (
[
socketIoPath,
"repos",
"deltas",
"documents",
"session",
"git",
"summaries",
"latest",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add the following as well:

  • document
  • commits
  • blobs
  • refs
  • revokeToken
  • accesstoken

].includes(portion)
) {
extractedPath += `/${portion}`;
} else {
extractedPath += "/REDACTED";
}
}
}

return extractedPath !== undefined
? `${strippedHostName}/${extractedPath}`
: strippedHostName;
return `${strippedHostName}${extractedPath}`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,18 @@ describe("ErrorUtils", () => {
["https://some.url.com/", "", "some.url.com"],
["something://some.url.com/", "", "something:"],
["some.url.com/path", undefined, "some.url.com"],
["some.url.com/", "randomPath", "some.url.com"],
["some.url.com/", "randomPath", "some.url.com/REDACTED"],
["some.url.com/", socketIoPath, `some.url.com/${socketIoPath}`],
["http://some.url.com/", "repos", "some.url.com/repos"],
["some.url.com/", "deltas", "some.url.com/deltas"],
["https://some.url.com", "documents", "some.url.com/documents"],
["https://some.url.com/", "/documents/", "some.url.com/documents"],
["https://some.url.com/", "documents/morePath", "some.url.com/documents"],
["https://some.url.com/", "documents/morePath", "some.url.com/documents/REDACTED"],
[
"https://some.url.com",
"documents/morePath/documents/latest/abc-123/",
"some.url.com/documents/REDACTED/documents/latest/REDACTED",
],
];

testCases.forEach((testCase) => {
Expand Down
Loading