From 805ed2d6b259274d50b84cb439b3ff6e9160daa0 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 10 Jul 2024 01:52:14 +0200 Subject: [PATCH 01/10] parse semver --- .../enricher/io_enricher_event_processor.dart | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart index 63304cdbf6..67f72fe057 100644 --- a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart +++ b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart @@ -54,8 +54,18 @@ class IoEnricherEventProcessor implements EnricherEventProcessor { List _getRuntimes(List? runtimes) { // Pure Dart doesn't have specific runtimes per build mode // like Flutter: https://flutter.dev/docs/testing/build-modes - final dartRuntime = SentryRuntime( + + // Regex taken from semver package + final versionRegex = RegExp(r'^' // Start at beginning. + r'(\d+)\.(\d+)\.(\d+)' // Version number. + r'(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?' // Pre-release. + r'(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?' // Build. + r' \((beta|stable)\)'); // Channel. + final version = versionRegex.stringMatch(Platform.version); + + SentryRuntime dartRuntime = SentryRuntime( name: 'Dart', + version: version ?? Platform.version, rawDescription: Platform.version, ); if (runtimes == null) { From 727e861f05ee1fc729c9f7e78a982d3999ac61ab Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 10 Jul 2024 01:57:06 +0200 Subject: [PATCH 02/10] use split --- .../enricher/io_enricher_event_processor.dart | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart index 67f72fe057..7ba29b2ffd 100644 --- a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart +++ b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart @@ -51,21 +51,29 @@ class IoEnricherEventProcessor implements EnricherEventProcessor { ); } + /// Extracts the version from the full version string. + /// Example of full version string: + /// 3.5.0-180.3.beta (beta) (Wed Jun 5 15:06:15 2024 +0000) on "android_arm64" + String _extractVersionWithChannel(String fullVersion) { + List parts = fullVersion.split(') '); + + // If there's at least one ')', return the first part plus ')' + if (parts.length > 1) { + return '${parts[0]})'; + } + + // If there's no ')', return the whole string (shouldn't happen with given format) + return fullVersion; + } + List _getRuntimes(List? runtimes) { // Pure Dart doesn't have specific runtimes per build mode // like Flutter: https://flutter.dev/docs/testing/build-modes - // Regex taken from semver package - final versionRegex = RegExp(r'^' // Start at beginning. - r'(\d+)\.(\d+)\.(\d+)' // Version number. - r'(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?' // Pre-release. - r'(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?' // Build. - r' \((beta|stable)\)'); // Channel. - final version = versionRegex.stringMatch(Platform.version); - + final version = _extractVersionWithChannel(Platform.version); SentryRuntime dartRuntime = SentryRuntime( name: 'Dart', - version: version ?? Platform.version, + version: version, rawDescription: Platform.version, ); if (runtimes == null) { From f112589da4e8a42d8f89adb1b4df828e914540e4 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 10 Jul 2024 08:00:39 +0200 Subject: [PATCH 03/10] Update --- .../enricher/io_enricher_event_processor.dart | 13 ++++++------- .../event_processor/enricher/io_enricher_test.dart | 4 ++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart index 7ba29b2ffd..2062960f83 100644 --- a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart +++ b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart @@ -51,18 +51,17 @@ class IoEnricherEventProcessor implements EnricherEventProcessor { ); } - /// Extracts the version from the full version string. - /// Example of full version string: + /// Extracts the semantic version and channel from the full version string. /// 3.5.0-180.3.beta (beta) (Wed Jun 5 15:06:15 2024 +0000) on "android_arm64" + /// turns into 3.5.0-180.3.beta (beta) String _extractVersionWithChannel(String fullVersion) { - List parts = fullVersion.split(') '); + RegExp channelRegex = RegExp(r'\((stable|beta|dev)\)'); + Match? match = channelRegex.firstMatch(fullVersion); - // If there's at least one ')', return the first part plus ')' - if (parts.length > 1) { - return '${parts[0]})'; + if (match != null) { + return fullVersion.substring(0, match.end); } - // If there's no ')', return the whole string (shouldn't happen with given format) return fullVersion; } diff --git a/dart/test/event_processor/enricher/io_enricher_test.dart b/dart/test/event_processor/enricher/io_enricher_test.dart index bdc6da2e4e..c35a7d270b 100644 --- a/dart/test/event_processor/enricher/io_enricher_test.dart +++ b/dart/test/event_processor/enricher/io_enricher_test.dart @@ -1,6 +1,8 @@ @TestOn('vm') library dart_test; +import 'dart:io'; + import 'package:sentry/sentry.dart'; import 'package:sentry/src/event_processor/enricher/io_enricher_event_processor.dart'; import 'package:test/test.dart'; @@ -25,6 +27,8 @@ void main() { .firstWhere((element) => element.name == 'Dart'); expect(dartRuntime?.name, 'Dart'); expect(dartRuntime?.rawDescription, isNotNull); + expect(dartRuntime!.version.toString() != Platform.version, true); + expect(Platform.version.contains(dartRuntime.version.toString()), true); }); test('does add to existing runtimes', () { From ebc15f8065886590c8e1fa4da197db775c407823 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 10 Jul 2024 08:04:38 +0200 Subject: [PATCH 04/10] Update --- .../enricher/io_enricher_event_processor.dart | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart index 2062960f83..6a09454494 100644 --- a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart +++ b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart @@ -51,25 +51,21 @@ class IoEnricherEventProcessor implements EnricherEventProcessor { ); } - /// Extracts the semantic version and channel from the full version string. - /// 3.5.0-180.3.beta (beta) (Wed Jun 5 15:06:15 2024 +0000) on "android_arm64" - /// turns into 3.5.0-180.3.beta (beta) - String _extractVersionWithChannel(String fullVersion) { + List _getRuntimes(List? runtimes) { + // Pure Dart doesn't have specific runtimes per build mode + // like Flutter: https://flutter.dev/docs/testing/build-modes + + // Extracts the semantic version and channel from the full version string. + // 3.5.0-180.3.beta (beta) (Wed Jun 5 15:06:15 2024 +0000) on "android_arm64" + // turns into 3.5.0-180.3.beta (beta) + String version = Platform.version; RegExp channelRegex = RegExp(r'\((stable|beta|dev)\)'); - Match? match = channelRegex.firstMatch(fullVersion); + Match? match = channelRegex.firstMatch(version); if (match != null) { - return fullVersion.substring(0, match.end); + version = version.substring(0, match.end); } - return fullVersion; - } - - List _getRuntimes(List? runtimes) { - // Pure Dart doesn't have specific runtimes per build mode - // like Flutter: https://flutter.dev/docs/testing/build-modes - - final version = _extractVersionWithChannel(Platform.version); SentryRuntime dartRuntime = SentryRuntime( name: 'Dart', version: version, From 4ea3b9c3988a352d23fc14e8a4c77fbd89213dd0 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 10 Jul 2024 08:09:03 +0200 Subject: [PATCH 05/10] CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d024ca890..421044d70e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ - Time out for app start info retrieval has been reduced to 10s - If `autoAppStarts` is `false` and `setAppStartEnd` has not been called, the app start event processor will now return early instead of waiting for `getAppStartInfo` to finish +### Improvements + +- Set dart runtime version with parsed `Platform.version` ([#2156](https://github.com/getsentry/sentry-dart/pull/2156)) + ## 8.4.0-beta.1 ### Features From 4387d6eb388e1e258063a9604f0d9cbd45330802 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 10 Jul 2024 13:22:29 +0200 Subject: [PATCH 06/10] Move dart version to late and only extract it once during init --- .../enricher/io_enricher_event_processor.dart | 32 +++++++++++-------- .../enricher/io_enricher_test.dart | 4 +-- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart index 6a09454494..86c271c0af 100644 --- a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart +++ b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart @@ -12,9 +12,26 @@ EnricherEventProcessor enricherEventProcessor(SentryOptions options) { /// Uses Darts [Platform](https://api.dart.dev/stable/dart-io/Platform-class.html) /// class to read information. class IoEnricherEventProcessor implements EnricherEventProcessor { - IoEnricherEventProcessor(this._options); + IoEnricherEventProcessor(this._options) { + dartVersion = _extractDartVersion(Platform.version); + } final SentryOptions _options; + late final String dartVersion; + + /// Extracts the semantic version and channel from the full version string. + /// + /// Example: + /// Input: "3.5.0-180.3.beta (beta) (Wed Jun 5 15:06:15 2024 +0000) on "android_arm64"" + /// Output: "3.5.0-180.3.beta (beta)" + /// + /// Falls back to the full version if the matching fails. + static String _extractDartVersion(String fullVersion) { + RegExp channelRegex = RegExp(r'\((stable|beta|dev)\)'); + Match? match = channelRegex.firstMatch(fullVersion); + // if match is null this will return the full version + return fullVersion.substring(0, match?.end); + } @override SentryEvent? apply(SentryEvent event, Hint hint) { @@ -55,20 +72,9 @@ class IoEnricherEventProcessor implements EnricherEventProcessor { // Pure Dart doesn't have specific runtimes per build mode // like Flutter: https://flutter.dev/docs/testing/build-modes - // Extracts the semantic version and channel from the full version string. - // 3.5.0-180.3.beta (beta) (Wed Jun 5 15:06:15 2024 +0000) on "android_arm64" - // turns into 3.5.0-180.3.beta (beta) - String version = Platform.version; - RegExp channelRegex = RegExp(r'\((stable|beta|dev)\)'); - Match? match = channelRegex.firstMatch(version); - - if (match != null) { - version = version.substring(0, match.end); - } - SentryRuntime dartRuntime = SentryRuntime( name: 'Dart', - version: version, + version: dartVersion, rawDescription: Platform.version, ); if (runtimes == null) { diff --git a/dart/test/event_processor/enricher/io_enricher_test.dart b/dart/test/event_processor/enricher/io_enricher_test.dart index c35a7d270b..dad1a62f6c 100644 --- a/dart/test/event_processor/enricher/io_enricher_test.dart +++ b/dart/test/event_processor/enricher/io_enricher_test.dart @@ -27,8 +27,8 @@ void main() { .firstWhere((element) => element.name == 'Dart'); expect(dartRuntime?.name, 'Dart'); expect(dartRuntime?.rawDescription, isNotNull); - expect(dartRuntime!.version.toString() != Platform.version, true); - expect(Platform.version.contains(dartRuntime.version.toString()), true); + expect(dartRuntime!.version.toString(), isNot(Platform.version)); + expect(Platform.version, contains(dartRuntime.version.toString())); }); test('does add to existing runtimes', () { From 93d73bab4d1ceaca87f8a8b5c83c03dfc79dd070 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 10 Jul 2024 13:31:15 +0200 Subject: [PATCH 07/10] Remove static --- .../event_processor/enricher/io_enricher_event_processor.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart index 86c271c0af..383c402386 100644 --- a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart +++ b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart @@ -26,7 +26,7 @@ class IoEnricherEventProcessor implements EnricherEventProcessor { /// Output: "3.5.0-180.3.beta (beta)" /// /// Falls back to the full version if the matching fails. - static String _extractDartVersion(String fullVersion) { + String _extractDartVersion(String fullVersion) { RegExp channelRegex = RegExp(r'\((stable|beta|dev)\)'); Match? match = channelRegex.firstMatch(fullVersion); // if match is null this will return the full version From d743433c8564e09de3894c9af626c90684a6f101 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 10 Jul 2024 13:32:08 +0200 Subject: [PATCH 08/10] Revert to final dartRuntime --- .../event_processor/enricher/io_enricher_event_processor.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart index 383c402386..2fbd6429ea 100644 --- a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart +++ b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart @@ -72,7 +72,7 @@ class IoEnricherEventProcessor implements EnricherEventProcessor { // Pure Dart doesn't have specific runtimes per build mode // like Flutter: https://flutter.dev/docs/testing/build-modes - SentryRuntime dartRuntime = SentryRuntime( + final dartRuntime = SentryRuntime( name: 'Dart', version: dartVersion, rawDescription: Platform.version, From 51bce18b1ed33bd395e14aa4945fe2e49c722110 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 10 Jul 2024 13:32:42 +0200 Subject: [PATCH 09/10] Formatting --- .../event_processor/enricher/io_enricher_event_processor.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart index 2fbd6429ea..9477d61c7b 100644 --- a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart +++ b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart @@ -71,7 +71,6 @@ class IoEnricherEventProcessor implements EnricherEventProcessor { List _getRuntimes(List? runtimes) { // Pure Dart doesn't have specific runtimes per build mode // like Flutter: https://flutter.dev/docs/testing/build-modes - final dartRuntime = SentryRuntime( name: 'Dart', version: dartVersion, From 04590252c678b8ea8f90736e1f1d820faa43ee7c Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 10 Jul 2024 13:55:51 +0200 Subject: [PATCH 10/10] Set dartVersion to private and move _extractDartVersion out of init --- .../enricher/io_enricher_event_processor.dart | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart index 9477d61c7b..6c598b1ed5 100644 --- a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart +++ b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart @@ -12,12 +12,10 @@ EnricherEventProcessor enricherEventProcessor(SentryOptions options) { /// Uses Darts [Platform](https://api.dart.dev/stable/dart-io/Platform-class.html) /// class to read information. class IoEnricherEventProcessor implements EnricherEventProcessor { - IoEnricherEventProcessor(this._options) { - dartVersion = _extractDartVersion(Platform.version); - } + IoEnricherEventProcessor(this._options); final SentryOptions _options; - late final String dartVersion; + late final String _dartVersion = _extractDartVersion(Platform.version); /// Extracts the semantic version and channel from the full version string. /// @@ -73,7 +71,7 @@ class IoEnricherEventProcessor implements EnricherEventProcessor { // like Flutter: https://flutter.dev/docs/testing/build-modes final dartRuntime = SentryRuntime( name: 'Dart', - version: dartVersion, + version: _dartVersion, rawDescription: Platform.version, ); if (runtimes == null) {