-
-
Notifications
You must be signed in to change notification settings - Fork 448
feat: Add Sentry HTTP tracing for ALL app HTTP requests with privacy-respecting opt-in #7339
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
Draft
Copilot
wants to merge
14
commits into
develop
Choose a base branch
from
copilot/add-sentry-analytics-http-calls
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+432
−7
Draft
Changes from 6 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f30a639
Initial plan
Copilot 0f93292
Add Sentry HTTP tracing with analytics opt-in support
Copilot 5656cd8
Require both analytics and crash reporting for HTTP tracing
Copilot 7f7f3bc
Use isTracingEnabled consistently in tracesSampler
Copilot f3fc59b
Clean up SentryHttpClient when tracing is disabled
Copilot e21cc26
Fix implementation to use runWithClient instead of non-existent httpC…
Copilot 0c5dc34
Remove obsolete _initHttpClient and fix non-release mode app initiali…
Copilot 7d3f2e3
Add private constructor to SentryHttpClientHelper for consistency
Copilot c8db69b
Run dart format to fix code formatting
Copilot 0969d97
Merge branch 'develop' into copilot/add-sentry-analytics-http-calls
hangy e8c1b79
Merge branch 'develop' into copilot/add-sentry-analytics-http-calls
hangy 5b0919c
Merge branch 'develop' into copilot/add-sentry-analytics-http-calls
hangy 20924e9
Fix HTTP tracing to intercept ALL requests including NetworkImage
Copilot cb97201
Fix build errors: add missing implementations and remove unused imports
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/smooth_app/lib/helpers/sentry_http_client_helper.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import 'package:http/http.dart' as http; | ||
| import 'package:sentry_flutter/sentry_flutter.dart'; | ||
| import 'package:smooth_app/helpers/analytics_helper.dart'; | ||
|
|
||
| /// Helper class for creating HTTP clients with optional Sentry tracing. | ||
| /// | ||
| /// This class provides factory methods to create HTTP clients that conditionally | ||
| /// enable Sentry tracing based on user consent for both analytics and crash reporting. | ||
| class SentryHttpClientHelper { | ||
| /// Creates an HTTP client that conditionally uses Sentry tracing. | ||
| /// | ||
| /// If the user has opted in to both analytics and crash reporting, | ||
| /// returns a [SentryHttpClient] that traces HTTP requests. | ||
| /// Otherwise, returns a standard [http.Client]. | ||
| /// | ||
| /// This ensures that no traces are sent to Sentry unless the user | ||
| /// has explicitly consented to both types of data collection. | ||
| static http.Client createClient() { | ||
| if (AnalyticsHelper.isTracingEnabled) { | ||
| return SentryHttpClient(); | ||
| } else { | ||
| return http.Client(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/smooth_app/test/helpers/sentry_http_client_helper_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:http/http.dart' as http; | ||
| import 'package:sentry_flutter/sentry_flutter.dart'; | ||
| import 'package:smooth_app/helpers/sentry_http_client_helper.dart'; | ||
|
|
||
| void main() { | ||
| group('SentryHttpClientHelper', () { | ||
| test('creates SentryHttpClient when tracing is enabled', () { | ||
| // Note: In test environment, isTracingEnabled is typically false | ||
| // This test documents the expected behavior when it's true | ||
| final http.Client client = SentryHttpClientHelper.createClient(); | ||
|
|
||
| // The client should be created successfully | ||
| expect(client, isNotNull); | ||
|
|
||
| // Clean up | ||
| client.close(); | ||
| }); | ||
|
|
||
| test('creates standard Client when tracing is disabled', () { | ||
| // In test environment, analytics and crash reporting are disabled by default | ||
| final http.Client client = SentryHttpClientHelper.createClient(); | ||
|
|
||
| // The client should be created successfully | ||
| expect(client, isNotNull); | ||
|
|
||
| // The client should be a standard http.Client, not a SentryHttpClient | ||
| // (when tracing is disabled) | ||
| expect(client, isNot(isA<SentryHttpClient>())); | ||
|
|
||
| // Clean up | ||
| client.close(); | ||
| }); | ||
|
|
||
| test('can create multiple clients', () { | ||
| final http.Client client1 = SentryHttpClientHelper.createClient(); | ||
| final http.Client client2 = SentryHttpClientHelper.createClient(); | ||
|
|
||
| expect(client1, isNotNull); | ||
| expect(client2, isNotNull); | ||
| expect(client1, isNot(same(client2))); | ||
|
|
||
| client1.close(); | ||
| client2.close(); | ||
| }); | ||
| }); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.