firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

Performance metrics not pushed when created too early

Open tehGoti opened this issue 7 years ago • 3 comments

[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

tehGoti avatar Dec 02 '19 08:12 tehGoti

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar Dec 02 '19 08:12 google-oss-bot

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.

alikn avatar Dec 09 '19 21:12 alikn

I close this issue for now. Please feel free to reopen if the problem persists.

alikn avatar Dec 11 '19 23:12 alikn