flush method

TelemetryBatch flush()

Flushes all buffered telemetry data.

Returns the flushed data and clears the buffer.

Implementation

TelemetryBatch flush() {
  if (_isFlushing || size == 0) {
    return TelemetryBatch.empty();
  }

  _isFlushing = true;

  try {
    final batch = TelemetryBatch(
      traces: List.from(_traces),
      spans: List.from(_spans),
      metrics: List.from(_metrics),
      events: List.from(_events),
    );

    _clear();

    return batch;
  } finally {
    _isFlushing = false;
  }
}