export method
Exports a batch of finished Spans.
Implementation
@override
Future<void> export(List<Span> spans) async {
if (_isShutdown) {
throw StateError('Exporter is shutdown');
}
if (spans.isEmpty) {
if (OTelLog.isDebug()) {
OTelLog.debug('OtlpHttpSpanExporter: No spans to export');
}
return;
}
if (OTelLog.isDebug()) {
OTelLog.debug(
'OtlpHttpSpanExporter: Beginning export of ${spans.length} spans');
}
final exportFuture = _export(spans);
// Track the pending export but don't throw if it fails during shutdown
_pendingExports.add(exportFuture);
try {
await exportFuture;
if (OTelLog.isDebug()) {
OTelLog.debug('OtlpHttpSpanExporter: Export completed successfully');
}
} catch (e) {
if (_isShutdown &&
e is StateError &&
e.message.contains('shut down during')) {
// Gracefully handle the case where shutdown interrupted the export
if (OTelLog.isDebug()) {
OTelLog.debug(
'OtlpHttpSpanExporter: Export was interrupted by shutdown, suppressing error');
}
} else {
// Re-throw other errors
rethrow;
}
} finally {
_pendingExports.remove(exportFuture);
}
}