diff --git a/antenna/app.py b/antenna/app.py index 3c034111..2513ad2d 100644 --- a/antenna/app.py +++ b/antenna/app.py @@ -5,6 +5,7 @@ import logging import logging.config from pathlib import Path +import socket import sys from everett.manager import ( @@ -69,7 +70,7 @@ def configure_sentry(app_config): set_up_sentry( sentry_dsn=app_config("secret_sentry_dsn"), release=get_release_name(app_config("basedir")), - host_id=app_config("host_id"), + host_id=app_config("hostname"), # Disable frame-local variables with_locals=False, # Disable request data from being added to Sentry events @@ -132,14 +133,15 @@ class Config: "will be used instead." ), ) - host_id = Option( - default="", + hostname = Option( + default=socket.gethostname(), doc=( "Identifier for the host that is running Antenna. This identifies this Antenna " "instance in the logs and makes it easier to correlate Antenna logs with " - "other data. For example, the value could be a public hostname, an instance id, " - "or something like that. If you do not set this, then socket.gethostname() is " - "used instead." + "other data. For example, the value could be a an instance id, pod id, " + "or something like that.\n" + "\n" + "If you do not set this, then ``socket.gethostname()`` is used instead." ), ) @@ -211,6 +213,7 @@ def setup(self): setup_metrics( statsd_host=self.config("statsd_host"), statsd_port=self.config("statsd_port"), + hostname=self.config("hostname"), debug=self.config("local_dev_env"), ) @@ -281,7 +284,7 @@ def get_app(config_manager=None): setup_logging( logging_level=app_config("logging_level"), debug=app_config("local_dev_env"), - host_id=app_config("host_id"), + host_id=app_config("hostname"), processname="antenna", ) diff --git a/antenna/libmarkus.py b/antenna/libmarkus.py index e04bddfe..37a43281 100644 --- a/antenna/libmarkus.py +++ b/antenna/libmarkus.py @@ -7,22 +7,25 @@ import logging import markus +from markus.filters import AddTagFilter _IS_MARKUS_SETUP = False LOGGER = logging.getLogger(__name__) +METRICS = markus.get_metrics() -def setup_metrics(statsd_host, statsd_port, debug=False): +def setup_metrics(statsd_host, statsd_port, hostname, debug=False): """Initialize and configures the metrics system. :arg statsd_host: the statsd host to send metrics to :arg statsd_port: the port on the host to send metrics to + :arg hostname: the host name :arg debug: whether or not to additionally log metrics to the logger """ - global _IS_MARKUS_SETUP + global _IS_MARKUS_SETUP, METRICS if _IS_MARKUS_SETUP: return @@ -45,9 +48,10 @@ def setup_metrics(statsd_host, statsd_port, debug=False): }, } ) - markus.configure(markus_backends) - _IS_MARKUS_SETUP = True + if hostname: + METRICS.filters.append(AddTagFilter(f"host:{hostname}")) + markus.configure(markus_backends) -METRICS = markus.get_metrics() + _IS_MARKUS_SETUP = True diff --git a/tests/unittest/test_sentry.py b/tests/unittest/test_sentry.py index 39b89b72..b0f18e2e 100644 --- a/tests/unittest/test_sentry.py +++ b/tests/unittest/test_sentry.py @@ -94,7 +94,7 @@ "packages": [{"name": "pypi:sentry-sdk", "version": ANY}], "version": ANY, }, - "server_name": "", + "server_name": ANY, "timestamp": ANY, "transaction": "/__broken__", "transaction_info": {"source": "route"},