element-hq / element-hq/synapse

Ability to add Sentry environment

Open
#14,715 0 comments 0 reactions 0 assignees View on GitHub
O-Uncommon S-Minor T-Enhancement Z-Sentry
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

This issue has been migrated from [#14715](https://github.com/matrix-org/synapse/issues/14715).

---

Currently, it's not possible to define Sentry environments.
The initialization code is https://github.com/matrix-org/synapse/blob/9af2be192a759c22d189b72cc0a7580cd9de8a37/synapse/app/_base.py#L620

The SDK used supports environments definition as documented here https://docs.sentry.io/platforms/python/configuration/environments/

If configured, the environment is set to `production` by default. It's not ideal for teams who maintain several environments for the synapse backend (e.g. production, staging, development, etc...)

An easy fix might be to:
1. Add `environment` to the homeserver.yaml file
```
sentry:
dsn: "..."
environment: "..."
```

2. change `synapse/config/metrics.py` here https://github.com/matrix-org/synapse/blob/9af2be192a759c22d189b72cc0a7580cd9de8a37/synapse/config/metrics.py#L59
```
...
self.sentry_enabled = "sentry" in config
if self.sentry_enabled:
check_requirements("sentry")

self.sentry_dsn = config["sentry"].get("dsn")
self.sentry_environment = config["sentry"].get("environment", "production")

```

3. change `/synapse/app/_base.py` here https://github.com/matrix-org/synapse/blob/9af2be192a759c22d189b72cc0a7580cd9de8a37/synapse/app/_base.py#L620

```
sentry_sdk.init(
dsn=hs.config.metrics.sentry_dsn,
environment=hs.config.metrics.sentry_environment,
release=SYNAPSE_VERSION,
)
```

I can submit a PR for this if that helps fixing the issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.