Prevent trace mutation during critical path computation#3271
Prevent trace mutation during critical path computation#3271yurishkuro merged 5 commits intomainfrom
Conversation
Co-authored-by: yurishkuro <3523016+yurishkuro@users.noreply.github.com>
…ation Co-authored-by: yurishkuro <3523016+yurishkuro@users.noreply.github.com>
Co-authored-by: yurishkuro <3523016+yurishkuro@users.noreply.github.com>
| duration: number; | ||
| references: Array<SpanReference>; | ||
| childSpanIds: Array<string>; | ||
| hasChildren: boolean; |
There was a problem hiding this comment.
I think hasChildren can be dropped, code can check if(span.childSpanIds) for the same outcome, less data to maintain
There was a problem hiding this comment.
Done in commit 1d5832f. Removed hasChildren from CPSpan type and updated code to check childSpanIds.length > 0 instead.
| import sanitizeOverFlowingChildren from './sanitizeOverFlowingChildren'; | ||
|
|
||
| // Helper function to create CPSpan objects from Span objects | ||
| function createCPSpan(span) { |
There was a problem hiding this comment.
this function seems to be needed in many places, extract it into utility module and use every time we're creating CPSpan
There was a problem hiding this comment.
Done in commit 1d5832f. Extracted createCPSpan() and createCPSpanMap() functions into a new utility module at utils/cpspan.tsx and updated all test files to use it.
| }), | ||
| ], | ||
| ])('sanitizeOverFlowingChildren', (testProps, expectedSanitizedData) => { | ||
| it('Should sanitize the data(overflowing spans) correctly', () => { |
There was a problem hiding this comment.
add a description string to each test case (illustrating what is specific about it compared to other tests) and include that description in the test name in it()
There was a problem hiding this comment.
Done in commit 1d5832f. Added descriptive strings to each test case (e.g., "child starts after parent ends - child dropped") that appear in both the test suite name and individual test names.
…, add test descriptions Co-authored-by: yurishkuro <3523016+yurishkuro@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3271 +/- ##
=======================================
Coverage 97.45% 97.45%
=======================================
Files 268 269 +1
Lines 8364 8369 +5
Branches 2211 2212 +1
=======================================
+ Hits 8151 8156 +5
Misses 210 210
Partials 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The critical path algorithm was mutating the original trace's spans by modifying
childSpanIdsarrays andreferencesduring computation, breaking immutability guarantees.Changes
New types for isolated computation:
CPSpantype containing only fields needed for critical path computation (spanID,startTime,duration,references,childSpanIds)CPSpanReferencetype for span references within CPSpan objectsUtility functions for CPSpan creation:
utils/cpspan.tsxmodule withcreateCPSpan()andcreateCPSpanMap()helper functionsUpdated critical path functions:
criticalPathForTrace()now usescreateCPSpanMap()to create defensive copies before processinggetChildOfSpans,sanitizeOverFlowingChildren,findLastFinishingChildSpan,computeCriticalPath) to operate on CPSpan instead of SpangetChildOfSpansnow checkschildSpanIds.length > 0instead of using a separatehasChildrenfieldExample of the fix:
Test coverage:
createCPSpan()utilityOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.