Skip to content

Commit fe477b4

Browse files
authored
feat: statsd configuration through environment variables (#4031)
* feat: statsd configuration through environment variables * feat: provide statsd config via environment variables for relay and symbolicator * fix: default statsd value to localhost * Update sentry/sentry.conf.example.py
1 parent 275e7d0 commit fe477b4

File tree

5 files changed

+29
-17
lines changed

5 files changed

+29
-17
lines changed

.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ HEALTHCHECK_FILE_RETRIES=3
2626
HEALTHCHECK_FILE_START_PERIOD=600s
2727
# Set SETUP_JS_SDK_ASSETS to 1 to enable the setup of JS SDK assets
2828
# SETUP_JS_SDK_ASSETS=1
29+
#
30+
# Sentry (and its' surrounding services) uses Statsd for metrics collection.
31+
# It's also the proper way to monitor self-hosted Sentry systems.
32+
# Set STATSD_ADDR to a valid IP:PORT combination to enable Statsd metrics collection.
33+
# STATSD_ADDR=127.0.0.1:8125

docker-compose.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ x-sentry-defaults: &sentry_defaults
6969
SENTRY_EVENT_RETENTION_DAYS:
7070
SENTRY_MAIL_HOST:
7171
SENTRY_MAX_EXTERNAL_SOURCEMAP_SIZE:
72+
SENTRY_STATSD_ADDR: "${STATSD_ADDR:-}"
7273
volumes:
7374
- "sentry-data:/data"
7475
- "./sentry:/etc/sentry"
@@ -96,8 +97,7 @@ x-snuba-defaults: &snuba_defaults
9697
SENTRY_EVENT_RETENTION_DAYS:
9798
# If you have statsd server, you can utilize that to monitor self-hosted Snuba containers.
9899
# To start, state these environment variables below on your `.env.` file and adjust the options as needed.
99-
SNUBA_STATSD_HOST: # Example value: "100.100.123.123". Must be an IP address, not domain name
100-
SNUBA_STATSD_PORT: # Example value: 8125
100+
SNUBA_STATSD_ADDR: "${STATSD_ADDR:-}"
101101
services:
102102
smtp:
103103
<<: *restart_policy
@@ -466,6 +466,8 @@ services:
466466
symbolicator:
467467
<<: *restart_policy
468468
image: "$SYMBOLICATOR_IMAGE"
469+
environment:
470+
SYMBOLICATOR_STATSD_ADDR: ${STATSD_ADDR:-127.0.0.1:8125}
469471
command: run -c /etc/symbolicator/config.yml
470472
volumes:
471473
- "sentry-symbolicator:/data"
@@ -700,6 +702,8 @@ services:
700702
relay:
701703
<<: *restart_policy
702704
image: "$RELAY_IMAGE"
705+
environment:
706+
RELAY_STATSD_ADDR: ${STATSD_ADDR:-127.0.0.1:8125}
703707
volumes:
704708
- type: bind
705709
read_only: true
@@ -726,6 +730,7 @@ services:
726730
TASKBROKER_KAFKA_CLUSTER: "kafka:9092"
727731
TASKBROKER_KAFKA_DEADLETTER_CLUSTER: "kafka:9092"
728732
TASKBROKER_DB_PATH: "/opt/sqlite/taskbroker-activations.sqlite"
733+
TASKBROKER_STATSD_ADDR: ${STATSD_ADDR:-127.0.0.1:8125}
729734
volumes:
730735
- sentry-taskbroker:/opt/sqlite
731736
depends_on:
@@ -794,6 +799,7 @@ services:
794799
# Separated by commas. Leaving this unset will default to the systems dns
795800
# resolver.
796801
#UPTIME_CHECKER_HTTP_CHECKER_DNS_NAMESERVERS: "8.8.8.8,8.8.4.4"
802+
UPTIME_CHECKER_STATSD_ADDR: ${STATSD_ADDR:-127.0.0.1:8125}
797803
depends_on:
798804
kafka:
799805
<<: *depends_on-healthy

relay/config.example.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ processing:
2727
# If you have statsd server, you can utilize that to monitor self-hosted Relay.
2828
# To start, uncomment the following `metrics` section and adjust the options as needed.
2929
#
30-
# metrics:
31-
# statsd: "100.100.123.123:8125" # It is recommended to use IP address instead of domain name
32-
# prefix: "sentry.relay" # Adjust this to your needs, default is "sentry.relay"
30+
metrics:
31+
statsd: "${RELAY_STATSD_ADDR}"
32+
prefix: "sentry.relay" # Adjust this to your needs, default is "sentry.relay"
3333
# sample_rate: 1.0 # Adjust this to your needs, default is 1.0
3434
# # `periodic_secs` is the interval for periodic metrics emitted from Relay.
3535
# # Setting it to `0` seconds disables the periodic metrics.

sentry/sentry.conf.example.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -521,10 +521,14 @@ def get_internal_network():
521521
#
522522
# To start, uncomment the following line and adjust the options as needed.
523523

524-
# SENTRY_METRICS_BACKEND = 'sentry.metrics.statsd.StatsdMetricsBackend'
525-
# SENTRY_METRICS_OPTIONS: dict[str, Any] = {
526-
# 'host': '100.100.123.123', # It is recommended to use IP address instead of domain name
527-
# 'port': 8125,
528-
# }
524+
SENTRY_STATSD_ADDR = env("SENTRY_STATSD_ADDR")
525+
if SENTRY_STATSD_ADDR:
526+
host, _, port = SENTRY_STATSD_ADDR.partition(":")
527+
port = int(port or 8125)
528+
SENTRY_METRICS_BACKEND = 'sentry.metrics.statsd.StatsdMetricsBackend'
529+
SENTRY_METRICS_OPTIONS: dict[str, Any] = {
530+
'host': host,
531+
'port': port,
532+
}
529533
# SENTRY_METRICS_SAMPLE_RATE = 1.0 # Adjust this to your needs, default is 1.0
530534
# SENTRY_METRICS_PREFIX = "sentry." # Adjust this to your needs, default is "sentry."

symbolicator/config.example.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ cache_dir: "/data"
33
bind: "0.0.0.0:3021"
44
logging:
55
level: "warn"
6-
metrics:
7-
statsd: null
6+
87
sentry_dsn: null # TODO: Automatically fill this with the internal project DSN
98

109
# If you have statsd server, you can utilize that to monitor self-hosted Symbolicator.
11-
# To start, uncomment the following line and adjust the options as needed.
12-
#
13-
# metrics:
14-
# statsd: "100.100.123.123:8125" # It is recommended to use IP address instead of domain name
15-
# prefix: "sentry.symbolicator" # Adjust this to your needs, default is "symbolicator"
10+
metrics:
11+
statsd: "${SYMBOLICATOR_STATSD_ADDR}" # It is recommended to use IP address instead of domain name
12+
prefix: "sentry.symbolicator" # Adjust this to your needs, default is "symbolicator"

0 commit comments

Comments
 (0)