Performance metrics not pushed when created too early
[REQUIRED] Describe your environment
- Operating System version: OSX 10.15.1
- Browser version: Google Chrome 78
- Firebase SDK version: 7.5.0
- Firebase Product: performance
[REQUIRED] Describe the problem
Steps to reproduce:
- create a barebone app with Firebase performance
- call
firebase.initializeApp() - right after this call
const perf = firebase.performance();
const trace = perf.trace('test');
trace.putMetric('my-test-metric', 1000);
- What should happen: the metric is pushed to Firebase
- What does happen: no metric is pushed
Relevant Code:
https://firebase-issue-sandbox-rpotbr.stackblitz.io/
Additional
I think that the reason for this behaviour is here: https://github.com/firebase/firebase-js-sdk/blob/master/packages/performance/src/services/perf_logger.ts#L120
SettingsService is checked for loggingEnabled and logTraceAfterSampling, both are false right after calling performance().
getInitializationPromise would wait for the config init to happen but logTrace returns before calling it
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
In Firebase Performance, metrics are only recorded in the context of a trace. Meaning that, a trace needs to be created for the metrics to be logged. Initializing a trace is not enough for a trace record to be created. It has to measure a duration using either trace.start() and trace.stop() methods or trace.record method.
I close this issue for now. Please feel free to reopen if the problem persists.