From 89f6b3d69bb9807e64efb7874cce351d0183af0f Mon Sep 17 00:00:00 2001 From: zeeshanrafiqrana Date: Fri, 8 Dec 2023 03:14:58 +0500 Subject: [PATCH 1/7] add environment based sentry sdk configuration --- synapse/app/_base.py | 5 +++++ synapse/config/metrics.py | 1 + 2 files changed, 6 insertions(+) diff --git a/synapse/app/_base.py b/synapse/app/_base.py index 9ac7e4313ec5..f376a7e52182 100644 --- a/synapse/app/_base.py +++ b/synapse/app/_base.py @@ -662,9 +662,14 @@ def setup_sentry(hs: "HomeServer") -> None: import sentry_sdk + # Set a default environment if it's not configured + default_environment = "" + environment = hs.config.metrics.sentry_environment or default_environment + sentry_sdk.init( dsn=hs.config.metrics.sentry_dsn, release=SYNAPSE_VERSION, + environment=environment ) # We set some default tags that give some context to this instance diff --git a/synapse/config/metrics.py b/synapse/config/metrics.py index 8c1c9bd12d45..cb2a61a1c72f 100644 --- a/synapse/config/metrics.py +++ b/synapse/config/metrics.py @@ -61,6 +61,7 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None: check_requirements("sentry") self.sentry_dsn = config["sentry"].get("dsn") + self.sentry_environment = config["sentry"].get("environment") if not self.sentry_dsn: raise ConfigError( "sentry.dsn field is required when sentry integration is enabled" From 0c371b0c16a319d8f2310dfa8f8e7d3732e4cd5e Mon Sep 17 00:00:00 2001 From: zeeshanrafiqrana Date: Fri, 8 Dec 2023 03:24:50 +0500 Subject: [PATCH 2/7] linting for sentry environment change basepy file --- synapse/app/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/app/_base.py b/synapse/app/_base.py index f376a7e52182..d786b4a8dad6 100644 --- a/synapse/app/_base.py +++ b/synapse/app/_base.py @@ -669,7 +669,7 @@ def setup_sentry(hs: "HomeServer") -> None: sentry_sdk.init( dsn=hs.config.metrics.sentry_dsn, release=SYNAPSE_VERSION, - environment=environment + environment=environment, ) # We set some default tags that give some context to this instance From da85445554f618f3cec5e5ecbf7fec6200389a69 Mon Sep 17 00:00:00 2001 From: zeeshanrafiqrana Date: Fri, 8 Dec 2023 17:53:40 +0500 Subject: [PATCH 3/7] add None for default env --- synapse/app/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/app/_base.py b/synapse/app/_base.py index d786b4a8dad6..9a52dab67e65 100644 --- a/synapse/app/_base.py +++ b/synapse/app/_base.py @@ -663,7 +663,7 @@ def setup_sentry(hs: "HomeServer") -> None: import sentry_sdk # Set a default environment if it's not configured - default_environment = "" + default_environment = None environment = hs.config.metrics.sentry_environment or default_environment sentry_sdk.init( From 0b7d3b29052fd91e5cec1eb79f7f455d9a7f9548 Mon Sep 17 00:00:00 2001 From: zeeshanrafiqrana Date: Tue, 12 Dec 2023 02:26:20 +0500 Subject: [PATCH 4/7] add changelog entries for feature and doc changes --- changelog.d/16738.doc | 1 + changelog.d/16738.feature | 1 + docs/usage/configuration/config_documentation.md | 3 ++- synapse/app/_base.py | 6 +----- 4 files changed, 5 insertions(+), 6 deletions(-) create mode 100644 changelog.d/16738.doc create mode 100644 changelog.d/16738.feature diff --git a/changelog.d/16738.doc b/changelog.d/16738.doc new file mode 100644 index 000000000000..311acf520a62 --- /dev/null +++ b/changelog.d/16738.doc @@ -0,0 +1 @@ +Clarify that in the Sentry configuration, adding the sentry.environment setting alongside the existing sentry.dsn setting enables log maintenance based on different environments, enhancing organizational control and analysis. \ No newline at end of file diff --git a/changelog.d/16738.feature b/changelog.d/16738.feature new file mode 100644 index 000000000000..6b4ed3e80892 --- /dev/null +++ b/changelog.d/16738.feature @@ -0,0 +1 @@ +Enhanced Sentry configuration with a startup-loaded environment for improved system monitoring. Contributed by @zeeshanrafiqrana. \ No newline at end of file diff --git a/docs/usage/configuration/config_documentation.md b/docs/usage/configuration/config_documentation.md index dc92cc2992a3..ac4f8e89f75e 100644 --- a/docs/usage/configuration/config_documentation.md +++ b/docs/usage/configuration/config_documentation.md @@ -2772,7 +2772,7 @@ enable_metrics: true ### `sentry` Use this option to enable sentry integration. Provide the DSN assigned to you by sentry -with the `dsn` setting. +with the `dsn` setting and specify the environment in the `environment` field. This allows for log maintenance based on different environments, ensuring better organization and analysis.. NOTE: While attempts are made to ensure that the logs don't contain any sensitive information, this cannot be guaranteed. By enabling @@ -2783,6 +2783,7 @@ through insecure notification channels if so configured. Example configuration: ```yaml sentry: + environment: "production" dsn: "..." ``` --- diff --git a/synapse/app/_base.py b/synapse/app/_base.py index 9a52dab67e65..aed98f03af30 100644 --- a/synapse/app/_base.py +++ b/synapse/app/_base.py @@ -662,14 +662,10 @@ def setup_sentry(hs: "HomeServer") -> None: import sentry_sdk - # Set a default environment if it's not configured - default_environment = None - environment = hs.config.metrics.sentry_environment or default_environment - sentry_sdk.init( dsn=hs.config.metrics.sentry_dsn, release=SYNAPSE_VERSION, - environment=environment, + environment=hs.config.metrics.sentry_environment, ) # We set some default tags that give some context to this instance From 23d5bf59491ec03d46655eab8313d41d8d12c29c Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 12 Dec 2023 10:04:13 +0000 Subject: [PATCH 5/7] Minor wording tweak --- docs/usage/configuration/config_documentation.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/usage/configuration/config_documentation.md b/docs/usage/configuration/config_documentation.md index ac4f8e89f75e..b7a9d9656458 100644 --- a/docs/usage/configuration/config_documentation.md +++ b/docs/usage/configuration/config_documentation.md @@ -2772,7 +2772,11 @@ enable_metrics: true ### `sentry` Use this option to enable sentry integration. Provide the DSN assigned to you by sentry -with the `dsn` setting and specify the environment in the `environment` field. This allows for log maintenance based on different environments, ensuring better organization and analysis.. +with the `dsn` setting. + + An optional `environment` field can be used to specify an environment. This allows + for log maintenance based on different environments, ensuring better organization + and analysis.. NOTE: While attempts are made to ensure that the logs don't contain any sensitive information, this cannot be guaranteed. By enabling From 22e7562eb4383a3d66768a6e163b45f63046524f Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 12 Dec 2023 10:05:48 +0000 Subject: [PATCH 6/7] Changelog wording tweak --- changelog.d/16738.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/16738.feature b/changelog.d/16738.feature index 6b4ed3e80892..c9ea12a2abc6 100644 --- a/changelog.d/16738.feature +++ b/changelog.d/16738.feature @@ -1 +1 @@ -Enhanced Sentry configuration with a startup-loaded environment for improved system monitoring. Contributed by @zeeshanrafiqrana. \ No newline at end of file +Add new Sentry configuration option `environment` for improved system monitoring. Contributed by @zeeshanrafiqrana. \ No newline at end of file From d0d48713db17540db9f6af1ae86231024af5a44e Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 12 Dec 2023 10:07:04 +0000 Subject: [PATCH 7/7] Delete redundant changelog --- changelog.d/16738.doc | 1 - 1 file changed, 1 deletion(-) delete mode 100644 changelog.d/16738.doc diff --git a/changelog.d/16738.doc b/changelog.d/16738.doc deleted file mode 100644 index 311acf520a62..000000000000 --- a/changelog.d/16738.doc +++ /dev/null @@ -1 +0,0 @@ -Clarify that in the Sentry configuration, adding the sentry.environment setting alongside the existing sentry.dsn setting enables log maintenance based on different environments, enhancing organizational control and analysis. \ No newline at end of file