captureException method
Implementation
@override
Future<void> captureException({
required Object error,
StackTrace? stackTrace,
Map<String, Object>? properties,
Map<String, Object?>? options,
}) async {
try {
final exceptionData = DartExceptionProcessor.processException(
error: error,
stackTrace: stackTrace,
properties: properties,
inAppIncludes: _config?.errorTrackingConfig.inAppIncludes,
inAppExcludes: _config?.errorTrackingConfig.inAppExcludes,
inAppByDefault: _config?.errorTrackingConfig.inAppByDefault ?? true,
);
final processedEvent = _runBeforeSend(
PostHogEventName.exception,
_withWebContext(Map<String, Object>.from(exceptionData)),
options: options,
);
if (processedEvent == null) {
printIfDebug(
'[PostHog] Exception event dropped by beforeSend: ${error.runtimeType}',
);
return;
}
if (processedEvent.event != PostHogEventName.exception) {
await _sendCapture(processedEvent);
return;
}
final extracted = CaptureUtils.extractUserProperties(
properties: processedEvent.properties?.cast<String, Object>(),
userProperties: processedEvent.userProperties,
userPropertiesSetOnce: processedEvent.userPropertiesSetOnce,
);
final userProperties = extracted.userProperties;
final userPropertiesSetOnce = extracted.userPropertiesSetOnce;
// posthog-js's captureException takes no capture options, but capture
// merges `$set` and `$set_once` from the event's properties.
final normalizedData = PropertyNormalizer.normalize({
...?_withOptionProperties(
extracted.properties,
processedEvent.options,
PostHogEventName.exception,
),
if (userProperties != null) r'$set': userProperties,
if (userPropertiesSetOnce != null) r'$set_once': userPropertiesSetOnce,
});
return await handleWebMethodCall(
MethodCall('captureException', {
'automaticPropertiesApplied': true,
'properties': normalizedData,
}),
);
} catch (error) {
printIfDebug('Exception in captureException: $error');
}
}