Observer/MarkEsiPage.php
public function execute(Observer $observer)
    {
        if ($this->fastlyConfig->isFastlyEnabled() != true) {
            return;
        }

        $event = $observer->getEvent();
        $name = $event->getElementName();

        /** @var \Magento\Framework\View\Layout $layout */
        $layout = $event->getLayout();

        /** @var AbstractBlock $block */
        $block = $layout->getBlock($name);

        if ($block instanceof AbstractBlock) {
            $blockTtl = $block->getTtl();
            if (isset($blockTtl)) {
                // This page potentially has ESIs so as a first cut let's mark it as such
                $this->response->setHeader("x-esi", "1");
            }
        }
    }
public function execute(Observer $observer)
    {
        if ($this->fastlyConfig->isFastlyEnabled() != true) {
            return;
        }

        $event = $observer->getEvent();
        $name = $event->getElementName();

        /** @var \Magento\Framework\View\Layout $layout */
        $layout = $event->getLayout();

        /** @var AbstractBlock $block */
        $block = $layout->getBlock($name);

        if ($block instanceof AbstractBlock) {
            $blockTtl = $block->getTtl();
            if (isset($blockTtl)) {
                // This page potentially has ESIs so as a first cut let's mark it as such
                $this->response->setHeader("x-esi", "1");
            }
        }
    }
Set x-esi header if block contains ttl attribute

@param Observer $observer