[No QA] Fix negative Sentry span duration logs in dev#85009
Conversation
…stead of spanToJSON start_timestamp
|
@ChavdaSachin Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
JakubKorytko
left a comment
There was a problem hiding this comment.
LGTM, one small comment
src/libs/telemetry/activeSpans.ts
Outdated
| span.setAttribute(CONST.TELEMETRY.ATTRIBUTE_MIN_DURATION, extraOptions.minDuration); | ||
| } | ||
| activeSpans.set(spanId, span); | ||
| activeSpans.set(spanId, {span, startTime: Date.now()}); |
There was a problem hiding this comment.
Date.now() is still wall-clock time, not monotonic. If the device clock jumps forward/backward during a span because of NTP sync, manual time change, or resume-from-sleep behavior, durationMs can still become negative or arbitrarily large. That means the bug is reduced, but not actually fixed "across all environments"; I believe a monotonic source like performance.now() would avoid the same class of failure.
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safari |
Julesssss
left a comment
There was a problem hiding this comment.
NAB, description is outdated now with the last commit.
NAB, Also should we use performance.now elsewhere in our metrics?
|
🚧 @marcaaron has triggered a test Expensify/App build. You can view the workflow run here. |
I think yes, but also would need to audit the usages to make sure that is what we want. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/marcaaron in version: 9.3.37-0 🚀
|
|
🚀 Deployed to production by https://github.com/cristipaval in version: 9.3.37-10 🚀
|
Explanation of Change
spanToJSON(span).start_timestampproduces negative or huge duration values in dev (reported here by @JakubKorytko). This switches to storingperformance.now()when a span starts and using that for the duration log, which is reliable across all environments.ActiveSpanEntrytype wrapping the span + astartTimeactiveSpansmap to store entries instead of raw spansendSpan,cancelSpan, andgetSpanto unwrap entriesspanToJSONimportFixed Issues
$ #85008
Tests
npm run web[Sentry]Ending span (120ms)) instead of negative or huge valuesOffline tests
N/A - logging-only change, no network dependency.
QA Steps
N/A - No QA. Dev logging only, no user-facing behavior change.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari