Skip to content
Merged
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2

### :bug: Bug Fixes

* fix(sdk-trace-web): propagate `optimised` flag in `getElementXPath` recursion [#6335](https://github.com/open-telemetry/opentelemetry-js/pull/6335) @akkupratap323

### :books: Documentation

### :house: Internal
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const fixture = `
<div></div>
</div>
<div></div>
<div id="body-id"><div></div></div>
</div>
`;

Expand Down Expand Up @@ -92,6 +93,13 @@ describe('utils', function () {
);
});

it('should use ancestor id when optimised recursively', function () {
const inner = $fixture.find('#body-id div')[0];
const element = getElementXPath(inner, true);
assert.strictEqual(element, '//*[@id="body-id"]/div');
assert.strictEqual(inner, getElementByXpath(element));
});

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