Skip to content

Conversation

@motiz88
Copy link
Contributor

@motiz88 motiz88 commented Jan 29, 2026

Summary:
Changelog: [Internal]

Behaviour

Fixes an edge case in the way background traces are emitted when multiple RNDT frontends (or other clients with the ReactNativeApplication domain enabled) are connected to a single Host. Previously, only one of the clients would receive the CDP events for the trace. With this diff, all of them will.

NOTE: This leaves another, even smaller edge case / inconsistency: if there are no RNDT frontends at the time a background trace ends, we still only send it to the first frontend (if any) that connects. This is logically more defensible than picking one client out of multiple active connections ( = what's fixed in this diff).

Implementation

Tracing functionality is somewhat awkwardly split between HostTarget (background traces) and TracingAgent (CDP-initiated traces). This diff doesn't attempt to fully clean this up[1], but we do reduce duplication and boilerplate by creating a helper function used by both. This function encapsulates the gnarly/surprising details of dealing with tracing::HostTracingProfile objects in a memory-efficient way:

  1. As per the existing implementation, we serialise them to JSON chunk-by-chunk, destroying the original object in the process.
  2. Each chunk is sent to all relevant sessions and destroyed before we begin serialising the next one.

[1] In future work, we should probably move the Host's tracing state and logic into its own TracingTarget class. The naturally close coupling of a Target with its corresponding Agent would be helpful here.

Differential Revision: D90888852

…ets (facebook#55314)

Summary:

TSIA - minor refactor for correctness and clarity before making changes to some of these methods up the stack.

Changelog: [Internal]

Reviewed By: hoxyq

Differential Revision: D91140491
Summary:

Changelog: [Internal]

TSIA - minor refactor for convenience and correctness.

NOTE: When we get C++23, we can deduplicate the identical const/non-const method bodies using the nifty [deducing `this`](https://en.cppreference.com/w/cpp/language/member_functions.html#Explicit_object_member_functions) feature.

Reviewed By: hoxyq

Differential Revision: D91140490
…#55347)

Summary:

Changelog: [Internal]

Moves state and logic related to stashing a background trace from `JReactHostInspectorTarget` (JNI wrapper boilerplate, Android-specific) to `HostTarget` (cross-platform C++).

Managing the full lifecycle of a background trace inside `HostTarget` lets us remove a fair amount of API surface:
* `HostTargetDelegate::unstable_getHostTracingProfileThatWillBeEmittedOnInitialization()`
* `HostTarget::hasActiveSessionWithFuseboxClient()`
* `TracingAgent::emitExternalHostTracingProfile()`

We also refactor some of the surrounding code and add tests (previously missing) for the behaviour of stashed background traces when there is more than one session.

Reviewed By: huntie, hoxyq

Differential Revision: D91589884
Summary:
Changelog: [Internal]

## Behaviour

Fixes an edge case in the way background traces are emitted when multiple RNDT frontends (or other clients with the `ReactNativeApplication` domain enabled) are connected to a single Host. Previously, only one of the clients would receive the CDP events for the trace. With this diff, *all* of them will.

NOTE: This leaves another, even smaller edge case / inconsistency: if there are *no* RNDT frontends at the time a background trace ends, we still only send it to the first frontend (if any) that connects. This is logically more defensible than picking one client out of multiple active connections ( = what's fixed in this diff). 

## Implementation

Tracing functionality is somewhat awkwardly split between `HostTarget` (background traces) and `TracingAgent` (CDP-initiated traces). This diff doesn't attempt to fully clean this up[1], but we do reduce duplication and boilerplate by creating a helper function used by both. This function encapsulates the gnarly/surprising details of dealing with `tracing::HostTracingProfile` objects in a memory-efficient way:

1. As per the existing implementation, we serialise them to JSON chunk-by-chunk, destroying the original object in the process.
2. Each chunk is sent to all relevant sessions *and destroyed* before we begin serialising the next one.

[1] In future work, we should probably move the Host's tracing state and logic into its own `TracingTarget` class. The naturally close coupling of a Target with its corresponding Agent would be helpful here.

Differential Revision: D90888852
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 29, 2026
@meta-codesync
Copy link

meta-codesync bot commented Jan 29, 2026

@motiz88 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D90888852.

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants