From 0e12dac3d06fe2ecc71eb672ef92d901b6b0bbd5 Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Wed, 10 Jul 2024 14:23:20 +0200 Subject: [PATCH] Set dart runtime version with parsed `Platform.version` (#2156) * Parse semver * Move dart version to late and only extract it once during init * Set dartVersion to private and move _extractDartVersion out of init --- CHANGELOG.md | 4 ++++ .../enricher/io_enricher_event_processor.dart | 16 ++++++++++++++++ .../enricher/io_enricher_test.dart | 4 ++++ 3 files changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c617b171af..88967b15dc 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)) + ### Dependencies - Bump Cocoa SDK from v8.30.0 to v8.30.1 ([#2155](https://github.com/getsentry/sentry-dart/pull/2155)) 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..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 @@ -15,6 +15,21 @@ class IoEnricherEventProcessor implements EnricherEventProcessor { IoEnricherEventProcessor(this._options); final SentryOptions _options; + late final String _dartVersion = _extractDartVersion(Platform.version); + + /// 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. + 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) { @@ -56,6 +71,7 @@ class IoEnricherEventProcessor implements EnricherEventProcessor { // like Flutter: https://flutter.dev/docs/testing/build-modes final dartRuntime = SentryRuntime( name: 'Dart', + 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 bdc6da2e4e..dad1a62f6c 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(), isNot(Platform.version)); + expect(Platform.version, contains(dartRuntime.version.toString())); }); test('does add to existing runtimes', () {