Skip to content

Commit d15fc20

Browse files
committed
chore(performance): add content
1 parent f1a02d8 commit d15fc20

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

packages/firebase-performance/README.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,74 @@
11
# @nativescript/firebase-performance
22

3-
```javascript
3+
```cli
44
ns plugin add @nativescript/firebase-performance
55
```
66

7+
## What does it do
8+
9+
Performance Monitoring allows you to gain insight into key performance characteristics within your application. It provides a simple API to track custom trace and HTTP request metrics
10+
11+
[![image](https://img.youtube.com/vi/0EHSPFvH7vk/hqdefault.jpg)](https://www.youtube.com/watch?v=0EHSPFvH7vk)
12+
13+
Review and analyze that data in the Firebase console. Performance Monitoring helps you to understand where and when the performance of your app can be improved so that you can use that information to fix performance issues.
14+
15+
Performance Monitoring package automatically traces events and metrics which are sent to Firebase. For more information on the automatic traces, please see the Firebase Performance Monitoring [documentation](https://firebase.google.com/docs/perf-mon/auto_duration-traces-metrics_ios-android). The package also allows you to performance monitor custom aspects to your application like network requests & task specific app code. All performance metrics are available on your Firebase [console](https://console.firebase.google.com/u/0/) performance tab.
16+
717
## Usage
818

9-
// TODO
19+
### Custom tracing
20+
21+
Below is how you would measure the amount of time it would take to complete a specific task in your app code.
22+
23+
```ts
24+
import { firebase } from '@nativescript/firebase-core';
25+
import '@nativescript/firebase-performance';
26+
async function customTrace() {
27+
// Define & start a trace
28+
const trace = await firebase().perf().startTrace('custom_trace');
29+
30+
// Define trace meta details
31+
trace.putAttribute('user', 'abcd');
32+
trace.putMetric('credits', 30);
33+
34+
// Stop the trace
35+
await trace.stop();
36+
}
37+
```
38+
39+
### HTTP Request Tracing
40+
41+
```ts
42+
import { firebase } from '@nativescript/firebase-core';
43+
import '@nativescript/firebase-performance';
44+
45+
async function getRequest(url) {
46+
// Define the network metric
47+
const metric = await firebase().perf().newHttpMetric(url, 'GET');
48+
49+
// Define meta details
50+
metric.putAttribute('user', 'abcd');
51+
52+
// Start the metric
53+
await metric.start();
54+
55+
// Perform a HTTP request and provide response information
56+
const response = await fetch(url);
57+
metric.setHttpResponseCode(response.statusCode);
58+
metric.setResponseContentType(response.headers['Content-Type']);
59+
metric.setResponsePayloadSize(response.headers['Content-Length']);
60+
61+
// Stop the metric
62+
await metric.stop();
63+
64+
return response.toJSON();
65+
}
66+
67+
// Call API
68+
getRequest('https://api.com').then((json) => {
69+
console.log(json);
70+
});
71+
```
1072

1173
## License
1274

0 commit comments

Comments
 (0)