Skip to content

Commit

Permalink
Log to scribe using scribe_cat
Browse files Browse the repository at this point in the history
Summary:
Use `scribe_cat` for Metro Scribe logs (Scuba: `perfpipe_react_packager`, LogView: `errorlog_metro_bundler_javascript`), as opposed to direct `fetch` to GraphQL.

We've [previously seen](https://fb.workplace.com/groups/rn.support/posts/24467303359558282) instances where in poor network conditions or with some misconfiguration, Metro would perform poorly but - for the same reason - we wouldn't log anything to LogView. By delegating logging to `scribe_cat`, which has a long-lived persistent buffer, we should lose fewer messages.

This is also much faster, as `scribe_cat` maintains its own persistent local buffer and returns immediately, so we don't have to wait for a series of remote calls to flush Metro's buffer (Metro's scribe volume can be quite large, as each transformed file generates several logs, a startup with prebundling can be many thousands). This was also contributing factor to "Timed out waiting for graceful shutdown ... Telemetry may have been lost".

Finally, this removes the need for a hardcoded ID/token.

Follows similar changes in D49277801 and D45812150

NB: Categories must still be [allowlisted](https://www.internalfb.com/intern/wiki/Scribe/users/Knowledge_Base/Interacting_with_Scribe_categories/Graph_API/category_access/#common-scenario-1-allow) in GraphQL to make it from a local machine to Scuba. A non-allowlisted category will work from prod, but on corp (backed by GraphQL rather than Thrift) it will be accepted by scribe_cat only to fail unobservably when flushed.

Reviewed By: huntie

Differential Revision: D63226891

fbshipit-source-id: 44ef6260e8e9ff97c97effd6cdff40f5761ea433
  • Loading branch information
robhogan authored and facebook-github-bot committed Sep 23, 2024
1 parent bfd9473 commit 398939a
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions packages/metro/src/lib/BatchProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict
* @format
* @oncall react_native
*/
Expand Down Expand Up @@ -54,8 +54,6 @@ class BatchProcessor<TItem, TResult> {
this._queue = [];
this._timeoutHandle = null;
this._currentProcessCount = 0;
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
(this: any)._processQueue = this._processQueue.bind(this);
}

_onBatchFinished(): void {
Expand Down Expand Up @@ -90,25 +88,21 @@ class BatchProcessor<TItem, TResult> {
this._processBatch(
jobs.map((job: QueueItem<TItem, TResult>) => job.item),
).then(
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
this._onBatchResults.bind(this, jobs),
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
this._onBatchError.bind(this, jobs),
results => this._onBatchResults(jobs, results),
error => this._onBatchError(jobs, error),
);
}
}

_processQueueOnceReady(): void {
if (this._queue.length >= this._options.maximumItems) {
clearTimeout(this._timeoutHandle);
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
process.nextTick(this._processQueue);
process.nextTick(() => this._processQueue());
return;
}
if (this._timeoutHandle == null) {
this._timeoutHandle = setTimeout(
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
this._processQueue,
() => this._processQueue(),
this._options.maximumDelayMs,
);
}
Expand Down

0 comments on commit 398939a

Please sign in to comment.