events: add sentry for geoip

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-12-13 16:15:20 +01:00
parent 10b16bc36a
commit 8eecc28c3c
1 changed files with 12 additions and 7 deletions

View File

@ -7,6 +7,7 @@ from typing import Optional, TypedDict
from geoip2.database import Reader from geoip2.database import Reader
from geoip2.errors import GeoIP2Error from geoip2.errors import GeoIP2Error
from geoip2.models import City from geoip2.models import City
from sentry_sdk.hub import Hub
from structlog.stdlib import get_logger from structlog.stdlib import get_logger
from authentik.lib.config import CONFIG from authentik.lib.config import CONFIG
@ -62,6 +63,10 @@ class GeoIPReader:
def city(self, ip_address: str) -> Optional[City]: def city(self, ip_address: str) -> Optional[City]:
"""Wrapper for Reader.city""" """Wrapper for Reader.city"""
with Hub.current.start_span(
op="events.geo.city",
description=ip_address,
):
if not self.enabled: if not self.enabled:
return None return None
self.__check_expired() self.__check_expired()