Skip to content

Improve trace timestamp accuracy under concurrent event recording#1734

Open
rahul-lohra wants to merge 1 commit into
developfrom
bugfix/rahullohra/tracer-timestamp-fifo
Open

Improve trace timestamp accuracy under concurrent event recording#1734
rahul-lohra wants to merge 1 commit into
developfrom
bugfix/rahullohra/tracer-timestamp-fifo

Conversation

@rahul-lohra

@rahul-lohra rahul-lohra commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Goal

Close #AND-1265

Improve the accuracy of trace timestamps by recording the timestamp when the trace event is created rather than when it is inserted into the tracer buffer.

Previously, timestamps were generated inside the synchronized buffer section. Under contention, a thread could wait to acquire the lock before recording its timestamp, causing the recorded time to reflect lock acquisition order rather than the actual time the event occurred.

By capturing the timestamp before acquiring the buffer lock, trace records more accurately represent when the underlying event was observed by the SDK.

Implementation

  • Moved TraceRecord creation outside the synchronized buffer section.
  • Capture System.currentTimeMillis() before attempting to acquire the tracer lock.
  • Preserve the existing synchronization strategy for buffer mutations.
  • No changes to trace serialization, buffering, rollback behavior, or upload logic.

Before:

  • Timestamp represented when the tracer accepted the event into the buffer.

After:

  • Timestamp represents when the event was observed and trace() was invoked.

This change improves the temporal accuracy of analytics and debugging traces when multiple threads are recording events concurrently.

🎨 UI Changes

None

Testing

Visit Stream Demo App's Dashboard to see the tracer events

@rahul-lohra rahul-lohra self-assigned this Jun 25, 2026
@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

PR checklist ✅

All required conditions are satisfied:

  • Title length is OK (or ignored by label).
  • At least one pr: label exists.
  • Sections ### Goal, ### Implementation, and ### Testing are filled, or the PR is bot-authored.
  • An issue is linked (Linear ticket or GitHub issue), or the PR is bot-authored.

🎉 Great job! This PR is ready for review.

@rahul-lohra rahul-lohra changed the title Improve trace timestamp accuracy under concurrent event recording [AND-1265] Improve trace timestamp accuracy under concurrent event recording Jun 25, 2026
@rahul-lohra rahul-lohra changed the title [AND-1265] Improve trace timestamp accuracy under concurrent event recording Improve trace timestamp accuracy under concurrent event recording Jun 25, 2026
@rahul-lohra rahul-lohra added the pr:internal Internal or infra-only changes label Jun 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

SDK Size Comparison 📏

SDK Before After Difference Status
stream-video-android-core 12.27 MB 12.27 MB 0.00 MB 🟢
stream-video-android-ui-xml 5.68 MB 5.68 MB 0.00 MB 🟢
stream-video-android-ui-compose 6.20 MB 6.20 MB 0.00 MB 🟢

@sonarqubecloud

Copy link
Copy Markdown

@rahul-lohra rahul-lohra marked this pull request as ready for review July 2, 2026 11:13
@rahul-lohra rahul-lohra requested a review from a team as a code owner July 2, 2026 11:13
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4ff38456-1011-4ed6-82c0-2d9383bbdd4d

📥 Commits

Reviewing files that changed from the base of the PR and between 6035a0d and 5e35534.

📒 Files selected for processing (2)
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/trace/TraceRecord.kt
  • stream-video-android-core/src/test/kotlin/io/getstream/video/android/core/trace/TraceRecordTest.kt
👮 Files not reviewed due to content moderation or server errors (2)
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/trace/TraceRecord.kt
  • stream-video-android-core/src/test/kotlin/io/getstream/video/android/core/trace/TraceRecordTest.kt

Warning

Walkthrough skipped

File diffs could not be summarized.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/rahullohra/tracer-timestamp-fifo

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

pr:internal Internal or infra-only changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant