TF-4136 Move Sentry duplication guard, but keep interceptor ordering last (not first)

This commit is contained in:
dab246
2026-01-12 10:04:33 +07:00
committed by Dat H. Pham
parent 1514136f39
commit 944029d16c
7 changed files with 27 additions and 7 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ class ApplicationManager {
log('ApplicationManager:getAppVersion -> cached: $version'); log('ApplicationManager:getAppVersion -> cached: $version');
return version; return version;
} catch (e) { } catch (e) {
logWarning('ApplicationManager:getAppVersion failedd, Exception = $e'); logWarning('ApplicationManager:getAppVersion failed, Exception = $e');
return ''; return '';
} }
} }
@@ -10,6 +10,10 @@ class SentryInitializer {
'set-cookie', 'set-cookie',
'x-auth', 'x-auth',
'x-token', 'x-token',
'api-key',
'apikey',
'secret',
'bearer',
]; ];
static Future<bool> init(FutureOr<void> Function() appRunner) async { static Future<bool> init(FutureOr<void> Function() appRunner) async {
@@ -63,6 +67,8 @@ class SentryInitializer {
data: null, data: null,
); );
// Note: The copyWith method is deprecated,
// so values must be assigned directly to the instance.
return SentryEvent( return SentryEvent(
eventId: event.eventId, eventId: event.eventId,
contexts: event.contexts, contexts: event.contexts,
@@ -20,6 +20,10 @@ class SentryManager {
required FutureOr<void> Function() fallBackRunner, required FutureOr<void> Function() fallBackRunner,
}) async { }) async {
try { try {
if (_isSentryAvailable) {
log('[SentryManager] Already initialized, skipping');
return;
}
_isSentryAvailable = await SentryInitializer.init(appRunner); _isSentryAvailable = await SentryInitializer.init(appRunner);
log('[SentryManager] Sentry initialized: $_isSentryAvailable'); log('[SentryManager] Sentry initialized: $_isSentryAvailable');
} catch (e, st) { } catch (e, st) {
+2 -2
View File
@@ -38,8 +38,8 @@ mixin AiScribeMixin {
if (aiCapability?.isScribeEndpointAvailable == true) { if (aiCapability?.isScribeEndpointAvailable == true) {
AIScribeBindings(aiCapability!.scribeEndpoint!).dependencies(); AIScribeBindings(aiCapability!.scribeEndpoint!).dependencies();
} }
} catch (e) { } catch (e, st) {
logWarning('AiScribeMixin::injectAIScribeBindings(): $e'); logWarning('AiScribeMixin::injectAIScribeBindings(): $e\n$st');
} }
} }
} }
@@ -194,8 +194,8 @@ extension SessionExtensions on Session {
); );
log('SessionExtensions::getAICapability:aiCapability = $aiCapability'); log('SessionExtensions::getAICapability:aiCapability = $aiCapability');
return aiCapability; return aiCapability;
} catch (e) { } catch (e, st) {
logWarning('SessionExtensions::getAICapability():[Exception] $e'); logWarning('SessionExtensions::getAICapability():[Exception] ${e.runtimeType}\n$st');
return null; return null;
} }
} }
@@ -103,7 +103,12 @@ class NetworkBindings extends Bindings {
dio.interceptors.add(LogInterceptor(requestBody: true)); dio.interceptors.add(LogInterceptor(requestBody: true));
} }
if (SentryManager.instance.isSentryAvailable) { if (SentryManager.instance.isSentryAvailable) {
dio.addSentry(); // Guard against duplicate Sentry interceptor registration
final alreadyHasSentry = dio.interceptors
.any((i) => i.runtimeType.toString().contains('Sentry'));
if (!alreadyHasSentry) {
dio.addSentry();
}
} }
} }
@@ -68,7 +68,12 @@ class NetworkIsolateBindings extends Bindings {
dio.interceptors.add(LogInterceptor(requestBody: true)); dio.interceptors.add(LogInterceptor(requestBody: true));
} }
if (SentryManager.instance.isSentryAvailable) { if (SentryManager.instance.isSentryAvailable) {
dio.addSentry(); // Guard against duplicate Sentry interceptor registration
final alreadyHasSentry = dio.interceptors
.any((i) => i.runtimeType.toString().contains('Sentry'));
if (!alreadyHasSentry) {
dio.addSentry();
}
} }
} }