applyToEvent method
Implementation
Future<SentryEvent?> applyToEvent(
SentryEvent event,
Hint hint,
) async {
event = event.copyWith(
transaction: event.transaction ?? transaction,
user: _mergeUsers(user, event.user),
breadcrumbs: (event.breadcrumbs?.isNotEmpty ?? false)
? event.breadcrumbs
: List.from(_breadcrumbs),
tags: tags.isNotEmpty ? _mergeEventTags(event) : event.tags,
// ignore: deprecated_member_use_from_same_package
extra: extra.isNotEmpty ? _mergeEventExtra(event) : event.extra,
);
if (event is! SentryTransaction) {
event = event.copyWith(
fingerprint: (event.fingerprint?.isNotEmpty ?? false)
? event.fingerprint
: _fingerprint,
level: level ?? event.level);
}
_contexts.clone().forEach((key, value) {
// add the contexts runtime list to the event.contexts.runtimes
if (key == SentryRuntime.listType &&
value is List<SentryRuntime> &&
value.isNotEmpty) {
_mergeEventContextsRuntimes(value, event);
} else if (key != SentryRuntime.listType &&
(!event.contexts.containsKey(key) || event.contexts[key] == null) &&
value != null) {
event.contexts[key] = value;
}
});
final newSpan = span;
if (event.contexts.trace == null) {
if (newSpan != null) {
event.contexts.trace = newSpan.context.toTraceContext(
sampled: newSpan.samplingDecision?.sampled,
);
} else {
event.contexts.trace =
SentryTraceContext.fromPropagationContext(propagationContext);
}
}
SentryEvent? processedEvent = event;
for (final processor in _eventProcessors) {
try {
final e = processor.apply(processedEvent!, hint);
if (e is Future<SentryEvent?>) {
processedEvent = await e;
} else {
processedEvent = e;
}
} catch (exception, stackTrace) {
_options.logger(
SentryLevel.error,
'An exception occurred while processing event by a processor',
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
}
if (processedEvent == null) {
_options.logger(SentryLevel.debug, 'Event was dropped by a processor');
break;
}
}
return processedEvent;
}