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

refactor(performance)!: rework as part of #6979 #7391

Merged
merged 79 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
95e3cb8
tests: initialise firebase app from test driver
russellwheatley Nov 16, 2021
cbcb1d1
test(crashlytics): init from config files
russellwheatley Nov 18, 2021
bf2b84f
chore(performance): update firebase_performance_platform_interface.da…
russellwheatley Nov 18, 2021
850ca99
chore(performance): refactor platform_interface_http_metric.dart
russellwheatley Nov 18, 2021
f884374
refactor(performance): http_metric PI & method channel
russellwheatley Nov 18, 2021
eedd335
refactor(performance): trace PI & method channel
russellwheatley Nov 18, 2021
0f63f64
format
russellwheatley Nov 18, 2021
1274e13
refactor(performance): delegateFor() to lazy load
russellwheatley Nov 18, 2021
4a13d8a
chore(performance): stub number
russellwheatley Nov 18, 2021
3c9e7ee
chore(performance): todo queries
russellwheatley Nov 18, 2021
f901d1c
chore: branched off wrong branch. revert changes.
russellwheatley Nov 18, 2021
0f941be
chore(performance): update method names
russellwheatley Nov 18, 2021
bf5ded5
refactor(performance): universal code update
russellwheatley Nov 18, 2021
71a4e0d
chore(performance): gradle & AndroidManifest.xml updates
russellwheatley Nov 19, 2021
b0bcbac
chore(performance, android): update to follow flutterfire conventions
russellwheatley Nov 19, 2021
95ea4fb
chore(performance): naming
russellwheatley Nov 19, 2021
5456460
chore(performance): update pubspec.yaml's
russellwheatley Nov 19, 2021
ea37484
chore(performance): update example app
russellwheatley Nov 19, 2021
2c1d179
chore(performance): rm myLog example app
russellwheatley Nov 19, 2021
bf1d0d8
chore(performance, ios): updates to config
russellwheatley Nov 19, 2021
edc3080
test(performance): use drive to run tests
russellwheatley Nov 19, 2021
9df326a
test(performance): add unit test to correct file
russellwheatley Nov 19, 2021
3678171
docs(performance): update
russellwheatley Nov 19, 2021
ed0d7f1
chore(performance): error handling
russellwheatley Nov 19, 2021
c176c40
tes(performance): e2e tests
russellwheatley Nov 19, 2021
cae1e04
format
russellwheatley Nov 19, 2021
790898b
refactor(performance): web refactor part 1
russellwheatley Nov 22, 2021
f674397
refactor(performance, ios): extend FLTFirebasePlugin
russellwheatley Nov 22, 2021
ef7c67d
chore(performance, web): js dep
russellwheatley Nov 22, 2021
b6914d7
test(performance): update unit tests
russellwheatley Nov 22, 2021
142b030
refactor(performance, web): update for rework
russellwheatley Nov 23, 2021
d6460c0
refactor(performance): update unit tests & API
russellwheatley Nov 23, 2021
44ad813
refactor(performance): revert Trace & Metric to sync func call
russellwheatley Nov 23, 2021
18be185
format
russellwheatley Nov 24, 2021
476eb6a
refactor(performance): method channel work
russellwheatley Nov 24, 2021
9248aa9
refactor(performance): Trace refactored across plugin
russellwheatley Nov 24, 2021
a17b0d1
chore(dynamic_links): http_metric; uni, method channel, PI & native
russellwheatley Nov 24, 2021
88259f2
chore(dynamic_links): http_metric universal instance unit tests
russellwheatley Nov 24, 2021
2c40e88
chore(dynamic_links): http_metric PI tests & clean up
russellwheatley Nov 24, 2021
2a36d02
chore(dynamic_links): trace PI tests & clean up
russellwheatley Nov 24, 2021
f312578
format
russellwheatley Nov 24, 2021
ebb00d4
test(performance): finish method channel testing
russellwheatley Nov 25, 2021
d90bbfb
test(performance): update e2e tests
russellwheatley Nov 25, 2021
e3ddd2a
test(performance): update unit test for universal
russellwheatley Nov 25, 2021
0fe73c6
test(performance, web): update
russellwheatley Nov 25, 2021
ae9e4f5
chore(performance): update example
russellwheatley Nov 25, 2021
58b7f2e
chore(performance): misc. PR updates
russellwheatley Nov 25, 2021
a43fbd3
chore(performance, ios): rm dead code
russellwheatley Nov 25, 2021
bd24db7
chore(performance): update example
russellwheatley Nov 25, 2021
636f40d
chore(performance): rm dead code
russellwheatley Nov 25, 2021
def9807
chore(performance,android): rm dead code
russellwheatley Nov 25, 2021
562b610
chore(performance,android): Integer type for response code
russellwheatley Nov 25, 2021
e6d8fa7
chore(performance): format & analyse issues
russellwheatley Nov 25, 2021
4016455
format
russellwheatley Nov 25, 2021
0bed9cf
docs(performance): update methods with documentation
russellwheatley Nov 25, 2021
a88aaff
docs(performance): update usage.mdx
russellwheatley Nov 25, 2021
14210ae
refactor(performance, web): rm HttpMetric stub
russellwheatley Nov 25, 2021
94a5d30
test(performance, web): skip HttpMetric e2e for web
russellwheatley Nov 25, 2021
638fc61
analyze issue
russellwheatley Nov 25, 2021
84120e6
format
russellwheatley Nov 25, 2021
994e95d
refactor(performance): rm GoogleService-Info.plist & update example
russellwheatley Nov 26, 2021
def89a9
refactor(performance, ios): ios config
russellwheatley Nov 26, 2021
dda90a3
refactor(performance, web): update
russellwheatley Nov 26, 2021
03a22cf
chore(performance, web): update example
russellwheatley Nov 26, 2021
81e0d68
fix(performance, web): cast to map
russellwheatley Nov 26, 2021
dc9284d
test(performance, web): updates
russellwheatley Nov 26, 2021
1b8517b
docs(performance, web): update
russellwheatley Nov 26, 2021
0999b84
chore: analyze issue
russellwheatley Nov 26, 2021
5c936e5
docs(performance): CHANGELOG.md update
russellwheatley Nov 30, 2021
4f65947
docs(perf): update README.md
russellwheatley Dec 2, 2021
cc90ef9
chore: update docs
Ehesp Dec 2, 2021
5866419
chore: update changelog
Ehesp Dec 2, 2021
bc8527e
Merge branch 'master' into @russell/performance-rework
russellwheatley Dec 6, 2021
e81d6f5
format
russellwheatley Dec 6, 2021
4c57323
Merge branch 'dev' into @russell/performance-rework
russellwheatley Dec 6, 2021
7b1f9ab
chore: pubspec.yaml dep
russellwheatley Dec 6, 2021
3102b76
remove old startTrace method
Salakar Dec 7, 2021
7114254
Merge branches '@russell/performance-rework' and 'dev' of https://git…
Salakar Dec 7, 2021
378c3de
-
Salakar Dec 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions docs/performance/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,4 @@ $ flutter run

## Next Steps

Once installed, you're ready to start using Performance Monitoring in your Flutter Project.

> Additional documentation will be available once the Firebase Performance Monitoring plugin update lands as part of the [FlutterFire roadmap](https://github.com/FirebaseExtended/flutterfire/issues/2582).

<!-- View the [Usage documentation](usage.mdx) to get started. -->
Once installed, head over to the [Usage](./usage.mdx) documentation to learn more.
123 changes: 122 additions & 1 deletion docs/performance/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,125 @@ title: Performance Monitoring
sidebar_label: Usage
---

Performance Monitoring usage
To start using Performance Monitoring for Firebase package within your project, import it at the top of your project files:

```dart
import 'package:firebase_performance/firebase_performance.dart';
```

Before using Performance Monitoring, you must first have ensured you have [initialized FlutterFire](overview#initializing-flutterfire).

To create a new Performance Monitoring for Firebase instance, call the [`instance`](!firebase_performance.FirebasePerformance.instance) getter on [`FirebaseFunctions`](!firebase_performance.FirebasePerformance):

```dart
FirebasePerformance performance = FirebasePerformance.instance;
```

By default, this allows you to interact with Performance Monitoring using the default Firebase App.

## Automatic Tracing

When installed, Android & iOS will automatically report metrics such as application start time, network requests and other useful data.

## Custom tracing

You can create your own traces to monitor performance data associated with specific code in your app. With a custom code trace, you can
measure how long it takes your app to complete a specific task or a set of tasks, for example loading a set of images or querying your database.

To setup a custom trace, create a new `Trace` instance by calling the `newTrace()` method:

```dart
FirebasePerformance performance = FirebasePerformance.instance;

Trace trace = performance.newTrace('custom-trace');
```

The name provided will appear within the Firebase Console, allowing you to provide unique names for different trace metrics.

When it makes sense to start a trace, call the `start()` method on the `Trace` instance. Once started, you can apply custom metric
data to the trace by calling `setMetric()`:

```dart
Trace trace = performance.newTrace('custom-trace');

await trace.start();

// Set metrics you wish to track
trace.setMetric('sum', 200);
trace.setMetric('time', 342340435);
```

The API also allows you to increment metric data:

```dart
trace.setMetric('sum', 200);

// `sum` will be incremented to 201
trace.incrementMetric('sum', 1);
```

You can also set non-metric related data, such as a user id on the trace by calling the `putAttribute()` method. Note,
each trace supports up to 5 attributes.

```dart
trace.putAttribute('userId', '1234');
```

Once your trace has completed, call the `stop()` method. The data will then be sent to the Firebase Console:

```dart
await trace.stop();
```

## HTTP Request Tracing

The network request traces automatically collected by Performance Monitoring include most network requests for your app.

Some requests might not be reported or you might use a different library to make network requests. In these cases,
you can use the Performance Monitoring API to manually instrument custom network request traces. Custom network request traces
are only supported for Apple and Android platforms. To setup a custom network request trace, see below:

```dart
// Using http package to make a network request
import 'package:http/http.dart' as http;

FirebasePerformance performance = FirebasePerformance.instance;

// Create a `HttpMetric` instance using the URL you're requesting as well as the type of request
String url = 'https://firebase.flutter.dev';
HttpMetric metric = performance
.newHttpMetric(url, HttpMethod.Get);

// You may also assign up to 5 attributes for each trace
metric.putAttribute('foo', 'bar');

// Start the trace
await metric.start();

// Make the request
Uri url = Uri.parse(url);
var response = await http.get(url);

// Set specific headers to be collated
metric.responseContentType = response.headers['Content-Type'];
metric.httpResponseCode = response.statusCode;
metric.responsePayloadSize = response.contentLength;

// Stops the trace. This is when the data is sent to the Firebase server and it will appear in your Firebase console
await metric.stop();

```

## Stop Automatic Data Collection

To stop automatic data collection, you can call `setPerformanceCollectionEnabled` like in the example:

```dart
FirebasePerformance performance = FirebasePerformance.instance;

// Custom data collection is, by default, enabled
bool isEnabled = await performance.isPerformanceCollectionEnabled();

// Set data collection to `false`
await performance.setPerformanceCollectionEnabled(false);
```
1 change: 1 addition & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ module.exports = {
],
"Performance Monitoring": [
"performance/overview",
"performance/usage",
toReferenceAPI("firebase_performance"),
toGithubExample("firebase_performance"),
],
Expand Down
23 changes: 23 additions & 0 deletions packages/firebase_performance/firebase_performance/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
## UNRELEASED

The Firebase Performance plugin has been heavily reworked to bring it inline with the federated plugin setup along with adding new features,
documentation and updating unit and end-to-end tests.

- General
- Collecting metric and attribute data was previously an asynchronous task. The API has been reworked to better reflect other Firebase APIs, whereby
setting such data is now a synchronous task. Once a trace or HTTP metric stops, data will be sent to the Firebase services in a single operation.
Because of this, breaking changes are introduced to support the new API.

- **`FirebasePerformance`**
- **BREAKING**: `HttpMetric().putAttribute()` method is now synchronous.
- **BREAKING**: `HttpMetric().removeAttribute()` method is now synchronous.
- **BREAKING**: `HttpMetric().getAttribute()` method is now synchronous.
- **BREAKING**: `HttpMetric().getAttributes()` method is now synchronous.
- **BREAKING**: `Trace().putAttribute()` method is now synchronous.
- **BREAKING**: `Trace().removeAttribute()` method is now synchronous.
- **BREAKING**: `Trace().getAttribute()` method is now synchronous.
- **BREAKING**: `Trace().getAttributes()` method is now synchronous.
- **BREAKING**: `Trace().incrementMetric()` method is now synchronous.
- **BREAKING**: `Trace().setMetric()` method is now synchronous.
- **BREAKING**: `Trace().getMetric()` method is now synchronous.

## 0.7.1+5

- Update a dependency to the latest release.
Expand Down
106 changes: 9 additions & 97 deletions packages/firebase_performance/firebase_performance/README.md
Original file line number Diff line number Diff line change
@@ -1,113 +1,25 @@
# Google Performance Monitoring for Firebase
# Firebase Performance Plugin for Flutter

[![pub package](https://img.shields.io/pub/v/firebase_performance.svg)](https://pub.dev/packages/firebase_performance)

A Flutter plugin to use the [Google Performance Monitoring for Firebase API](https://firebase.google.com/docs/perf-mon/).

For Flutter plugins for other Firebase products, see [README.md](https://github.com/FirebaseExtended/flutterfire/blob/master/README.md).

## Usage

To use this plugin, first connect to Firebase by following the instructions for [Android](https://firebase.flutter.dev/docs/installation/android) / [iOS](https://firebase.flutter.dev/docs/installation/ios) / [Web](https://firebase.flutter.dev/docs/installation/web). Then add this plugin by following [these instructions](https://firebase.flutter.dev/docs/performance/overview). See [`example/lib/main.dart`](example/lib/main.dart) for details on the API usage.

You can confirm that Performance Monitoring results appear in the [Firebase Performance Monitoring console](https://console.firebase.google.com/project/_/performance). Results should appear within a few minutes.

> :warning: **Note:** *First Paint* and *First Contentful Paint* metrics of web page load trace will not be collected; automatic network request traces and screen traces will not always be collected for mobile apps.


### Define a Custom Trace

A custom trace is a report of performance data associated with some of the code in your app. To learn more about custom traces, see the [Performance Monitoring overview](https://firebase.google.com/docs/perf-mon/custom-code-traces).

```dart
final Trace myTrace = FirebasePerformance.instance.newTrace("test_trace");
await myTrace.start();

final Item item = cache.fetch("item");
if (item != null) {
await myTrace.incrementMetric("item_cache_hit", 1);
} else {
await myTrace.incrementMetric("item_cache_miss", 1);
}

await myTrace.stop();
```
A Flutter plugin to use the [Firebase Performance API](https://firebase.google.com/docs/perf-mon/).

### Add monitoring for specific network requests (mobile only)
To learn more about Firebase Performance, please visit the [Firebase website](https://firebase.google.com/products/performance)

Performance Monitoring collects network requests automatically. Although this includes most network requests for your app, some might not be reported. To include specific network requests in Performance Monitoring, add the following code to your app:

```dart
class _MetricHttpClient extends BaseClient {
_MetricHttpClient(this._inner);

final Client _inner;

@override
Future<StreamedResponse> send(BaseRequest request) async {
final HttpMetric metric = FirebasePerformance.instance
.newHttpMetric(request.url.toString(), HttpMethod.Get);

await metric.start();

StreamedResponse response;
try {
response = await _inner.send(request);
metric
..responsePayloadSize = response.contentLength
..responseContentType = response.headers['Content-Type']
..requestPayloadSize = request.contentLength
..httpResponseCode = response.statusCode;
} finally {
await metric.stop();
}
[![pub package](https://img.shields.io/pub/v/firebase_performance.svg)](https://pub.dev/packages/firebase_performance)

return response;
}
}
## Getting Started

class _MyAppState extends State<MyApp> {
.
.
.
Future<void> testHttpMetric() async {
final _MetricHttpClient metricHttpClient = _MetricHttpClient(Client());
To get started with Firebase Performance for Flutter, please [see the documentation](https://firebase.flutter.dev/docs/performance/overview).

final Request request =
Request("SEND", Uri.parse("https://www.google.com"));
## Usage

metricHttpClient.send(request);
}
.
.
.
}
```
To use this plugin, please visit the [Firebase Performance Usage documentation](https://firebase.flutter.dev/docs/performance/usage)

## Issues and feedback

Please file FlutterFire specific issues, bugs, or feature requests in our [issue tracker](https://github.com/FirebaseExtended/flutterfire/issues/new).

Plugin issues that are not specific to Flutterfire can be filed in the [Flutter issue tracker](https://github.com/flutter/flutter/issues/new).

## Contribution
Plugin issues that are not specific to FlutterFire can be filed in the [Flutter issue tracker](https://github.com/flutter/flutter/issues/new).

To contribute a change to this plugin,
please review our [contribution guide](https://github.com/FirebaseExtended/flutterfire/blob/master/CONTRIBUTING.md)
and open a [pull request](https://github.com/FirebaseExtended/flutterfire/pulls).

### Testing

The unit test is in `test` directory which you can run using `flutter test`.

The integration test is in `example/test_driver/firebase_performance_e2e.dart` which you can run on an emulator:
```
cd example
flutter drive --target=./test_driver/firebase_performance_e2e.dart
```

To test the web implementation, [download and run ChromeDriver](https://flutter.dev/docs/testing/integration-tests#running-in-a-browser), and then run `flutter_drive`:

```
flutter drive --target=./test_driver/firebase_performance_e2e.dart -d web-server --release --browser-name=chrome --web-port=8080
```
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ android {
implementation 'com.google.firebase:firebase-perf'
implementation 'androidx.annotation:annotation:1.1.0'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.flutter.plugins.firebaseperformance">
package="io.flutter.plugins.firebase.performance">

<uses-permission android:name="android.permission.INTERNET" />
<application>
<service android:name="com.google.firebase.components.ComponentDiscoveryService">
<meta-data android:name="com.google.firebase.components:io.flutter.plugins.firebaseperformance.FlutterFirebaseAppRegistrar"
<meta-data android:name="com.google.firebase.components:io.flutter.plugins.firebase.performance.FlutterFirebaseAppRegistrar"
android:value="com.google.firebase.components.ComponentRegistrar" />
</service>
</application>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.firebaseperformance;
package io.flutter.plugins.firebase.performance;

import androidx.annotation.Keep;
import com.google.firebase.components.Component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.firebaseperformance;
package io.flutter.plugins.firebase.performance;

import com.google.firebase.perf.FirebasePerformance;
import com.google.firebase.perf.metrics.HttpMetric;
Expand Down Expand Up @@ -36,10 +36,10 @@ private static String parseHttpMethod(String httpMethod) {
}
}

private final FirebasePerformancePlugin plugin;
private final FlutterFirebasePerformancePlugin plugin;
private final FirebasePerformance performance;

FlutterFirebasePerformance(FirebasePerformancePlugin plugin) {
FlutterFirebasePerformance(FlutterFirebasePerformancePlugin plugin) {
this.plugin = plugin;
this.performance = FirebasePerformance.getInstance();
}
Expand Down
Loading