Skip to content

Commit 0e12dac

Browse files
authored
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
1 parent d5fb969 commit 0e12dac

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
- Time out for app start info retrieval has been reduced to 10s
1414
- 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
1515

16+
### Improvements
17+
18+
- Set dart runtime version with parsed `Platform.version` ([#2156](https://github.com/getsentry/sentry-dart/pull/2156))
19+
1620
### Dependencies
1721

1822
- Bump Cocoa SDK from v8.30.0 to v8.30.1 ([#2155](https://github.com/getsentry/sentry-dart/pull/2155))

dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart

+16
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ class IoEnricherEventProcessor implements EnricherEventProcessor {
1515
IoEnricherEventProcessor(this._options);
1616

1717
final SentryOptions _options;
18+
late final String _dartVersion = _extractDartVersion(Platform.version);
19+
20+
/// Extracts the semantic version and channel from the full version string.
21+
///
22+
/// Example:
23+
/// Input: "3.5.0-180.3.beta (beta) (Wed Jun 5 15:06:15 2024 +0000) on "android_arm64""
24+
/// Output: "3.5.0-180.3.beta (beta)"
25+
///
26+
/// Falls back to the full version if the matching fails.
27+
String _extractDartVersion(String fullVersion) {
28+
RegExp channelRegex = RegExp(r'\((stable|beta|dev)\)');
29+
Match? match = channelRegex.firstMatch(fullVersion);
30+
// if match is null this will return the full version
31+
return fullVersion.substring(0, match?.end);
32+
}
1833

1934
@override
2035
SentryEvent? apply(SentryEvent event, Hint hint) {
@@ -56,6 +71,7 @@ class IoEnricherEventProcessor implements EnricherEventProcessor {
5671
// like Flutter: https://flutter.dev/docs/testing/build-modes
5772
final dartRuntime = SentryRuntime(
5873
name: 'Dart',
74+
version: _dartVersion,
5975
rawDescription: Platform.version,
6076
);
6177
if (runtimes == null) {

dart/test/event_processor/enricher/io_enricher_test.dart

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
@TestOn('vm')
22
library dart_test;
33

4+
import 'dart:io';
5+
46
import 'package:sentry/sentry.dart';
57
import 'package:sentry/src/event_processor/enricher/io_enricher_event_processor.dart';
68
import 'package:test/test.dart';
@@ -25,6 +27,8 @@ void main() {
2527
.firstWhere((element) => element.name == 'Dart');
2628
expect(dartRuntime?.name, 'Dart');
2729
expect(dartRuntime?.rawDescription, isNotNull);
30+
expect(dartRuntime!.version.toString(), isNot(Platform.version));
31+
expect(Platform.version, contains(dartRuntime.version.toString()));
2832
});
2933

3034
test('does add to existing runtimes', () {

0 commit comments

Comments
 (0)