protected function flushIfNeeded() {
        if (!$this->_enabled) {
            return;
        }

        $now = $this->_util->nowMicros();
        $delta = $now - $this->_lastFlushMicros;

        // Set a bound on maximum flush frequency
        if ($delta < $this->_minFlushPeriodMicros) {
            return;
        }

        // Set a bound of minimum flush frequency
        if ($delta > $this->_maxFlushPeriodMicros) {
            $this->flush();
            return;
        }

        // Look for a trigger that a flush is warranted
        if (count($this->_logRecords) >= $this->_options["max_log_records"]) {
            $this->flush();
            return;
        }
        if (count($this->_spanRecords) >= $this->_options["max_span_records"]) {
            $this->flush();
            return;
        }
    }