Skip to content
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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): pass `optimised` parameter recursively in `getElementXPath` [#6323](https://github.com/open-telemetry/opentelemetry-js/issues/6323) @ritesh
* fix(opentelemetry-sdk-node): the custom value from env variable for service.instance.id should take priority over random uuid as backup [#6345](https://github.com/open-telemetry/opentelemetry-js/pull/6345) @maryliag

### :books: Documentation
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
19 changes: 19 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 @@ -148,6 +148,25 @@ describe('utils', function () {
assert.strictEqual(element, '//html/body/div/div[4]/div[8]/comment()');
assert.strictEqual(node, getElementByXpath(element));
});

it('should pass optimised parameter recursively to parent nodes', function () {
// Test the specific bug from issue #6323
// Create a structure: div#test-parent-id > div (no id)
const testContainer = document.createElement('div');
testContainer.id = 'test-parent-id';
const childDiv = document.createElement('div');
testContainer.appendChild(childDiv);
document.body.appendChild(testContainer);

try {
const xpath = getElementXPath(childDiv, true);
// With optimised=true, should use parent's id instead of full path
assert.strictEqual(xpath, '//*[@id="test-parent-id"]/div');
assert.strictEqual(childDiv, getElementByXpath(xpath));
} finally {
document.body.removeChild(testContainer);
}
});
});

describe('parseUrl', function () {
Expand Down
Loading