Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FirebasePerformance: Unable to process the PerfMetric due to missing or invalid value #3119

Closed
dngconsulting opened this issue Jan 21, 2020 · 4 comments · Fixed by #3123
Closed
Labels
help: android Needs help implementing a PR relating to Android code. help: good-first-issue Issues that are non-critical issues & well defined for first time contributors. impact: bug New bug report Keep Open avoids the stale bot platform: android plugin: performance Firebase Performance Monitoring
Milestone

Comments

@dngconsulting
Copy link

dngconsulting commented Jan 21, 2020

Hello,

I use 6.2.0 perfmetric dependency. Here's my code, it is exactly the sample provided on the docs.

middleware: [{
    pre: async (context: RequestContext): Promise<void> => {
      metric = firebase.perf().newHttpMetric(context.url, context.method);
      await metric.start();
    },
    post: async (context: ResponseContext): Promise<void> => {
      metric.setHttpResponseCode(context.response.status);
      metric.setResponseContentType(context.response.headers.get('Content-Type'));
      await metric.stop();
    }
  }]

This code always return :
01-21 12:03:20.862 31225 32555 I FirebasePerformance: HTTP ResponseCode is a negative value:0
01-21 12:03:20.862 31225 32555 W FirebasePerformance: Unable to process the PerfMetric due to missing or invalid values. See earlier log statements for additional information on the specific missing/invalid values.

When I log context.response.status, the value type is number and contains the correct information.

I never see my custom perf metrics on firebase console. Other predefined metrics are ok.

Cheers,

Sami

Other logs :

` Bundle  : Key httpResponseCode expected Integer but value was a java.lang.Double.  The default value 0 was returned.
01-21 12:18:08.045  1366  1366 W Bundle  : Attempt to cast generated internal exception:
01-21 12:18:08.045  1366  1366 W Bundle  : java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer
01-21 12:18:08.045  1366  1366 W Bundle  :      at android.os.BaseBundle.getInt(BaseBundle.java:1041)
01-21 12:18:08.045  1366  1366 W Bundle  :      at android.os.BaseBundle.getInt(BaseBundle.java:1023)
01-21 12:18:08.045  1366  1366 W Bundle  :      at io.invertase.firebase.perf.UniversalFirebasePerfModule.lambda$stopHttpMetric$4(UniversalFirebasePerfModule.java:120)
01-21 12:18:08.045  1366  1366 W Bundle  :      at io.invertase.firebase.perf.-$$Lambda$UniversalFirebasePerfModule$8oSWtKLEvWtKoK5hC2zPWKWFldM.call(Unknown Source:6)
01-21 12:18:08.045  1366  1366 W Bundle  :      at com.google.android.gms.tasks.zzv.run(Unknown Source:2)
01-21 12:18:08.045  1366  1366 W Bundle  :      at android.os.Handler.handleCallback(Handler.java:883)
01-21 12:18:08.045  1366  1366 W Bundle  :      at android.os.Handler.dispatchMessage(Handler.java:100)
01-21 12:18:08.045  1366  1366 W Bundle  :      at android.os.Looper.loop(Looper.java:237)
01-21 12:18:08.045  1366  1366 W Bundle  :      at android.app.ActivityThread.main(ActivityThread.java:7762)
01-21 12:18:08.045  1366  1366 W Bundle  :      at java.lang.reflect.Method.invoke(Native Method)
01-21 12:18:08.045  1366  1366 W Bundle  :      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
01-21 12:18:08.045  1366  1366 W Bundle  :      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1047)

`

@Salakar Salakar added plugin: performance Firebase Performance Monitoring impact: bug New bug report labels Jan 21, 2020
@Salakar Salakar added this to the v6.3.0 milestone Jan 21, 2020
@Salakar Salakar added help: good-first-issue Issues that are non-critical issues & well defined for first time contributors. help: android Needs help implementing a PR relating to Android code. platform: android Keep Open avoids the stale bot labels Jan 21, 2020
@Salakar
Copy link
Member

Salakar commented Jan 21, 2020

Hey @dngconsulting thanks for the report, looks like you've found a bug.

The fix for this I think would be using getDouble instead of getInt and casting the double to an int on this line in the https://github.com/invertase/react-native-firebase/blob/master/packages/perf/android/src/main/java/io/invertase/firebase/perf/UniversalFirebasePerfModule.java#L120

e.g. the line now becomes:

httpMetric.setHttpResponseCode((int) httpMetricConfig.getDouble("httpResponseCode"));

Casting as the method only accepts an integer and its coming through from RN as a double;
https://developers.google.com/android/reference/com/google/firebase/perf/metrics/HttpMetric.html#setHttpResponseCode(int)


PRs welcome, otherwise we'll get to it in due course, thanks

@mikehardy
Copy link
Collaborator

I always mention using patch-package in these cases, it's the perfect application until a PR is in and released

@dngconsulting
Copy link
Author

Thanks @Salakar for the investigation. As you can imagine it's an annoying bug because it's nearly impossible to gather any custom metric (which is the main purpose of firebase.perfMetric). patch-package is not a viable solution for me, do you have any idea of the next release date ?

@russellwheatley russellwheatley mentioned this issue Jan 22, 2020
5 tasks
@russellwheatley
Copy link
Member

@dngconsulting I've created a PR (#3123) that will hopefully solve your problem in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help: android Needs help implementing a PR relating to Android code. help: good-first-issue Issues that are non-critical issues & well defined for first time contributors. impact: bug New bug report Keep Open avoids the stale bot platform: android plugin: performance Firebase Performance Monitoring
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants