Skip to content

fix(sdk-trace-web): pass optimised parameter recursively in getElementXPath#6429

Closed
slegarraga wants to merge 1 commit intoopen-telemetry:mainfrom
slegarraga:fix/get-element-xpath-pass-optimised
Closed

fix(sdk-trace-web): pass optimised parameter recursively in getElementXPath#6429
slegarraga wants to merge 1 commit intoopen-telemetry:mainfrom
slegarraga:fix/get-element-xpath-pass-optimised

Conversation

@slegarraga
Copy link
Copy Markdown

Fixes #6323

Problem

getElementXPath hardcodes false for the optimised parameter when recursing to parent nodes:

xpath += getElementXPath(target.parentNode, false);

This means child elements of nodes with IDs produce non-optimised XPaths even when optimised=true is requested:

  • Expected: //*[@id="body-id"]/div
  • Actual: //html/body/div

Fix

Changed false to optimised so the parameter is correctly passed through recursive calls:

xpath += getElementXPath(target.parentNode, optimised);

Also added a test case verifying that child elements of id-bearing ancestors use the optimised @id shortcut.

…tXPath

The getElementXPath function was hardcoding false for the optimised
parameter when recursing to parent nodes. This caused child elements
of nodes with IDs to produce non-optimised XPaths (e.g.
//html/body/div instead of //*[@id="parent-id"]/div) even when
optimised=true was requested.

Fixes open-telemetry#6323
@slegarraga slegarraga requested review from a team as code owners February 19, 2026 23:10
@linux-foundation-easycla
Copy link
Copy Markdown

CLA Not Signed

@pichlermarc
Copy link
Copy Markdown
Member

closing as duplicate of #6335

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getElementXPath does not pass parameter optimised recursively

2 participants