From ca5dd19ac46cd923d8ae406a0762d3cb284a9238 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Tue, 11 Nov 2025 08:58:13 +0700 Subject: [PATCH 1/5] feat: statsd configuration through environment variables --- .env | 5 +++++ docker-compose.yml | 6 ++++-- sentry/sentry.conf.example.py | 14 +++++++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.env b/.env index dfe279267f8..6f62b1a88b2 100644 --- a/.env +++ b/.env @@ -26,3 +26,8 @@ HEALTHCHECK_FILE_RETRIES=3 HEALTHCHECK_FILE_START_PERIOD=600s # Set SETUP_JS_SDK_ASSETS to 1 to enable the setup of JS SDK assets # SETUP_JS_SDK_ASSETS=1 +# +# Sentry (and its' surrounding services) uses Statsd for metrics collection. +# It's also the proper way to monitor self-hosted Sentry systems. +# Set STATSD_ADDR to a valid IP:PORT combination to enable Statsd metrics collection. +# STATSD_ADDR=127.0.0.1:8125 diff --git a/docker-compose.yml b/docker-compose.yml index 8e8d50ba145..0ba906dd414 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -69,6 +69,7 @@ x-sentry-defaults: &sentry_defaults SENTRY_EVENT_RETENTION_DAYS: SENTRY_MAIL_HOST: SENTRY_MAX_EXTERNAL_SOURCEMAP_SIZE: + SENTRY_STATSD_ADDR: ${STATSD_ADDR:-} volumes: - "sentry-data:/data" - "./sentry:/etc/sentry" @@ -96,8 +97,7 @@ x-snuba-defaults: &snuba_defaults SENTRY_EVENT_RETENTION_DAYS: # If you have statsd server, you can utilize that to monitor self-hosted Snuba containers. # To start, state these environment variables below on your `.env.` file and adjust the options as needed. - SNUBA_STATSD_HOST: # Example value: "100.100.123.123". Must be an IP address, not domain name - SNUBA_STATSD_PORT: # Example value: 8125 + SNUBA_STATSD_ADDR: "${STATSD_ADDR:-}" services: smtp: <<: *restart_policy @@ -726,6 +726,7 @@ services: TASKBROKER_KAFKA_CLUSTER: "kafka:9092" TASKBROKER_KAFKA_DEADLETTER_CLUSTER: "kafka:9092" TASKBROKER_DB_PATH: "/opt/sqlite/taskbroker-activations.sqlite" + TASKBROKER_STATSD_ADDR: "${STATSD_ADDR:-}" volumes: - sentry-taskbroker:/opt/sqlite depends_on: @@ -794,6 +795,7 @@ services: # Separated by commas. Leaving this unset will default to the systems dns # resolver. #UPTIME_CHECKER_HTTP_CHECKER_DNS_NAMESERVERS: "8.8.8.8,8.8.4.4" + UPTIME_CHECKER_STATSD_ADDR: "${STATSD_ADDR:-}" depends_on: kafka: <<: *depends_on-healthy diff --git a/sentry/sentry.conf.example.py b/sentry/sentry.conf.example.py index 38147f7bb02..38d3eb48e29 100644 --- a/sentry/sentry.conf.example.py +++ b/sentry/sentry.conf.example.py @@ -463,10 +463,14 @@ def get_internal_network(): # # To start, uncomment the following line and adjust the options as needed. -# SENTRY_METRICS_BACKEND = 'sentry.metrics.statsd.StatsdMetricsBackend' -# SENTRY_METRICS_OPTIONS: dict[str, Any] = { -# 'host': '100.100.123.123', # It is recommended to use IP address instead of domain name -# 'port': 8125, -# } +SENTRY_STATSD_ADDR = env("STATSD_ADDR") +if SENTRY_STATSD_ADDR: + host, _, port = SENTRY_STATSD_ADDR.partition(":") + port = int(port or 8125) + SENTRY_METRICS_BACKEND = 'sentry.metrics.statsd.StatsdMetricsBackend' + SENTRY_METRICS_OPTIONS: dict[str, Any] = { + 'host': host, + 'port': port, + } # SENTRY_METRICS_SAMPLE_RATE = 1.0 # Adjust this to your needs, default is 1.0 # SENTRY_METRICS_PREFIX = "sentry." # Adjust this to your needs, default is "sentry." From 334f2ac171c85f9bbe4913261964127a8f13f8ee Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Wed, 12 Nov 2025 11:17:27 +0700 Subject: [PATCH 2/5] feat: provide statsd config via environment variables for relay and symbolicator --- docker-compose.yml | 8 ++++++-- relay/config.example.yml | 6 +++--- symbolicator/config.example.yml | 11 ++++------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 0ba906dd414..b76ac24e751 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -466,6 +466,8 @@ services: symbolicator: <<: *restart_policy image: "$SYMBOLICATOR_IMAGE" + environment: + SYMBOLICATOR_STATSD_ADDR: ${STATSD_ADDR:-} command: run -c /etc/symbolicator/config.yml volumes: - "sentry-symbolicator:/data" @@ -700,6 +702,8 @@ services: relay: <<: *restart_policy image: "$RELAY_IMAGE" + environment: + RELAY_STATSD_ADDR: ${STATSD_ADDR:-} volumes: - type: bind read_only: true @@ -726,7 +730,7 @@ services: TASKBROKER_KAFKA_CLUSTER: "kafka:9092" TASKBROKER_KAFKA_DEADLETTER_CLUSTER: "kafka:9092" TASKBROKER_DB_PATH: "/opt/sqlite/taskbroker-activations.sqlite" - TASKBROKER_STATSD_ADDR: "${STATSD_ADDR:-}" + TASKBROKER_STATSD_ADDR: ${STATSD_ADDR:-} volumes: - sentry-taskbroker:/opt/sqlite depends_on: @@ -795,7 +799,7 @@ services: # Separated by commas. Leaving this unset will default to the systems dns # resolver. #UPTIME_CHECKER_HTTP_CHECKER_DNS_NAMESERVERS: "8.8.8.8,8.8.4.4" - UPTIME_CHECKER_STATSD_ADDR: "${STATSD_ADDR:-}" + UPTIME_CHECKER_STATSD_ADDR: ${STATSD_ADDR:-} depends_on: kafka: <<: *depends_on-healthy diff --git a/relay/config.example.yml b/relay/config.example.yml index 06c73079564..007f81309f5 100644 --- a/relay/config.example.yml +++ b/relay/config.example.yml @@ -27,9 +27,9 @@ processing: # If you have statsd server, you can utilize that to monitor self-hosted Relay. # To start, uncomment the following `metrics` section and adjust the options as needed. # -# metrics: -# statsd: "100.100.123.123:8125" # It is recommended to use IP address instead of domain name -# prefix: "sentry.relay" # Adjust this to your needs, default is "sentry.relay" +metrics: + statsd: "${RELAY_STATSD_ADDR}" + prefix: "sentry.relay" # Adjust this to your needs, default is "sentry.relay" # sample_rate: 1.0 # Adjust this to your needs, default is 1.0 # # `periodic_secs` is the interval for periodic metrics emitted from Relay. # # Setting it to `0` seconds disables the periodic metrics. diff --git a/symbolicator/config.example.yml b/symbolicator/config.example.yml index de716de8c4c..f0da86d4c25 100644 --- a/symbolicator/config.example.yml +++ b/symbolicator/config.example.yml @@ -3,13 +3,10 @@ cache_dir: "/data" bind: "0.0.0.0:3021" logging: level: "warn" -metrics: - statsd: null + sentry_dsn: null # TODO: Automatically fill this with the internal project DSN # If you have statsd server, you can utilize that to monitor self-hosted Symbolicator. -# To start, uncomment the following line and adjust the options as needed. -# -# metrics: -# statsd: "100.100.123.123:8125" # It is recommended to use IP address instead of domain name -# prefix: "sentry.symbolicator" # Adjust this to your needs, default is "symbolicator" +metrics: + statsd: "${SYMBOLICATOR_STATSD_ADDR}" # It is recommended to use IP address instead of domain name + prefix: "sentry.symbolicator" # Adjust this to your needs, default is "symbolicator" From 39365333292f9ee338c69a66b1add3ca44935f0f Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Wed, 12 Nov 2025 12:13:54 +0700 Subject: [PATCH 3/5] fix: default statsd value to localhost --- docker-compose.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index b76ac24e751..a7361de024c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -69,7 +69,7 @@ x-sentry-defaults: &sentry_defaults SENTRY_EVENT_RETENTION_DAYS: SENTRY_MAIL_HOST: SENTRY_MAX_EXTERNAL_SOURCEMAP_SIZE: - SENTRY_STATSD_ADDR: ${STATSD_ADDR:-} + SENTRY_STATSD_ADDR: ${STATSD_ADDR:-127.0.0.1:8125} volumes: - "sentry-data:/data" - "./sentry:/etc/sentry" @@ -97,7 +97,7 @@ x-snuba-defaults: &snuba_defaults SENTRY_EVENT_RETENTION_DAYS: # If you have statsd server, you can utilize that to monitor self-hosted Snuba containers. # To start, state these environment variables below on your `.env.` file and adjust the options as needed. - SNUBA_STATSD_ADDR: "${STATSD_ADDR:-}" + SNUBA_STATSD_ADDR: "${STATSD_ADDR:-127.0.0.1:8125}" services: smtp: <<: *restart_policy @@ -467,7 +467,7 @@ services: <<: *restart_policy image: "$SYMBOLICATOR_IMAGE" environment: - SYMBOLICATOR_STATSD_ADDR: ${STATSD_ADDR:-} + SYMBOLICATOR_STATSD_ADDR: ${STATSD_ADDR:-127.0.0.1:8125} command: run -c /etc/symbolicator/config.yml volumes: - "sentry-symbolicator:/data" @@ -703,7 +703,7 @@ services: <<: *restart_policy image: "$RELAY_IMAGE" environment: - RELAY_STATSD_ADDR: ${STATSD_ADDR:-} + RELAY_STATSD_ADDR: ${STATSD_ADDR:-127.0.0.1:8125} volumes: - type: bind read_only: true @@ -730,7 +730,7 @@ services: TASKBROKER_KAFKA_CLUSTER: "kafka:9092" TASKBROKER_KAFKA_DEADLETTER_CLUSTER: "kafka:9092" TASKBROKER_DB_PATH: "/opt/sqlite/taskbroker-activations.sqlite" - TASKBROKER_STATSD_ADDR: ${STATSD_ADDR:-} + TASKBROKER_STATSD_ADDR: ${STATSD_ADDR:-127.0.0.1:8125} volumes: - sentry-taskbroker:/opt/sqlite depends_on: @@ -799,7 +799,7 @@ services: # Separated by commas. Leaving this unset will default to the systems dns # resolver. #UPTIME_CHECKER_HTTP_CHECKER_DNS_NAMESERVERS: "8.8.8.8,8.8.4.4" - UPTIME_CHECKER_STATSD_ADDR: ${STATSD_ADDR:-} + UPTIME_CHECKER_STATSD_ADDR: ${STATSD_ADDR:-127.0.0.1:8125} depends_on: kafka: <<: *depends_on-healthy From e7e288dd740f518a73111feec350beff87cd3912 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Thu, 13 Nov 2025 19:58:40 +0700 Subject: [PATCH 4/5] Update sentry/sentry.conf.example.py --- sentry/sentry.conf.example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry/sentry.conf.example.py b/sentry/sentry.conf.example.py index 6cdadf9d697..cb7b037d987 100644 --- a/sentry/sentry.conf.example.py +++ b/sentry/sentry.conf.example.py @@ -463,7 +463,7 @@ def get_internal_network(): # # To start, uncomment the following line and adjust the options as needed. -SENTRY_STATSD_ADDR = env("STATSD_ADDR") +SENTRY_STATSD_ADDR = env("SENTRY_STATSD_ADDR") if SENTRY_STATSD_ADDR: host, _, port = SENTRY_STATSD_ADDR.partition(":") port = int(port or 8125) From 5a039cdec77d1b5cd6cc95c998f76ae8b64bd57c Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Fri, 14 Nov 2025 10:16:56 +0700 Subject: [PATCH 5/5] fix: don't set default statsd addr value for sentry and snuba --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a7361de024c..4017e5245d5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -69,7 +69,7 @@ x-sentry-defaults: &sentry_defaults SENTRY_EVENT_RETENTION_DAYS: SENTRY_MAIL_HOST: SENTRY_MAX_EXTERNAL_SOURCEMAP_SIZE: - SENTRY_STATSD_ADDR: ${STATSD_ADDR:-127.0.0.1:8125} + SENTRY_STATSD_ADDR: "${STATSD_ADDR:-}" volumes: - "sentry-data:/data" - "./sentry:/etc/sentry" @@ -97,7 +97,7 @@ x-snuba-defaults: &snuba_defaults SENTRY_EVENT_RETENTION_DAYS: # If you have statsd server, you can utilize that to monitor self-hosted Snuba containers. # To start, state these environment variables below on your `.env.` file and adjust the options as needed. - SNUBA_STATSD_ADDR: "${STATSD_ADDR:-127.0.0.1:8125}" + SNUBA_STATSD_ADDR: "${STATSD_ADDR:-}" services: smtp: <<: *restart_policy