Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion packages/opentelemetry-sdk-trace-web/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export function getElementXPath(target: any, optimised?: boolean): string {
}
let xpath = '';
if (target.parentNode) {
xpath += getElementXPath(target.parentNode, false);
xpath += getElementXPath(target.parentNode, optimised);
}
xpath += targetValue;

Expand Down
17 changes: 17 additions & 0 deletions packages/opentelemetry-sdk-trace-web/test/window/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ describe('utils', function () {
);
});

it('should use ancestor id when optimised recursively', function () {
const body = document.body;
assert.ok(body, 'Missing document body');

const container = document.createElement('div');
Copy link
Contributor

@overbalance overbalance Jan 26, 2026

Choose a reason for hiding this comment

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

Check out the fixture above. Then you can remove this dynamic tag creation code.

container.id = 'body-id';
const inner = document.createElement('div');
container.appendChild(inner);
document.body.appendChild(container);

const element = getElementXPath(inner, true);
assert.strictEqual(element, '//*[@id="body-id"]/div');
assert.strictEqual(inner, getElementByXpath(element));

document.body.removeChild(container);
});

it(
'should return correct path for element with id and surrounded by the' +
' same type',
Expand Down