From 3c57d9749bf7ef94df4a0064f0a60df6f2c8628e Mon Sep 17 00:00:00 2001 From: debuggerx Date: Fri, 21 Apr 2023 19:06:18 +0800 Subject: [PATCH] add user and os info to sentry. --- lib/main.dart | 8 ++------ lib/utils.dart | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 8ab0a74..7cf8b12 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 { } 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) { diff --git a/lib/utils.dart b/lib/utils.dart index de050df..771b318 100644 --- a/lib/utils.dart +++ b/lib/utils.dart @@ -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 points) { center: center, size: size * 1.2, ); +} +setSentryScope(Scope scope) { + var infoLines = File('/etc/os-release').readAsStringSync().split('\n').where((line) => line.contains('=')); + Map 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, + ), + ); }