| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import asyncio |
| 4 |
from typing import Optional |
| 5 |
|
| 6 |
from ..config import Config |
| 7 |
from ..statsd import StatsdLogger as Base |
| 8 |
|
| 9 |
|
| 10 |
class _DummyProto(asyncio.DatagramProtocol): |
| 11 |
pass |
| 12 |
|
| 13 |
|
| 14 |
class StatsdLogger(Base): |
| 15 |
def __init__(self, config: Config) -> None: |
| 16 |
super().__init__(config) |
| 17 |
self.address = config.statsd_host.rsplit(":", 1) |
| 18 |
self.transport: Optional[asyncio.BaseTransport] = None |
| 19 |
|
| 20 |
async def _socket_send(self, message: bytes) -> None: |
| 21 |
if self.transport is None: |
| 22 |
self.transport, _ = await asyncio.get_event_loop().create_datagram_endpoint( |
| 23 |
_DummyProto, remote_addr=(self.address[0], int(self.address[1])) |
| 24 |
) |
| 25 |
|
| 26 |
self.transport.sendto(message) # type: ignore |