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

Enable APM features by default #1217

Merged
merged 4 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## Unreleased

### Breaking Changes

- Enable APM features by default ([#1217](https://github.com/getsentry/sentry-dart/pull/1217))
- captureFailedRequests
- enableStructuredDataTracing
- enableUserInteractionTracing

## 7.0.0-alpha.1

### Various fixes & improvements
Expand Down
4 changes: 2 additions & 2 deletions dart/lib/src/http_client/failed_request_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class FailedRequestClient extends BaseClient {
Hub? hub,
}) : _hub = hub ?? HubAdapter(),
_client = client ?? Client() {
if (_hub.options.captureFailedHttpRequests) {
if (_hub.options.captureFailedRequests) {
_hub.options.sdk.addIntegration('HTTPClientError');
}
}
Expand Down Expand Up @@ -111,7 +111,7 @@ class FailedRequestClient extends BaseClient {
// So just one of these blocks can be called.
var capture = false;
String? reason;
if (_hub.options.captureFailedHttpRequests && exception != null) {
if (_hub.options.captureFailedRequests && exception != null) {
capture = true;
} else if (failedRequestStatusCodes.containsStatusCode(statusCode)) {
// Capture an exception if the status code is considered bad
Expand Down
2 changes: 1 addition & 1 deletion dart/lib/src/sentry_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class SentryOptions {
/// - In an mobile or desktop application this can be requests which failed
/// because the connection was interrupted.
/// Use with [SentryHttpClient] or [Dio] integration for this to work
bool captureFailedHttpRequests = false;
bool captureFailedRequests = true;

/// Whether to records requests as breadcrumbs. This is on by default.
/// It only has an effect when the SentryHttpClient or dio integration is in use
Expand Down
11 changes: 7 additions & 4 deletions dart/test/http_client/failed_request_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void main() {
});

test('exception gets reported if client throws', () async {
fixture._hub.options.captureFailedHttpRequests = true;
fixture._hub.options.captureFailedRequests = true;
fixture._hub.options.sendDefaultPii = true;

final sut = fixture.getSut(
Expand Down Expand Up @@ -73,6 +73,7 @@ void main() {
test('event not reported if disabled', () async {
final sut = fixture.getSut(
client: createThrowingClient(),
captureFailedRequests: false,
);

await expectLater(
Expand Down Expand Up @@ -163,7 +164,7 @@ void main() {
});

test('pii is not send on exception', () async {
fixture._hub.options.captureFailedHttpRequests = true;
fixture._hub.options.captureFailedRequests = true;
final sut = fixture.getSut(
client: createThrowingClient(),
);
Expand Down Expand Up @@ -221,7 +222,7 @@ void main() {
MaxBodySizeTestConfig(MaxRequestBodySize.medium, 10001, false),
];

fixture._hub.options.captureFailedHttpRequests = true;
fixture._hub.options.captureFailedRequests = true;
fixture._hub.options.sendDefaultPii = true;
for (final scenario in scenarios) {
fixture._hub.options.maxRequestBodySize = scenario.maxBodySize;
Expand Down Expand Up @@ -251,7 +252,7 @@ void main() {
});

test('request passed to hint', () async {
fixture._hub.options.captureFailedHttpRequests = true;
fixture._hub.options.captureFailedRequests = true;

Request? failedRequest;
final client = MockClient(
Expand Down Expand Up @@ -303,8 +304,10 @@ class Fixture {
FailedRequestClient getSut({
MockClient? client,
List<SentryStatusCode> badStatusCodes = const [],
bool captureFailedRequests = true,
}) {
final mc = client ?? getClient();
_hub.options.captureFailedRequests = captureFailedRequests;
return FailedRequestClient(
client: mc,
hub: _hub,
Expand Down
5 changes: 4 additions & 1 deletion dart/test/http_client/sentry_http_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void main() {
test('no captured event with default config', () async {
final sut = fixture.getSut(
client: createThrowingClient(),
captureFailedRequests: false,
);

await expectLater(() async => await sut.get(requestUri), throwsException);
Expand All @@ -44,7 +45,7 @@ void main() {

test('one captured event with when enabling $FailedRequestClient',
() async {
fixture.hub.options.captureFailedHttpRequests = true;
fixture.hub.options.captureFailedRequests = true;
fixture.hub.options.recordHttpBreadcrumbs = true;
final sut = fixture.getSut(
client: createThrowingClient(),
Expand Down Expand Up @@ -115,8 +116,10 @@ class Fixture {
SentryHttpClient getSut({
MockClient? client,
List<SentryStatusCode> badStatusCodes = const [],
bool captureFailedRequests = true,
}) {
final mc = client ?? getClient();
hub.options.captureFailedRequests = captureFailedRequests;
return SentryHttpClient(
client: mc,
hub: hub,
Expand Down
4 changes: 2 additions & 2 deletions dio/example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ Future<void> main() async {
await Sentry.init(
(options) {
options.dsn = dsn;
options.tracesSampleRate = 1.0; // needed for Dio `networkTracing` feature
options.tracesSampleRate =
1.0; // needed for Dio `captureFailedRequests` feature
options.debug = true;
options.sendDefaultPii = true;

options.maxRequestBodySize = MaxRequestBodySize.small;
options.maxResponseBodySize = MaxResponseBodySize.small;
options.captureFailedRequests = true;
},
appRunner: runApp, // Init your App.
);
Expand Down
2 changes: 1 addition & 1 deletion dio/lib/src/sentry_dio_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension SentryDioExtension on Dio {
options.addEventProcessor(DioEventProcessor(options));
}

if (options.captureFailedHttpRequests) {
if (options.captureFailedRequests) {
// Add FailedRequestInterceptor at index 0, so it's the first interceptor.
// This ensures that it is called and not skipped by any previous interceptor.
interceptors.insert(0, FailedRequestInterceptor());
Expand Down
4 changes: 3 additions & 1 deletion dio/test/sentry_dio_client_adapter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void main() {
});

test('no captured span if tracing disabled', () async {
fixture.hub.options.captureFailedHttpRequests = false;
fixture.hub.options.captureFailedRequests = false;
fixture.hub.options.recordHttpBreadcrumbs = false;
final sut = fixture.getSut(
client: fixture.getClient(statusCode: 200, reason: 'OK'),
Expand Down Expand Up @@ -105,9 +105,11 @@ class Fixture {
MockHttpClientAdapter? client,
MaxRequestBodySize maxRequestBodySize = MaxRequestBodySize.never,
List<SentryStatusCode> badStatusCodes = const [],
bool captureFailedRequests = true,
}) {
final mc = client ?? getClient();
final dio = Dio(BaseOptions(baseUrl: requestUri.toString()));
hub.options.captureFailedRequests = captureFailedRequests;
dio.httpClientAdapter = SentryDioClientAdapter(
client: mc,
hub: hub,
Expand Down
2 changes: 1 addition & 1 deletion flutter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ runApp(
This adds performance tracing for all `AssetBundle` usages, where the `AssetBundle` is accessed with `DefaultAssetBunlde.of(context)`.
This includes all of Flutters internal access of `AssetBundle`s, like `Image.asset` for example.
Tracing for `AssetBundle.loadStructuredData()` is currently disabled.
It's hidden by the `enableStructureDataTracing` flag and considered experimental. Using it could lead to bugs. We recognize the irony.
It's hidden by the `enableStructuredDataTracing` flag and considered experimental. Using it could lead to bugs. We recognize the irony.
marandaneto marked this conversation as resolved.
Show resolved Hide resolved

##### Tracking HTTP events

Expand Down
4 changes: 1 addition & 3 deletions flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Future<void> main() async {
SentryScreenshotWidget(
child: SentryUserInteractionWidget(
child: DefaultAssetBundle(
bundle: SentryAssetBundle(enableStructuredDataTracing: true),
bundle: SentryAssetBundle(),
child: const MyApp(),
),
),
Expand All @@ -50,15 +50,13 @@ Future<void> setupSentry(AppRunner appRunner, String dsn) async {
options.sendDefaultPii = true;
options.reportSilentFlutterErrors = true;
options.enableNdkScopeSync = true;
options.enableUserInteractionTracing = true;
options.attachScreenshot = true;
options.attachViewHierarchy = true;
// We can enable Sentry debug logging during development. This is likely
// going to log too much for your app, but can be useful when figuring out
// configuration issues, e.g. finding out why your events are not uploaded.
options.debug = true;

options.captureFailedHttpRequests = true;
options.maxRequestBodySize = MaxRequestBodySize.always;
options.maxResponseBodySize = MaxResponseBodySize.always;
},
Expand Down
5 changes: 1 addition & 4 deletions flutter/lib/src/sentry_asset_bundle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@ typedef _Parser<T> = Future<T> Function(String value);
/// );
/// ```
/// [Image.asset], for example, will then use [SentryAssetBundle].
///
/// The `enableStructureDataTracing` setting is an experimental feature.
/// Use at your own risk.
class SentryAssetBundle implements AssetBundle {
SentryAssetBundle({
Hub? hub,
AssetBundle? bundle,
bool enableStructuredDataTracing = false,
bool enableStructuredDataTracing = true,
}) : _hub = hub ?? HubAdapter(),
_bundle = bundle ?? rootBundle,
_enableStructuredDataTracing = enableStructuredDataTracing {
Expand Down
2 changes: 1 addition & 1 deletion flutter/lib/src/sentry_flutter_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class SentryFlutterOptions extends SentryOptions {
/// Requires adding the [SentryUserInteractionWidget] to the widget tree.
/// Example:
/// runApp(SentryUserInteractionWidget(child: App()));
bool enableUserInteractionTracing = false;
bool enableUserInteractionTracing = true;

@internal
late RendererWrapper rendererWrapper = RendererWrapper();
Expand Down
4 changes: 1 addition & 3 deletions min_version_test/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Future<void> main() async {
SentryScreenshotWidget(
child: SentryUserInteractionWidget(
child: DefaultAssetBundle(
bundle: SentryAssetBundle(enableStructuredDataTracing: true),
bundle: SentryAssetBundle(),
child: const MyApp(),
),
),
Expand All @@ -37,14 +37,12 @@ Future<void> setupSentry(AppRunner appRunner) async {
options.sendDefaultPii = true;
options.reportSilentFlutterErrors = true;
options.enableNdkScopeSync = true;
options.enableUserInteractionTracing = true;
options.attachScreenshot = true;
options.attachViewHierarchy = true;
// We can enable Sentry debug logging during development. This is likely
// going to log too much for your app, but can be useful when figuring out
// configuration issues, e.g. finding out why your events are not uploaded.
options.debug = true;
options.captureFailedHttpRequests = true;
},
// Init your App.
appRunner: appRunner);
Expand Down