Skip to content

fix(sdk-trace-web): propagate optimised flag in getElementXPath recursion#6335

Merged
pichlermarc merged 4 commits intoopen-telemetry:mainfrom
akkupratap323:fix/getelementxpath-optimised
Feb 23, 2026
Merged

fix(sdk-trace-web): propagate optimised flag in getElementXPath recursion#6335
pichlermarc merged 4 commits intoopen-telemetry:mainfrom
akkupratap323:fix/getelementxpath-optimised

Conversation

@akkupratap323
Copy link
Copy Markdown
Contributor

@akkupratap323 akkupratap323 commented Jan 23, 2026

Summary

  • keep the optimised flag when recursing in getElementXPath
  • use ancestor id values to shorten XPath results when available
  • add a regression test for the ancestor-id optimization case

Background

getElementXPath currently forces optimised=false in the recursive call.
That discards ancestor IDs and yields verbose XPaths such as //html/body/div
instead of the expected //*[@id="body-id"]/div.

Fix

Propagate the optimised argument through recursion so the algorithm can
short-circuit to an ancestor id as intended.

Verification

  • npm test -- packages/opentelemetry-sdk-trace-web/test/window/utils.test.ts

Issue

Fixes #6323

Pass the optimised flag through recursive getElementXPath calls so
ancestor ids are used consistently, and add a regression test for it.
Fixes open-telemetry#6323.
@akkupratap323 akkupratap323 requested review from a team as code owners January 23, 2026 21:20
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Jan 23, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

Comment thread packages/opentelemetry-sdk-trace-web/test/window/utils.test.ts Outdated
Comment thread packages/opentelemetry-sdk-trace-web/test/window/utils.test.ts Outdated
- Use assert.ok() instead of if/throw for body check
- Remove try/finally pattern, use direct cleanup at end of test
- Use document.body directly to avoid TypeScript null checks

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Comment thread packages/opentelemetry-sdk-trace-web/test/window/utils.test.ts Outdated
@pichlermarc
Copy link
Copy Markdown
Member

@akkupratap323, are you still working on this? If yes, please address the remaining comments so we can proceed. 🙂

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.68%. Comparing base (2ca8ae1) to head (3b70d86).
⚠️ Report is 55 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6335      +/-   ##
==========================================
+ Coverage   95.58%   95.68%   +0.09%     
==========================================
  Files         314      364      +50     
  Lines        9590    11775    +2185     
  Branches     2221     2742     +521     
==========================================
+ Hits         9167    11267    +2100     
- Misses        423      508      +85     
Files with missing lines Coverage Δ
packages/opentelemetry-sdk-trace-web/src/utils.ts 93.75% <100.00%> (ø)

... and 88 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pichlermarc pichlermarc changed the title Fix getElementXPath optimised recursion fix(sdk-trace-web): propagate optimised flag in getElementXPath recursion Feb 23, 2026
@pichlermarc pichlermarc added this pull request to the merge queue Feb 23, 2026
Merged via the queue into open-telemetry:main with commit 6869565 Feb 23, 2026
27 checks passed
@otelbot
Copy link
Copy Markdown
Contributor

otelbot Bot commented Feb 23, 2026

Thank you for your contribution @akkupratap323! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

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

4 participants