@react-native-firebase/perf 17.0.0 → 17.2.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [17.2.0](https://github.com/invertase/react-native-firebase/compare/v17.1.0...v17.2.0) (2023-02-15)
7
+
8
+ ### Features
9
+
10
+ - **app, android:** firebase-android-sdk 31.2.0 ([87156e7](https://github.com/invertase/react-native-firebase/commit/87156e75e16775db14ef8f9bf6b0049b15ee1277))
11
+
12
+ ## [17.1.0](https://github.com/invertase/react-native-firebase/compare/v17.0.0...v17.1.0) (2023-02-09)
13
+
14
+ ### Features
15
+
16
+ - **perf:** Expose modular API that matches the Firebase web JS SDK v9 API ([#6771](https://github.com/invertase/react-native-firebase/issues/6771)) ([4e170ea](https://github.com/invertase/react-native-firebase/commit/4e170ead24035cd0154b153dcf1e8d69d6ab7ac9))
17
+
6
18
  ## [17.0.0](https://github.com/invertase/react-native-firebase/compare/v16.7.0...v17.0.0) (2023-02-02)
7
19
 
8
20
  **Note:** Version bump only for package @react-native-firebase/perf
@@ -55,6 +55,7 @@ public class UniversalFirebasePerfModule extends UniversalFirebaseModule {
55
55
  constants.put(
56
56
  "isPerformanceCollectionEnabled",
57
57
  FirebasePerformance.getInstance().isPerformanceCollectionEnabled());
58
+ constants.put("isInstrumentationEnabled", true);
58
59
  return constants;
59
60
  }
60
61
 
@@ -58,6 +58,8 @@ RCT_EXPORT_MODULE();
58
58
  NSMutableDictionary *constants = [NSMutableDictionary new];
59
59
  constants[@"isPerformanceCollectionEnabled"] =
60
60
  @([RCTConvert BOOL:@([FIRPerformance sharedInstance].dataCollectionEnabled)]);
61
+ constants[@"isInstrumentationEnabled"] =
62
+ @([RCTConvert BOOL:@([FIRPerformance sharedInstance].instrumentationEnabled)]);
61
63
  return constants;
62
64
  }
63
65
 
@@ -73,7 +75,6 @@ RCT_EXPORT_METHOD(setPerformanceCollectionEnabled
73
75
  : (RCTPromiseResolveBlock)resolve rejecter
74
76
  : (RCTPromiseRejectBlock)reject) {
75
77
  [FIRPerformance sharedInstance].dataCollectionEnabled = (BOOL)enabled;
76
- [FIRPerformance sharedInstance].instrumentationEnabled = (BOOL)enabled;
77
78
  resolve([NSNull null]);
78
79
  }
79
80
 
@@ -203,4 +204,12 @@ RCT_EXPORT_METHOD(stopHttpMetric
203
204
  resolve([NSNull null]);
204
205
  }
205
206
 
207
+ RCT_EXPORT_METHOD(instrumentationEnabled
208
+ : (BOOL)enabled resolver
209
+ : (RCTPromiseResolveBlock)resolve rejecter
210
+ : (RCTPromiseRejectBlock)reject) {
211
+ [FIRPerformance sharedInstance].instrumentationEnabled = (BOOL)enabled;
212
+ resolve([NSNull null]);
213
+ }
214
+
206
215
  @end
package/lib/index.d.ts CHANGED
@@ -426,7 +426,22 @@ export namespace FirebasePerformanceTypes {
426
426
  * ```
427
427
  */
428
428
  isPerformanceCollectionEnabled: boolean;
429
-
429
+ /**
430
+ * Determines whether to collect 'out of the box' (i.e already setup for Firebase Performance) events.
431
+ * This can be set for iOS. Android will always return "true" as it has to be set at gradle level.
432
+ */
433
+ instrumentationEnabled: boolean;
434
+ /**
435
+ * Determines whether performance monitoring is enabled or disabled.
436
+ *
437
+ * #### Example
438
+ *
439
+ * ```js
440
+ * const isEnabled = firebase.perf().dataCollectionEnabled;
441
+ * console.log('Performance collection enabled: ', isEnabled);
442
+ * ```
443
+ */
444
+ dataCollectionEnabled: boolean;
430
445
  /**
431
446
  * Enables or disables performance monitoring.
432
447
  *
@@ -436,8 +451,9 @@ export namespace FirebasePerformanceTypes {
436
451
  * // Disable performance monitoring collection
437
452
  * await firebase.perf().setPerformanceCollectionEnabled(false);
438
453
  * ```
439
- *
440
- * @param enabled Should performance monitoring be enabled
454
+ * @deprecated prefer setting `dataCollectionEnabled = boolean`.
455
+ * @param enabled Should performance monitoring be enabled. For iOS only, this also toggles whether instrumentation
456
+ * is enabled. See: https://firebase.google.com/docs/reference/ios/firebaseperformance/api/reference/Classes/FIRPerformance#instrumentationenabled
441
457
  */
442
458
  setPerformanceCollectionEnabled(enabled: boolean): Promise<null>;
443
459
 
@@ -470,7 +486,7 @@ export namespace FirebasePerformanceTypes {
470
486
 
471
487
  /**
472
488
  * Creates a ScreenTrace instance with the given identifier.
473
- * Throws if hardware acceleration is diabled or if Android is 9.0 or 9.1.
489
+ * Throws if hardware acceleration is disabled or if Android is 9.0 or 9.1.
474
490
  *
475
491
  * #### Example
476
492
  *
@@ -489,7 +505,7 @@ export namespace FirebasePerformanceTypes {
489
505
 
490
506
  /**
491
507
  * Creates a ScreenTrace instance with the given identifier and immediately starts it.
492
- * Throws if hardware acceleration is diabled or if Android is 9.0 or 9.1.
508
+ * Throws if hardware acceleration is disabled or if Android is 9.0 or 9.1.
493
509
  *
494
510
  * #### Example
495
511
  *
package/lib/index.js CHANGED
@@ -21,11 +21,21 @@ import {
21
21
  FirebaseModule,
22
22
  getFirebaseRoot,
23
23
  } from '@react-native-firebase/app/lib/internal';
24
+ import { Platform } from 'react-native';
24
25
  import HttpMetric from './HttpMetric';
25
26
  import Trace from './Trace';
26
27
  import ScreenTrace from './ScreenTrace';
27
28
  import version from './version';
28
29
 
30
+ export {
31
+ getPerformance,
32
+ initializePerformance,
33
+ trace,
34
+ httpMetric,
35
+ newScreenTrace,
36
+ startScreenTrace,
37
+ } from './modular/index';
38
+
29
39
  const statics = {};
30
40
 
31
41
  const namespace = 'perf';
@@ -48,19 +58,55 @@ class FirebasePerfModule extends FirebaseModule {
48
58
  constructor(...args) {
49
59
  super(...args);
50
60
  this._isPerformanceCollectionEnabled = this.native.isPerformanceCollectionEnabled;
61
+ this._instrumentationEnabled = this.native.isInstrumentationEnabled;
51
62
  }
52
63
 
53
64
  get isPerformanceCollectionEnabled() {
54
65
  return this._isPerformanceCollectionEnabled;
55
66
  }
56
67
 
57
- setPerformanceCollectionEnabled(enabled) {
68
+ get instrumentationEnabled() {
69
+ return this._instrumentationEnabled;
70
+ }
71
+
72
+ set instrumentationEnabled(enabled) {
73
+ if (!isBoolean(enabled)) {
74
+ throw new Error("firebase.perf().instrumentationEnabled = 'enabled' must be a boolean.");
75
+ }
76
+ if (Platform.OS == 'ios') {
77
+ // We don't change for android as it cannot be set from code, it is set at gradle build time.
78
+ this._instrumentationEnabled = enabled;
79
+ // No need to await, as it only takes effect on the next app run.
80
+ this.native.instrumentationEnabled(enabled);
81
+ }
82
+ }
83
+
84
+ get dataCollectionEnabled() {
85
+ return this._isPerformanceCollectionEnabled;
86
+ }
87
+
88
+ set dataCollectionEnabled(enabled) {
89
+ if (!isBoolean(enabled)) {
90
+ throw new Error("firebase.perf().dataCollectionEnabled = 'enabled' must be a boolean.");
91
+ }
92
+ this._isPerformanceCollectionEnabled = enabled;
93
+ this.native.setPerformanceCollectionEnabled(enabled);
94
+ }
95
+
96
+ async setPerformanceCollectionEnabled(enabled) {
58
97
  if (!isBoolean(enabled)) {
59
98
  throw new Error(
60
99
  "firebase.perf().setPerformanceCollectionEnabled(*) 'enabled' must be a boolean.",
61
100
  );
62
101
  }
63
102
 
103
+ if (Platform.OS == 'ios') {
104
+ // '_instrumentationEnabled' is updated here as well to maintain backward compatibility. See:
105
+ // https://github.com/invertase/react-native-firebase/commit/b705622e64d6ebf4ee026d50841e2404cf692f85
106
+ this._instrumentationEnabled = enabled;
107
+ await this.native.instrumentationEnabled(enabled);
108
+ }
109
+
64
110
  this._isPerformanceCollectionEnabled = enabled;
65
111
  return this.native.setPerformanceCollectionEnabled(enabled);
66
112
  }
@@ -0,0 +1,89 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import { isBoolean } from '@react-native-firebase/app/lib/common';
19
+ import { firebase } from '..';
20
+
21
+ /**
22
+ * Returns a Performance instance for the given app.
23
+ * @param app - FirebaseApp. Optional.
24
+ * @returns {Performance}
25
+ */
26
+ export function getPerformance(app) {
27
+ if (app) {
28
+ return firebase.app(app.name).perf();
29
+ }
30
+
31
+ return firebase.app().perf();
32
+ }
33
+
34
+ /**
35
+ * Returns a Performance instance for the given app.
36
+ * @param app - FirebaseApp. Required.
37
+ * @param settings - PerformanceSettings. Set "dataCollectionEnabled" which will enable/disable Performance collection.
38
+ * @returns {Performance}
39
+ */
40
+ export async function initializePerformance(app, settings) {
41
+ const perf = firebase.app(app.name).perf();
42
+
43
+ if (settings && isBoolean(settings.dataCollectionEnabled)) {
44
+ await perf.setPerformanceCollectionEnabled(settings.dataCollectionEnabled);
45
+ }
46
+
47
+ return perf;
48
+ }
49
+
50
+ /**
51
+ * Returns a Trace instance.
52
+ * @param perf - Performance instance
53
+ * @param identifier - A String to identify the Trace instance
54
+ * @returns {Trace}
55
+ */
56
+ export function trace(perf, identifier) {
57
+ return perf.newTrace(identifier);
58
+ }
59
+
60
+ /**
61
+ * Returns a HttpMetric instance.
62
+ * @param perf - Performance instance
63
+ * @param identifier - A String to identify the HttpMetric instance
64
+ * @returns {HttpMetric}
65
+ */
66
+ export function httpMetric(perf, identifier, httpMethod) {
67
+ return perf.newHttpMetric(identifier, httpMethod);
68
+ }
69
+
70
+ /**
71
+ * Creates a ScreenTrace instance with the given identifier.
72
+ * Throws if hardware acceleration is disabled or if Android is 9.0 or 9.1.
73
+ * @platform android Android !== 9.0.0 && Android !== 9.1.0
74
+ * @param perf - Performance instance
75
+ * @param identifier Name of the trace, no leading or trailing whitespace allowed, no leading underscore '_' character allowed, max length is 100.
76
+ */
77
+ export function newScreenTrace(perf, identifier) {
78
+ return perf.newScreenTrace(identifier);
79
+ }
80
+ /**
81
+ * Creates a ScreenTrace instance with the given identifier and immediately starts it.
82
+ * Throws if hardware acceleration is disabled or if Android is 9.0 or 9.1.
83
+ * @platform android Android !== 9.0.0 && Android !== 9.1.0
84
+ * @param perf - Performance instance
85
+ * @param identifier Name of the screen
86
+ */
87
+ export function startScreenTrace(perf, identifier) {
88
+ return perf.startScreenTrace(identifier);
89
+ }
package/lib/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- module.exports = '17.0.0';
2
+ module.exports = '17.2.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-firebase/perf",
3
- "version": "17.0.0",
3
+ "version": "17.2.0",
4
4
  "author": "Invertase <oss@invertase.io> (http://invertase.io)",
5
5
  "description": "React Native Firebase - React Native Firebase provides native integration with Performance Monitoring to gain insight into key performance characteristics within your React Native application.",
6
6
  "main": "lib/index.js",
@@ -29,7 +29,7 @@
29
29
  "performance monitoring"
30
30
  ],
31
31
  "peerDependencies": {
32
- "@react-native-firebase/app": "17.0.0"
32
+ "@react-native-firebase/app": "17.2.0"
33
33
  },
34
34
  "dependencies": {
35
35
  "@expo/config-plugins": "^5.0.4"
@@ -37,5 +37,5 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "53a436278f3c4cb23e1ddb7d2c9f14a65ce4abc1"
40
+ "gitHead": "57666670bd7fa4121a6598c639c4b2a24b9d181c"
41
41
  }