-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEVPROD-3188: Attach additional data to ui.click breadcrumbs in Sentry (
#113)
- Loading branch information
Showing
12 changed files
with
152 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { processHtmlAttributes } from "./utils"; | ||
|
||
describe("processHtmlAttributes", () => { | ||
it("properly extracts attributes", () => { | ||
const htmlElement = document.createElement("input"); | ||
htmlElement.setAttribute("aria-label", "custom-aria-label"); | ||
htmlElement.setAttribute("title", "custom-title"); | ||
htmlElement.setAttribute("data-cy", "custom-data-cy"); | ||
htmlElement.setAttribute("data-loading", "false"); | ||
|
||
const htmlAttributes = processHtmlAttributes(htmlElement); | ||
expect(htmlAttributes.ariaLabel).toBe("custom-aria-label"); | ||
expect(htmlAttributes?.dataset?.cy).toBe("custom-data-cy"); | ||
expect(htmlAttributes?.dataset?.loading).toBe("false"); | ||
expect(htmlAttributes.title).toBe("custom-title"); | ||
}); | ||
|
||
it("omits attributes that are unset", () => { | ||
const htmlElement = document.createElement("div"); | ||
htmlElement.setAttribute("data-cy", "custom-data-cy"); | ||
|
||
const htmlAttributes = processHtmlAttributes(htmlElement); | ||
expect(htmlAttributes?.dataset?.cy).toBe("custom-data-cy"); | ||
expect(htmlAttributes.ariaLabel).toBeUndefined(); | ||
expect(htmlAttributes.title).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* `processHtmlAttributes` extracts useful attributes to attach as | ||
* Sentry breadcrumb data. | ||
* @param htmlElement - HTML element detected by Sentry | ||
* @returns an object containing attributes of the HTML element | ||
*/ | ||
const processHtmlAttributes = (htmlElement: HTMLElement) => { | ||
const ariaLabel = htmlElement.getAttribute("aria-label"); | ||
const title = htmlElement.getAttribute("title"); | ||
// Get dataset directly to handle all data-* attributes. | ||
const { dataset } = htmlElement ?? {}; | ||
return { | ||
...(ariaLabel && { ariaLabel }), | ||
...(dataset && Object.keys(dataset).length > 0 && { dataset }), | ||
...(title && { title }), | ||
}; | ||
}; | ||
|
||
export { processHtmlAttributes }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { processHtmlAttributes } from "./utils"; | ||
|
||
describe("processHtmlAttributes", () => { | ||
it("properly extracts attributes", () => { | ||
const htmlElement = document.createElement("input"); | ||
htmlElement.setAttribute("aria-label", "custom-aria-label"); | ||
htmlElement.setAttribute("title", "custom-title"); | ||
htmlElement.setAttribute("data-cy", "custom-data-cy"); | ||
htmlElement.setAttribute("data-loading", "false"); | ||
|
||
const htmlAttributes = processHtmlAttributes(htmlElement); | ||
expect(htmlAttributes.ariaLabel).toBe("custom-aria-label"); | ||
expect(htmlAttributes?.dataset?.cy).toBe("custom-data-cy"); | ||
expect(htmlAttributes?.dataset?.loading).toBe("false"); | ||
expect(htmlAttributes.title).toBe("custom-title"); | ||
}); | ||
|
||
it("omits attributes that are unset", () => { | ||
const htmlElement = document.createElement("div"); | ||
htmlElement.setAttribute("data-cy", "custom-data-cy"); | ||
|
||
const htmlAttributes = processHtmlAttributes(htmlElement); | ||
expect(htmlAttributes?.dataset?.cy).toBe("custom-data-cy"); | ||
expect(htmlAttributes.ariaLabel).toBeUndefined(); | ||
expect(htmlAttributes.title).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* `processHtmlAttributes` extracts useful attributes to attach as | ||
* Sentry breadcrumb data. | ||
* @param htmlElement - HTML element detected by Sentry | ||
* @returns an object containing attributes of the HTML element | ||
*/ | ||
const processHtmlAttributes = (htmlElement: HTMLElement) => { | ||
const ariaLabel = htmlElement.getAttribute("aria-label"); | ||
const title = htmlElement.getAttribute("title"); | ||
// Get dataset directly to handle all data-* attributes. | ||
const { dataset } = htmlElement ?? {}; | ||
return { | ||
...(ariaLabel && { ariaLabel }), | ||
...(dataset && Object.keys(dataset).length > 0 && { dataset }), | ||
...(title && { title }), | ||
}; | ||
}; | ||
|
||
export { processHtmlAttributes }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters