add user and os info to sentry.

master
DebuggerX 2 years ago
parent 9218eb646e
commit 3c57d9749b

@ -42,9 +42,7 @@ Future main() async {
options.tracesSampleRate = 1.0;
options.reportPackages = false;
Sentry.configureScope(
(scope) => scope.setUser(
SentryUser(username: Platform.environment['USER']),
),
setSentryScope,
);
},
appRunner: () => runApp(const MyApp()),
@ -115,9 +113,7 @@ class _MyHomePageState extends State<MyHomePage> {
}
Sentry.captureMessage(
'Found ${result.length} codes.',
withScope: (scope) {
SentryUser(username: Platform.environment['USER']);
},
withScope: setSentryScope,
);
Future.delayed(const Duration(seconds: 3), () {
if (status == Status.notFound) {

@ -1,4 +1,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:zbar_scan_plugin/zbar_scan_plugin.dart';
import 'package:collection/collection.dart';
import 'dart:math';
@ -32,5 +35,20 @@ CenterAndSize getCenterAndSizeOfPoints(List<PointInfo> points) {
center: center,
size: size * 1.2,
);
}
setSentryScope(Scope scope) {
var infoLines = File('/etc/os-release').readAsStringSync().split('\n').where((line) => line.contains('='));
Map<String, dynamic> data = {};
for (var info in infoLines) {
var parts = info.split('=');
data['OS_${parts.first}'] = parts.sublist(1).join('=');
}
return scope.setUser(
SentryUser(
id: File('/etc/machine-id').readAsStringSync(),
username: Platform.environment['USER'],
data: data,
),
);
}

Loading…
Cancel
Save