Skip to content

Commit

Permalink
transform log.i into Sentry.captureMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkbee1 committed Oct 9, 2023
1 parent ff8f768 commit 2afb0ee
Show file tree
Hide file tree
Showing 43 changed files with 336 additions and 305 deletions.
5 changes: 3 additions & 2 deletions lib/app/shared/dio_client/dio_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:altme/app/app.dart';
import 'package:dio/dio.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
part 'logging.dart';

const _defaultConnectTimeout = Duration(minutes: 1);
Expand Down Expand Up @@ -61,7 +62,7 @@ class DioClient {
cancelToken: cancelToken,
onReceiveProgress: onReceiveProgress,
);
log.i('Time - ${stopwatch.elapsed}');
Sentry.captureMessage('Time - ${stopwatch.elapsed}');
return response.data;
} on FormatException catch (_) {
throw ResponseMessage(
Expand Down Expand Up @@ -128,7 +129,7 @@ class DioClient {
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
log.i('Time - ${stopwatch.elapsed}');
Sentry.captureMessage('Time - ${stopwatch.elapsed}');
return response.data;
} on FormatException catch (_) {
throw ResponseMessage(
Expand Down
6 changes: 3 additions & 3 deletions lib/app/shared/dio_client/logging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Logging extends Interceptor {

@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
log.i('REQUEST[${options.method}] => PATH: ${options.uri}');
Sentry.captureMessage('REQUEST[${options.method}] => PATH: ${options.uri}');
return super.onRequest(options, handler);
}

Expand All @@ -14,15 +14,15 @@ class Logging extends Interceptor {
Response<dynamic> response,
ResponseInterceptorHandler handler,
) {
log.i(
Sentry.captureMessage(
'''RESPONSE[${response.statusCode}] => PATH: ${response.requestOptions.path} => data: ${jsonEncode(response.data)}''',
);
return super.onResponse(response, handler);
}

@override
void onError(DioException err, ErrorInterceptorHandler handler) {
log.e(
Sentry.captureMessage(
'ERROR[${err.response?.statusCode}] TYPE[${err.type}],=> PATH:'
' ${err.requestOptions.path} data: ${err.response?.data}',
);
Expand Down
11 changes: 8 additions & 3 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import 'package:key_generator/key_generator.dart';
import 'package:oidc4vc/oidc4vc.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:secure_storage/secure_storage.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

String generateDefaultAccountName(
int accountIndex,
Expand Down Expand Up @@ -112,7 +113,7 @@ Future<bool> isConnected() async {
connectivityResult == ConnectivityResult.wifi) {
return true;
}
log.e('No Internet Connection');
Sentry.captureMessage('No Internet Connection');
return false;
}

Expand Down Expand Up @@ -332,7 +333,9 @@ Map<String, dynamic> decodePayload({
final payload = jwtDecode.parseJwt(token);
data = payload;
} catch (e, s) {
log.e('An error occurred while decoding.', error: e, stackTrace: s);
Sentry.captureMessage(
'An error occurred while decoding.',
);
}
return data;
}
Expand All @@ -348,7 +351,9 @@ Map<String, dynamic> decodeHeader({
final header = jwtDecode.parseJwtHeader(token);
data = header;
} catch (e, s) {
log.e('An error occurred while decoding.', error: e, stackTrace: s);
Sentry.captureMessage(
'An error occurred while decoding.',
);
}
return data;
}
Expand Down
7 changes: 4 additions & 3 deletions lib/app/shared/issuer/check_issuer.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:altme/app/app.dart';
import 'package:altme/app/shared/issuer/models/organization_info.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

class CheckIssuer {
CheckIssuer(
Expand All @@ -18,7 +19,7 @@ class CheckIssuer {
didToTest = getIssuerDid(uriToCheck: uriToCheck);
if (checkIssuerServerUrl == Urls.checkIssuerEbsiUrl &&
!didToTest.startsWith('did:ebsi')) {
log.i('did:ebsi issuer');
Sentry.captureMessage('did:ebsi issuer');
return Issuer.emptyIssuer(uriToCheck.host);
}

Expand All @@ -27,7 +28,7 @@ class CheckIssuer {
}

try {
log.i('fetching issuer data');
Sentry.captureMessage('fetching issuer data');
final dynamic response =
await client.get('$checkIssuerServerUrl/$didToTest');
if (checkIssuerServerUrl == Urls.checkIssuerEbsiUrl) {
Expand All @@ -53,7 +54,7 @@ class CheckIssuer {

return Issuer.emptyIssuer(uriToCheck.host);
} catch (e) {
log.e('error $e');
Sentry.captureMessage('error $e');
if (e is NetworkException) {
if (e.message == NetworkError.NETWORK_ERROR_NOT_FOUND) {
return Issuer.emptyIssuer(uriToCheck.toString());
Expand Down
3 changes: 2 additions & 1 deletion lib/app/shared/local_auth/local_auth_api.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:altme/app/app.dart';
import 'package:flutter/services.dart';
import 'package:local_auth/local_auth.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

class LocalAuthApi {
factory LocalAuthApi() {
Expand Down Expand Up @@ -45,7 +46,7 @@ class LocalAuthApi {
),
);
} on PlatformException catch (e, s) {
log.e('${e.message} stack: $s');
Sentry.captureMessage('${e.message} stack: $s');
return false;
}
}
Expand Down
47 changes: 24 additions & 23 deletions lib/app/shared/m_web3_client/m_web3_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:altme/dashboard/dashboard.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'package:http/http.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:web3dart/crypto.dart';
import 'package:web3dart/json_rpc.dart';
import 'package:web3dart/web3dart.dart';
Expand All @@ -21,7 +22,7 @@ class MWeb3Client {

final balance = await ethClient.getBalance(credentials.address);
final balanceInUnit = balance.getValueInUnit(EtherUnit.ether);
log.i('ETH balance in unit: $balanceInUnit');
Sentry.captureMessage('ETH balance in unit: $balanceInUnit');
return balanceInUnit;
}

Expand Down Expand Up @@ -63,7 +64,7 @@ class MWeb3Client {
transaction,
chainId: chainId,
);
log.i('Transaction sent: $result');
Sentry.captureMessage('Transaction sent: $result');
}

static double formatEthAmount({
Expand Down Expand Up @@ -178,7 +179,7 @@ class MWeb3Client {
BigInt.from(amountInWei), //amount
bytes, //bytes
];
log.i('ERC1155 bytes : $bytes');
Sentry.captureMessage('ERC1155 bytes : $bytes');
}

// // listen for the Transfer event when it's emitted by the contract above
Expand All @@ -195,8 +196,8 @@ class MWeb3Client {
// final to = decoded[1] as EthereumAddress;
// final value = decoded[2] as BigInt;

// log.i('decoded response: $decoded');
// log.i('$from sent $value ${token.name} to $to');
// Sentry.captureMessage('decoded response: $decoded');
// Sentry.captureMessage('$from sent $value ${token.name} to $to');
// });

try {
Expand All @@ -206,9 +207,9 @@ class MWeb3Client {
function: balanceFunction,
params: balanceFunctionParams,
);
log.i('We have ${balance.first} ${token.name}');
Sentry.captureMessage('We have ${balance.first} ${token.name}');
} catch (e, s) {
log.e('error in the token balance e: $e, s: $s');
Sentry.captureMessage('error in the token balance e: $e, s: $s');
}

final txId = await client.sendTransaction(
Expand All @@ -228,7 +229,7 @@ class MWeb3Client {
await client.dispose();
return txId;
} catch (e, s) {
log.e('sendToken() error: $e , stack: $s');
Sentry.captureMessage('sendToken() error: $e , stack: $s');
if (e is RPCError) rethrow;
return null;
}
Expand All @@ -241,17 +242,17 @@ class MWeb3Client {
required EtherAmount amount,
String? data,
}) async {
log.i('estimateEthereumFee');
Sentry.captureMessage('estimateEthereumFee');
late EtherAmount gasPrice = EtherAmount.inWei(BigInt.one);
try {
final Web3Client web3Client = Web3Client(web3RpcURL, http.Client());
gasPrice = await web3Client.getGasPrice();

log.i('from: ${sender.hex}');
log.i('to: ${reciever.hex}');
log.i('gasPrice: ${gasPrice.getInWei}');
log.i('value: ${amount.getInWei}');
log.i('data: $data');
Sentry.captureMessage('from: ${sender.hex}');
Sentry.captureMessage('to: ${reciever.hex}');
Sentry.captureMessage('gasPrice: ${gasPrice.getInWei}');
Sentry.captureMessage('value: ${amount.getInWei}');
Sentry.captureMessage('data: $data');

final BigInt maxGas = await web3Client.estimateGas(
sender: sender,
Expand All @@ -260,15 +261,15 @@ class MWeb3Client {
gasPrice: gasPrice,
data: data != null ? hexToBytes(data) : null,
);
log.i('maxGas - $maxGas');
Sentry.captureMessage('maxGas - $maxGas');

final fee = maxGas * gasPrice.getInWei;
log.i('maxGas * gasPrice.getInWei = $fee');
Sentry.captureMessage('maxGas * gasPrice.getInWei = $fee');
return fee;
} catch (e, s) {
log.e('e: $e, s: $s');
Sentry.captureMessage('e: $e, s: $s');
final fee = BigInt.from(21000) * gasPrice.getInWei;
log.i('2100 * gasPrice.getInWei = $fee');
Sentry.captureMessage('2100 * gasPrice.getInWei = $fee');
return fee;
}
}
Expand All @@ -283,7 +284,7 @@ class MWeb3Client {
BigInt? gas,
String? data,
}) async {
log.i('sendEthereumTransaction');
Sentry.captureMessage('sendEthereumTransaction');
final Web3Client web3Client = Web3Client(web3RpcURL, http.Client());
final int nonce = await web3Client.getTransactionCount(sender);
final EtherAmount gasPrice = await web3Client.getGasPrice();
Expand All @@ -308,17 +309,17 @@ class MWeb3Client {
maxGas: maxGas.toInt(),
);

log.i('nonce: $nonce');
log.i('maxGas: ${maxGas.toInt()}');
log.i('chainId: $chainId');
Sentry.captureMessage('nonce: $nonce');
Sentry.captureMessage('maxGas: ${maxGas.toInt()}');
Sentry.captureMessage('chainId: $chainId');

final transactionHash = await web3Client.sendTransaction(
credentials,
transaction,
chainId: chainId,
);

log.i('transactionHash - $transactionHash');
Sentry.captureMessage('transactionHash - $transactionHash');
return transactionHash;
}
}
4 changes: 2 additions & 2 deletions lib/app/shared/widget/base/markdown_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:altme/theme/theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

class MarkdownPage extends StatelessWidget {
MarkdownPage({super.key, required this.title, required this.file});
Expand Down Expand Up @@ -46,9 +47,8 @@ class MarkdownPage extends StatelessWidget {
}

if (snapshot.error != null) {
log.e(
Sentry.captureMessage(
'something went wrong when loading $file',
error: snapshot.error,
);
return Container();
}
Expand Down
6 changes: 3 additions & 3 deletions lib/app/shared/widget/display_terms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

class DisplayTermsOfUseCubit extends Cubit<bool> {
DisplayTermsOfUseCubit() : super(false);
Expand Down Expand Up @@ -115,9 +116,8 @@ class _DisplayTermsofUseState extends State<DisplayTermsofUse> {
}

if (snapshot.error != null) {
log.e(
'something went wrong when loading privacy file',
error: snapshot.error,
Sentry.captureMessage(
snapshot.error.toString(),
);
return const SizedBox.shrink();
}
Expand Down
11 changes: 6 additions & 5 deletions lib/app/shared/widget/m_webview/view/m_webview_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:typed_data';
import 'package:altme/app/app.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:webview_flutter_android/webview_flutter_android.dart';
import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart';
Expand Down Expand Up @@ -83,21 +84,21 @@ class _MWebViewState extends State<MWebView>
..setNavigationDelegate(
NavigationDelegate(
onProgress: (int progress) {
log.i('WebView is loading (progress : $progress%)');
Sentry.captureMessage('WebView is loading (progress : $progress%)');
if (progress == 100) {
mWebViewCubit.setLoading(isLoading: false);
}
},
onPageStarted: (String url) {
log.i('Page started loading: $url');
Sentry.captureMessage('Page started loading: $url');
mWebViewCubit.setLoading(isLoading: true);
},
onPageFinished: (String url) {
log.i('Page finished loading: $url');
Sentry.captureMessage('Page finished loading: $url');
},
onWebResourceError: (WebResourceError error) {
mWebViewCubit.setLoading(isLoading: false);
log.i('''
Sentry.captureMessage('''
Page resource error:
code: ${error.errorCode}
description: ${error.description}
Expand All @@ -106,7 +107,7 @@ class _MWebViewState extends State<MWebView>
''');
},
onNavigationRequest: (NavigationRequest request) {
log.i('navigate - ${request.url}');
Sentry.captureMessage('navigate - ${request.url}');
if (widget.onNavigationRequest != null) {
return widget.onNavigationRequest!.call(request);
} else {
Expand Down
Loading

0 comments on commit 2afb0ee

Please sign in to comment.