@capacitor-firebase/performance 6.1.0 → 6.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,7 @@ Pod::Spec.new do |s|
13
13
  s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
14
  s.ios.deployment_target = '13.0'
15
15
  s.dependency 'Capacitor'
16
- s.dependency 'FirebasePerformance', '~> 10.25'
16
+ s.dependency 'FirebasePerformance', '~> 11.0'
17
17
  s.swift_version = '5.1'
18
18
  s.static_framework = true
19
19
  end
package/README.md CHANGED
@@ -58,6 +58,66 @@ const isEnabled = async () => {
58
58
  const result = await FirebasePerformance.isEnabled();
59
59
  return result.enabled;
60
60
  };
61
+
62
+ const putAttribute = async () => {
63
+ await FirebasePerformance.putAttribute({
64
+ traceName: 'test_trace',
65
+ attribute: 'user_id',
66
+ value: '123',
67
+ });
68
+ };
69
+
70
+ const getAttribute = async () => {
71
+ const result = await FirebasePerformance.getAttribute({
72
+ traceName: 'test_trace',
73
+ attribute: 'user_id',
74
+ });
75
+ return result.attributes;
76
+ };
77
+
78
+ const getAttributes = async () => {
79
+ const result = await FirebasePerformance.getAttributes({ traceName: 'test_trace' });
80
+ return result.attributes;
81
+ };
82
+
83
+ const removeAttribute = async () => {
84
+ await FirebasePerformance.removeAttribute({
85
+ traceName: 'test_trace',
86
+ attribute: 'user_id',
87
+ });
88
+ };
89
+
90
+ const putMetric = async () => {
91
+ await FirebasePerformance.putMetric({
92
+ traceName: 'test_trace',
93
+ metricName: 'item_cache_hit',
94
+ num: 1,
95
+ });
96
+ };
97
+
98
+ const getMetric = async () => {
99
+ const result = await FirebasePerformance.getMetric({
100
+ traceName: 'test_trace',
101
+ metricName: 'item_cache_hit',
102
+ });
103
+ return result.value;
104
+ };
105
+
106
+ const record = async () => {
107
+ await FirebasePerformance.record({
108
+ traceName: 'test_trace',
109
+ startTime: Date.now(),
110
+ duration: 1000,
111
+ options: {
112
+ metrics: {
113
+ item_cache_hit: 1,
114
+ },
115
+ attributes: {
116
+ user_id: '123',
117
+ },
118
+ },
119
+ });
120
+ };
61
121
  ```
62
122
 
63
123
  ## API
@@ -69,7 +129,15 @@ const isEnabled = async () => {
69
129
  * [`incrementMetric(...)`](#incrementmetric)
70
130
  * [`setEnabled(...)`](#setenabled)
71
131
  * [`isEnabled()`](#isenabled)
132
+ * [`putAttribute(...)`](#putattribute)
133
+ * [`getAttribute(...)`](#getattribute)
134
+ * [`getAttributes(...)`](#getattributes)
135
+ * [`removeAttribute(...)`](#removeattribute)
136
+ * [`putMetric(...)`](#putmetric)
137
+ * [`getMetric(...)`](#getmetric)
138
+ * [`record(...)`](#record)
72
139
  * [Interfaces](#interfaces)
140
+ * [Type Aliases](#type-aliases)
73
141
 
74
142
  </docgen-index>
75
143
 
@@ -160,6 +228,133 @@ Determines whether performance monitoring is enabled or disabled.
160
228
  --------------------
161
229
 
162
230
 
231
+ ### putAttribute(...)
232
+
233
+ ```typescript
234
+ putAttribute(options: PutAttributeOptions) => Promise<void>
235
+ ```
236
+
237
+ Sets a custom attribute of a trace to a given value.
238
+
239
+ | Param | Type |
240
+ | ------------- | ------------------------------------------------------------------- |
241
+ | **`options`** | <code><a href="#putattributeoptions">PutAttributeOptions</a></code> |
242
+
243
+ **Since:** 6.3.0
244
+
245
+ --------------------
246
+
247
+
248
+ ### getAttribute(...)
249
+
250
+ ```typescript
251
+ getAttribute(options: GetAttributeOptions) => Promise<GetAttributeResult>
252
+ ```
253
+
254
+ Returns the value of a custom attribute of a trace.
255
+
256
+ | Param | Type |
257
+ | ------------- | ------------------------------------------------------------------- |
258
+ | **`options`** | <code><a href="#getattributeoptions">GetAttributeOptions</a></code> |
259
+
260
+ **Returns:** <code>Promise&lt;<a href="#getattributeresult">GetAttributeResult</a>&gt;</code>
261
+
262
+ **Since:** 6.3.0
263
+
264
+ --------------------
265
+
266
+
267
+ ### getAttributes(...)
268
+
269
+ ```typescript
270
+ getAttributes(options: GetAttributesOptions) => Promise<GetAttributesResult>
271
+ ```
272
+
273
+ Gets the all the custom attributes of a trace with their values.
274
+
275
+ | Param | Type |
276
+ | ------------- | --------------------------------------------------------------------- |
277
+ | **`options`** | <code><a href="#getattributesoptions">GetAttributesOptions</a></code> |
278
+
279
+ **Returns:** <code>Promise&lt;<a href="#getattributesresult">GetAttributesResult</a>&gt;</code>
280
+
281
+ **Since:** 6.3.0
282
+
283
+ --------------------
284
+
285
+
286
+ ### removeAttribute(...)
287
+
288
+ ```typescript
289
+ removeAttribute(options: RemoveAttributeOptions) => Promise<void>
290
+ ```
291
+
292
+ Removes a custom attribute from a trace given its name.
293
+
294
+ | Param | Type |
295
+ | ------------- | ------------------------------------------------------------------- |
296
+ | **`options`** | <code><a href="#getattributeoptions">GetAttributeOptions</a></code> |
297
+
298
+ **Since:** 6.3.0
299
+
300
+ --------------------
301
+
302
+
303
+ ### putMetric(...)
304
+
305
+ ```typescript
306
+ putMetric(options: PutMetricOptions) => Promise<void>
307
+ ```
308
+
309
+ Sets the value of a custom metric.
310
+
311
+ | Param | Type |
312
+ | ------------- | ------------------------------------------------------------- |
313
+ | **`options`** | <code><a href="#putmetricoptions">PutMetricOptions</a></code> |
314
+
315
+ **Since:** 6.3.0
316
+
317
+ --------------------
318
+
319
+
320
+ ### getMetric(...)
321
+
322
+ ```typescript
323
+ getMetric(options: GetMetricOptions) => Promise<GetMetricResult>
324
+ ```
325
+
326
+ Get the value of a custom metric by name.
327
+
328
+ | Param | Type |
329
+ | ------------- | ------------------------------------------------------------- |
330
+ | **`options`** | <code><a href="#getmetricoptions">GetMetricOptions</a></code> |
331
+
332
+ **Returns:** <code>Promise&lt;<a href="#getmetricresult">GetMetricResult</a>&gt;</code>
333
+
334
+ **Since:** 6.3.0
335
+
336
+ --------------------
337
+
338
+
339
+ ### record(...)
340
+
341
+ ```typescript
342
+ record(options: RecordOptions) => Promise<void>
343
+ ```
344
+
345
+ Records a trace given its name and options.
346
+
347
+ Only available on web.
348
+
349
+ | Param | Type |
350
+ | ------------- | ------------------------------------------------------- |
351
+ | **`options`** | <code><a href="#recordoptions">RecordOptions</a></code> |
352
+
353
+ **Since:** 6.3.0
354
+
355
+ --------------------
356
+
357
+
163
358
  ### Interfaces
164
359
 
165
360
 
@@ -199,6 +394,86 @@ Determines whether performance monitoring is enabled or disabled.
199
394
  | ------------- | -------------------- | --------------------------------------------------------------- | ----- |
200
395
  | **`enabled`** | <code>boolean</code> | `true` if performance monitoring is enabled, otherwise `false`. | 0.1.0 |
201
396
 
397
+
398
+ #### PutAttributeOptions
399
+
400
+ | Prop | Type | Description | Since |
401
+ | --------------- | ------------------- | --------------------------------------- | ----- |
402
+ | **`traceName`** | <code>string</code> | Name of the trace to set its attribute. | 6.3.0 |
403
+ | **`attribute`** | <code>string</code> | Name of the attribute to set its value. | 6.3.0 |
404
+ | **`value`** | <code>string</code> | The value to set to the attribute. | 6.3.0 |
405
+
406
+
407
+ #### GetAttributeResult
408
+
409
+ | Prop | Type | Description | Since |
410
+ | ----------- | --------------------------- | ---------------------------------- | ----- |
411
+ | **`value`** | <code>string \| null</code> | The value of the custom attribute. | 6.3.0 |
412
+
413
+
414
+ #### GetAttributeOptions
415
+
416
+ | Prop | Type | Description | Since |
417
+ | --------------- | ------------------- | -------------------------------------------- | ----- |
418
+ | **`traceName`** | <code>string</code> | Name of the trace to set its attribute. | 6.3.0 |
419
+ | **`attribute`** | <code>string</code> | Name of the attribute to retrieve its value. | 6.3.0 |
420
+
421
+
422
+ #### GetAttributesResult
423
+
424
+ | Prop | Type | Description | Since |
425
+ | ---------------- | --------------------------------------- | ------------------------------------------------------------ | ----- |
426
+ | **`attributes`** | <code>{ [key: string]: string; }</code> | A map of all custom attributes of a trace with their values. | 6.3.0 |
427
+
428
+
429
+ #### GetAttributesOptions
430
+
431
+ | Prop | Type | Description | Since |
432
+ | --------------- | ------------------- | ---------------------------------------- | ----- |
433
+ | **`traceName`** | <code>string</code> | Name of the trace to get its attributes. | 6.3.0 |
434
+
435
+
436
+ #### PutMetricOptions
437
+
438
+ | Prop | Type | Description | Since |
439
+ | ---------------- | ------------------- | ---------------------------------------------------------------------------------------- | ----- |
440
+ | **`traceName`** | <code>string</code> | Name of the trace to set its metric. | 6.3.0 |
441
+ | **`metricName`** | <code>string</code> | The metric name. | 6.3.0 |
442
+ | **`num`** | <code>number</code> | The value to set for the metric. The given value is floored down to the nearest integer. | 6.3.0 |
443
+
444
+
445
+ #### GetMetricResult
446
+
447
+ | Prop | Type | Description | Since |
448
+ | ----------- | ------------------- | ---------------------------------- | ----- |
449
+ | **`value`** | <code>number</code> | The value of the metric if exists. | 6.3.0 |
450
+
451
+
452
+ #### GetMetricOptions
453
+
454
+ | Prop | Type | Description | Since |
455
+ | ---------------- | ------------------- | ------------------------------------ | ----- |
456
+ | **`traceName`** | <code>string</code> | Name of the trace to get its metric. | 6.3.0 |
457
+ | **`metricName`** | <code>string</code> | The metric name. | 6.3.0 |
458
+
459
+
460
+ #### RecordOptions
461
+
462
+ | Prop | Type | Description | Since |
463
+ | --------------- | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ----- |
464
+ | **`traceName`** | <code>string</code> | Name of the trace to record. | 6.3.0 |
465
+ | **`startTime`** | <code>number</code> | Start time of the trace since epoch in milliseconds. | 6.3.0 |
466
+ | **`duration`** | <code>number</code> | The duration of the trace in milliseconds. | 6.3.0 |
467
+ | **`options`** | <code>{ metrics?: { [key: string]: number; }; attributes?: { [key: string]: string; }; }</code> | An optional object that holds optional maps of custom metrics and attributes. | 6.3.0 |
468
+
469
+
470
+ ### Type Aliases
471
+
472
+
473
+ #### RemoveAttributeOptions
474
+
475
+ <code><a href="#getattributeoptions">GetAttributeOptions</a></code>
476
+
202
477
  </docgen-api>
203
478
 
204
479
  ## Changelog
@@ -2,6 +2,7 @@ package io.capawesome.capacitorjs.plugins.firebase.performance;
2
2
 
3
3
  import com.google.firebase.perf.metrics.Trace;
4
4
  import java.util.HashMap;
5
+ import java.util.Map;
5
6
 
6
7
  public class FirebasePerformance {
7
8
 
@@ -39,6 +40,30 @@ public class FirebasePerformance {
39
40
  return this.getFirebasePerformanceInstance().isPerformanceCollectionEnabled();
40
41
  }
41
42
 
43
+ public static void putAttribute(Trace trace, String attribute, String value) {
44
+ trace.putAttribute(attribute, value);
45
+ }
46
+
47
+ public static String getAttribute(Trace trace, String attribute) {
48
+ return trace.getAttribute(attribute);
49
+ }
50
+
51
+ public static Map<String, String> getAttributes(Trace trace) {
52
+ return trace.getAttributes();
53
+ }
54
+
55
+ public static void removeAttribute(Trace trace, String attribute) {
56
+ trace.removeAttribute(attribute);
57
+ }
58
+
59
+ public static void putMetric(Trace trace, String metricName, long num) {
60
+ trace.putMetric(metricName, num);
61
+ }
62
+
63
+ public static long getMetric(Trace trace, String metricName) {
64
+ return trace.getLongMetric(metricName);
65
+ }
66
+
42
67
  private com.google.firebase.perf.FirebasePerformance getFirebasePerformanceInstance() {
43
68
  return com.google.firebase.perf.FirebasePerformance.getInstance();
44
69
  }
@@ -7,6 +7,7 @@ import com.getcapacitor.PluginCall;
7
7
  import com.getcapacitor.PluginMethod;
8
8
  import com.getcapacitor.annotation.CapacitorPlugin;
9
9
  import com.google.firebase.perf.metrics.Trace;
10
+ import java.util.Map;
10
11
 
11
12
  @CapacitorPlugin(name = "FirebasePerformance")
12
13
  public class FirebasePerformancePlugin extends Plugin {
@@ -17,6 +18,12 @@ public class FirebasePerformancePlugin extends Plugin {
17
18
  public static final String ERROR_TRACE_NAME_ALREADY_ASSIGNED = "traceName already assigned.";
18
19
  public static final String ERROR_ENABLED_MISSING = "enabled must be provided.";
19
20
  public static final String ERROR_TRACE_NOT_FOUND = "No trace was found with the provided traceName.";
21
+ public static final String ERROR_ATTRIBUTE_MISSING = "attribute must be provided.";
22
+ public static final String ERROR_VALUE_MISSING = "value must be provided.";
23
+ public static final String ERROR_NUM_MISSING = "num must be provided.";
24
+ public static final String ERROR_START_TIME_MISSING = "startTime must be provided.";
25
+ public static final String ERROR_DURATION_MISSING = "duration must be provided.";
26
+ public static final String ERROR_INVALID_METRIC_VALUE = "provided metric value is not a number.";
20
27
  private FirebasePerformance implementation = new FirebasePerformance();
21
28
 
22
29
  @PluginMethod
@@ -116,4 +123,180 @@ public class FirebasePerformancePlugin extends Plugin {
116
123
  call.reject(exception.getMessage());
117
124
  }
118
125
  }
126
+
127
+ @PluginMethod
128
+ public void putAttribute(PluginCall call) {
129
+ try {
130
+ String traceName = call.getString("traceName");
131
+ if (traceName == null) {
132
+ call.reject(FirebasePerformancePlugin.ERROR_TRACE_NAME_MISSING);
133
+ return;
134
+ }
135
+ String attribute = call.getString("attribute");
136
+ if (attribute == null) {
137
+ call.reject(FirebasePerformancePlugin.ERROR_ATTRIBUTE_MISSING);
138
+ return;
139
+ }
140
+ String value = call.getString("value");
141
+ if (value == null) {
142
+ call.reject(FirebasePerformancePlugin.ERROR_VALUE_MISSING);
143
+ return;
144
+ }
145
+ Trace trace = implementation.getTraceByName(traceName);
146
+ if (trace == null) {
147
+ call.reject(ERROR_TRACE_NOT_FOUND);
148
+ return;
149
+ }
150
+ FirebasePerformance.putAttribute(trace, attribute, value);
151
+ call.resolve();
152
+ } catch (Exception exception) {
153
+ Logger.error(TAG, exception.getMessage(), exception);
154
+ call.reject(exception.getMessage());
155
+ }
156
+ }
157
+
158
+ @PluginMethod
159
+ public void getAttribute(PluginCall call) {
160
+ try {
161
+ String traceName = call.getString("traceName");
162
+ if (traceName == null) {
163
+ call.reject(FirebasePerformancePlugin.ERROR_TRACE_NAME_MISSING);
164
+ return;
165
+ }
166
+ String attribute = call.getString("attribute");
167
+ if (attribute == null) {
168
+ call.reject(FirebasePerformancePlugin.ERROR_ATTRIBUTE_MISSING);
169
+ return;
170
+ }
171
+ Trace trace = implementation.getTraceByName(traceName);
172
+ if (trace == null) {
173
+ call.reject(ERROR_TRACE_NOT_FOUND);
174
+ return;
175
+ }
176
+ String value = FirebasePerformance.getAttribute(trace, attribute);
177
+ JSObject result = new JSObject();
178
+ result.put("value", value);
179
+ call.resolve(result);
180
+ } catch (Exception exception) {
181
+ Logger.error(TAG, exception.getMessage(), exception);
182
+ call.reject(exception.getMessage());
183
+ }
184
+ }
185
+
186
+ @PluginMethod
187
+ public void getAttributes(PluginCall call) {
188
+ try {
189
+ String traceName = call.getString("traceName");
190
+ if (traceName == null) {
191
+ call.reject(ERROR_TRACE_NAME_MISSING);
192
+ return;
193
+ }
194
+ Trace trace = implementation.getTraceByName(traceName);
195
+ if (trace == null) {
196
+ call.reject(ERROR_TRACE_NOT_FOUND);
197
+ return;
198
+ }
199
+ Map<String, String> attributesMap = FirebasePerformance.getAttributes(trace);
200
+ JSObject result = new JSObject();
201
+ JSObject resultMap = new JSObject();
202
+ for (String attribute : attributesMap.keySet()) {
203
+ resultMap.put(attribute, attributesMap.get(attribute));
204
+ }
205
+ result.put("result", resultMap);
206
+ call.resolve(result);
207
+ } catch (Exception exception) {
208
+ Logger.error(TAG, exception.getMessage(), exception);
209
+ call.reject(exception.getMessage());
210
+ }
211
+ }
212
+
213
+ @PluginMethod
214
+ public void removeAttribute(PluginCall call) {
215
+ try {
216
+ String traceName = call.getString("traceName");
217
+ if (traceName == null) {
218
+ call.reject(FirebasePerformancePlugin.ERROR_TRACE_NAME_MISSING);
219
+ return;
220
+ }
221
+ String attribute = call.getString("attribute");
222
+ if (attribute == null) {
223
+ call.reject(FirebasePerformancePlugin.ERROR_ATTRIBUTE_MISSING);
224
+ return;
225
+ }
226
+ Trace trace = implementation.getTraceByName(traceName);
227
+ if (trace == null) {
228
+ call.reject(ERROR_TRACE_NOT_FOUND);
229
+ return;
230
+ }
231
+ FirebasePerformance.removeAttribute(trace, attribute);
232
+ call.resolve();
233
+ } catch (Exception exception) {
234
+ Logger.error(TAG, exception.getMessage(), exception);
235
+ call.reject(exception.getMessage());
236
+ }
237
+ }
238
+
239
+ @PluginMethod
240
+ public void putMetric(PluginCall call) {
241
+ try {
242
+ String traceName = call.getString("traceName");
243
+ if (traceName == null) {
244
+ call.reject(FirebasePerformancePlugin.ERROR_TRACE_NAME_MISSING);
245
+ return;
246
+ }
247
+ String metricName = call.getString("metricName");
248
+ if (metricName == null) {
249
+ call.reject(FirebasePerformancePlugin.ERROR_METRIC_NAME_MISSING);
250
+ return;
251
+ }
252
+ Double num = call.getDouble("num");
253
+ if (num == null) {
254
+ call.reject(FirebasePerformancePlugin.ERROR_NUM_MISSING);
255
+ return;
256
+ }
257
+ Trace trace = implementation.getTraceByName(traceName);
258
+ if (trace == null) {
259
+ call.reject(ERROR_TRACE_NOT_FOUND);
260
+ return;
261
+ }
262
+ FirebasePerformance.putMetric(trace, metricName, (long) Math.floor(num));
263
+ call.resolve();
264
+ } catch (Exception exception) {
265
+ Logger.error(TAG, exception.getMessage(), exception);
266
+ call.reject(exception.getMessage());
267
+ }
268
+ }
269
+
270
+ @PluginMethod
271
+ public void getMetric(PluginCall call) {
272
+ try {
273
+ String traceName = call.getString("traceName");
274
+ if (traceName == null) {
275
+ call.reject(FirebasePerformancePlugin.ERROR_TRACE_NAME_MISSING);
276
+ return;
277
+ }
278
+ String metricName = call.getString("metricName");
279
+ if (metricName == null) {
280
+ call.reject(FirebasePerformancePlugin.ERROR_METRIC_NAME_MISSING);
281
+ return;
282
+ }
283
+ Trace trace = implementation.getTraceByName(traceName);
284
+ if (trace == null) {
285
+ call.reject(ERROR_TRACE_NOT_FOUND);
286
+ return;
287
+ }
288
+ long value = FirebasePerformance.getMetric(trace, metricName);
289
+ JSObject result = new JSObject();
290
+ result.put("value", value);
291
+ call.resolve(result);
292
+ } catch (Exception exception) {
293
+ Logger.error(TAG, exception.getMessage(), exception);
294
+ call.reject(exception.getMessage());
295
+ }
296
+ }
297
+
298
+ @PluginMethod
299
+ public void record(PluginCall call) {
300
+ call.unimplemented("Not implemented on Android.");
301
+ }
119
302
  }