Skip to content

rtc: emit per-data-track bytes via BytesTrackStats#4540

Merged
paulwe merged 1 commit into
masterfrom
data-track-byte-stats
May 24, 2026
Merged

rtc: emit per-data-track bytes via BytesTrackStats#4540
paulwe merged 1 commit into
masterfrom
data-track-byte-stats

Conversation

@paulwe
Copy link
Copy Markdown
Contributor

@paulwe paulwe commented May 23, 2026

Summary

  • Data tracks (the new _data_track datachannel) previously only updated a private dataTrackStats that logged a single summary at Close. Bytes never reached the OnTrackStats → TelemetryService.TrackStats pipeline that media tracks and signal channels feed.
  • Wires DataTrack (UPSTREAM, at the publisher's home node where HandlePacket fires) and DataDownTrack (DOWNSTREAM, per local subscriber, at WritePacket post-marshal) into BytesTrackStats on the established 5s cadence.
  • Mirrors the media-track convention: DOWNSTREAM uses the subscriber's country/ID and the publisher's track ID; UPSTREAM uses the publisher's. BytesTrackStats for DOWNSTREAM is constructed inside DataTrack.AddSubscriber from the subscriber's LocalParticipant accessors; UPSTREAM is constructed at the two publisher-home NewDataTrack call sites (HandlePublishDataTrackRequest and the migration path).
  • Cross-region proxy DataTrack instances (e.g. cloud's RemoteParticipant) leave the new params field nil — they have no publisher reporter on that node, and relayed bytes routed through HandlePacket would double-count.
  • Legacy dataTrackStats packet-loss / out-of-order / frame counters are preserved unchanged.

Test plan

  • go test -short ./pkg/rtc/... passes
  • Cloud workspace builds + go test -short ./pkg/rtc/... passes (no cloud edits needed — additive params field defaults to nil at proxy and replay sites)
  • End-to-end: publish a data track + subscribe, confirm OnTrackStats receives both StatsKeyForData(UPSTREAM, publisherID, dataTrackID) (publisher node) and StatsKeyForData(DOWNSTREAM, subscriberID, dataTrackID) (subscriber node) on ~5s cadence with a final flush on Close
  • Cross-region replay: confirm proxy DataTrack on subscriber node emits no UPSTREAM (no nil panic, no double accounting)

Data tracks (the new _data_track datachannel) previously only updated a
private dataTrackStats that logged a single summary at Close. Bytes never
reached the OnTrackStats -> TelemetryService.TrackStats pipeline that
media tracks and signal channels feed.

Wire DataTrack (UPSTREAM, publisher-home) and DataDownTrack (DOWNSTREAM,
per-subscriber) into BytesTrackStats on the same 5s cadence, mirroring
the media-track convention: subscriber's country and ID with publisher's
track ID for DOWNSTREAM. Cross-region proxy DataTracks leave the stats
pointer nil (no publisher reporter on that node, and relayed bytes would
double-count). Legacy dataTrackStats packet-loss/frame counters are
preserved.
@anunaym14
Copy link
Copy Markdown
Member

dataChannelStats *BytesTrackStats

this probably needs to be removed?

@paulwe paulwe merged commit cde8962 into master May 24, 2026
7 checks passed
@paulwe paulwe deleted the data-track-byte-stats branch May 24, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants