Skip to content

Commit

Permalink
Set dart runtime version with parsed Platform.version (#2156)
Browse files Browse the repository at this point in the history
* Parse semver

* Move dart version to late and only extract it once during init

* Set dartVersion to private and move _extractDartVersion out of init
  • Loading branch information
buenaflor authored Jul 10, 2024
1 parent d5fb969 commit 0e12dac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions dart/test/event_processor/enricher/io_enricher_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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', () {
Expand Down

0 comments on commit 0e12dac

Please sign in to comment.