-
-
Notifications
You must be signed in to change notification settings - Fork 271
SentryIOOverridesIntegration #1362
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
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
b020ac6
add SentryIOOverridesIntegration
denrase dd7de03
Merge branch 'main' into feat/io-overrides-integration
denrase bdc195c
Merge branch 'main' into feat/io-overrides-integration
denrase 8c0e89d
check tracing in integration
denrase 8d770ef
add tests
denrase f15574e
add documentation
denrase d7e23f1
add changelog entry
denrase b8b40fb
only restore if tracing is enabled
denrase cd289c9
remove incorrect comment
denrase ad5f429
persist if integration was installed
denrase 549041e
Merge branch 'main' into feat/io-overrides-integration
denrase 4e991d4
update changelog
denrase 33d5dd2
Merge branch 'main' into feat/io-overrides-integration
denrase 9132997
make sure created file is sentryfile after installing integration
denrase a41db5c
export io_overrides
denrase ceee690
add documentation
denrase c1f860a
fix changelog entry
denrase 66fe848
format
denrase 36a1a77
document restore behaviour
denrase c59ef1a
Merge branch 'main' into feat/io-overrides-integration
marandaneto 519e875
fix
marandaneto 313745c
Merge branch 'main' into feat/io-overrides-integration
denrase 12a9c26
reset properties when integration is closed
denrase 65f8dbb
Merge branch 'main' into feat/io-overrides-integration
marandaneto 56d1736
lint
marandaneto 00b7f5b
Merge branch 'main' into feat/io-overrides-integration
marandaneto 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export 'src/sentry_file.dart'; | ||
export 'src/sentry_file_extension.dart'; | ||
export 'src/sentry_io_overrides_integration.dart'; | ||
export 'src/sentry_io_overrides.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,21 @@ | ||
import 'dart:io'; | ||
import 'package:sentry/sentry.dart'; | ||
|
||
import '../sentry_file.dart'; | ||
|
||
/// If set to [IOOverrides.global], newly created [File] instances will be of | ||
/// type [SentryFile]. | ||
/// Enable by adding [SentryIOOverridesIntegration] to [SentryOptions]. | ||
class SentryIOOverrides extends IOOverrides { | ||
denrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
final Hub _hub; | ||
|
||
SentryIOOverrides(this._hub); | ||
|
||
@override | ||
File createFile(String path) { | ||
return SentryFile( | ||
super.createFile(path), | ||
hub: _hub, | ||
); | ||
} | ||
} |
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,35 @@ | ||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:sentry/sentry.dart'; | ||
import 'sentry_io_overrides.dart'; | ||
|
||
/// When installed, every new file will be created as [SentryFile]. | ||
/// When installed, operations will use [SentryFile] instead of dart:io's [File] | ||
/// implementation whenever [File] is used. | ||
/// | ||
/// When closed, the [IOOverrides.current] value before this integration was | ||
/// added will be assigned to [IOOverrides.global]. | ||
class SentryIOOverridesIntegration extends Integration<SentryOptions> { | ||
IOOverrides? _previousOverrides; | ||
bool _installed = false; | ||
|
||
@override | ||
FutureOr<void> call(Hub hub, SentryOptions options) { | ||
if (options.isTracingEnabled()) { | ||
_previousOverrides = IOOverrides.current; | ||
marandaneto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_installed = true; | ||
IOOverrides.global = SentryIOOverrides(hub); | ||
options.sdk.addIntegration('sentryIOOverridesIntegration'); | ||
} | ||
} | ||
|
||
@override | ||
FutureOr<void> close() { | ||
if (_installed) { | ||
IOOverrides.global = _previousOverrides; | ||
denrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_previousOverrides = null; | ||
_installed = false; | ||
} | ||
} | ||
} |
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,77 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:sentry/sentry.dart'; | ||
import 'package:sentry_file/sentry_file.dart'; | ||
import 'package:test/expect.dart'; | ||
import 'package:test/scaffolding.dart'; | ||
|
||
import 'mock_sentry_client.dart'; | ||
|
||
void main() { | ||
denrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
late IOOverrides? current; | ||
late Fixture fixture; | ||
|
||
setUp(() { | ||
current = IOOverrides.current; | ||
fixture = Fixture(); | ||
}); | ||
|
||
tearDown(() { | ||
IOOverrides.global = current; | ||
}); | ||
|
||
test('adding integration installs io overrides', () { | ||
fixture.options.tracesSampleRate = 1.0; | ||
|
||
final sut = fixture.getSut(); | ||
sut.call(fixture.hub, fixture.options); | ||
|
||
expect( | ||
fixture.options.sdk.integrations.contains('sentryIOOverridesIntegration'), | ||
isTrue, | ||
); | ||
expect(IOOverrides.current is SentryIOOverrides, isTrue); | ||
}); | ||
|
||
test('not installed when tracing disabled', () { | ||
final sut = fixture.getSut(); | ||
sut.call(fixture.hub, fixture.options); | ||
|
||
expect( | ||
fixture.options.sdk.integrations.contains('sentryIOOverridesIntegration'), | ||
isFalse, | ||
); | ||
expect(IOOverrides.current is SentryIOOverrides, isFalse); | ||
}); | ||
|
||
test('global overrides restored', () { | ||
final previous = IOOverrides.current; | ||
|
||
fixture.options.tracesSampleRate = 1.0; | ||
|
||
final sut = fixture.getSut(); | ||
sut.call(fixture.hub, fixture.options); | ||
sut.close(); | ||
|
||
expect(IOOverrides.current, previous); | ||
}); | ||
|
||
test('files created are sentry file after adding integration', () { | ||
fixture.options.tracesSampleRate = 1.0; | ||
|
||
final sut = fixture.getSut(); | ||
sut.call(fixture.hub, fixture.options); | ||
|
||
final file = File("/home"); | ||
expect(file is SentryFile, true); | ||
}); | ||
} | ||
|
||
class Fixture { | ||
final options = SentryOptions(dsn: fakeDsn); | ||
late final hub = Hub(options); | ||
|
||
SentryIOOverridesIntegration getSut() { | ||
return SentryIOOverridesIntegration(); | ||
} | ||
} |
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.