fix #9377 feat(cirrus): Configure sentry for stage and prod environment for cirrus (#9378)

Because

- We want to monitor errors for both stage and prod for cirrus consuming
applications

This commit

- We have two new projects setup on sentry
[cirrus-prod](https://mozilla.sentry.io/projects/cirrus-prod/?project=4505841055825920)
and
[cirrus-stage](https://mozilla.sentry.io/projects/cirrus-stage/?project=4505841048682496)
- Add sentry sdk to Cirrus
- Consuming application needs to pass the DSN value as part of
environment variables
- Updated docs
- Tested manually sentry error- [manually created error to test the
integration](https://mozilla.sentry.io/issues/4463061449/?project=4505841048682496&query=&referrer=project-issue-stream)

fixes #9377
This commit is contained in:
Yashika Khurana 2023-09-11 09:53:04 -07:00 коммит произвёл GitHub
Родитель 6367788cfd
Коммит 3bba33ad78
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 446 добавлений и 333 удалений

Просмотреть файл

@ -55,4 +55,5 @@ REMOTE_SETTING_URL=http://kinto:8888/v1/buckets/main/collections/nimbus-web-expe
APP_ID=demo-app-beta
APP_NAME=demo_app
CHANNEL=beta
CIRRUS_FML_PATH=./feature_manifest/sample.yml
CIRRUS_FML_PATH=./feature_manifest/sample.yml
CIRRUS_SENTRY_DSN=

Просмотреть файл

@ -3,4 +3,5 @@ REMOTE_SETTING_REFRESH_RATE_IN_SECONDS=10
APP_ID=test_app_id
APP_NAME=test_app_name
CHANNEL=developer
CIRRUS_FML_PATH=./tests/feature_manifest/sample.fml.yaml
CIRRUS_FML_PATH=./tests/feature_manifest/sample.fml.yaml
CIRRUS_SENTRY_DSN=

Просмотреть файл

@ -23,6 +23,7 @@ To set up the Cirrus environment, follow these steps:
APP_NAME=test_app_name
CHANNEL=developer
CIRRUS_FML_PATH=./feature_manifest/sample.fml.yaml
CIRRUS_SENTRY_DSN=dsn_url
```
Here's what each variable represents:
@ -33,6 +34,7 @@ To set up the Cirrus environment, follow these steps:
- `APP_NAME`: Replace `test_app_name` with the desired name for your application for example `firefox_desktop`.
- `CHANNEL`: Replace `developer` with the channel like `beta`, `release` etc.
- `CIRRUS_FML_PATH`: The file path to the feature manifest file. Set it to `./feature_manifest/sample.fml.yaml` or specify the correct path to your feature manifest file.
- `CIRRUS_SENTRY_DSN`: Replace `dsn_url` with the appropriate DSN value.
Adjust the values of these variables according to your specific configuration requirements.

Просмотреть файл

@ -4,6 +4,7 @@ from contextlib import asynccontextmanager
from pathlib import Path
from typing import Any, List, NamedTuple
import sentry_sdk
from apscheduler.schedulers.asyncio import AsyncIOScheduler # type: ignore
from cirrus_sdk import NimbusError # type: ignore
from fastapi import FastAPI, HTTPException, status
@ -17,6 +18,7 @@ from .sdk import SDK
from .settings import (
app_id,
channel,
cirrus_sentry_dsn,
context,
fml_path,
metrics_config,
@ -35,6 +37,7 @@ class FeatureRequest(BaseModel):
@asynccontextmanager
async def lifespan(app: FastAPI):
initialize_sentry()
app.state.fml = create_fml()
app.state.sdk = create_sdk(app.state.fml.get_coenrolling_feature_ids())
app.state.remote_setting = RemoteSettings(app.state.sdk)
@ -48,6 +51,21 @@ async def lifespan(app: FastAPI):
Glean.shutdown()
def initialize_sentry():
if cirrus_sentry_dsn: # pragma: no cover
sentry_sdk.init(
dsn=cirrus_sentry_dsn,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
# We recommend adjusting this value in production.
traces_sample_rate=0.1,
# Set profiles_sample_rate to 1.0 to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
profiles_sample_rate=0.1,
)
def create_fml():
try:
return FML(fml_path=fml_path, channel=channel)

Просмотреть файл

@ -25,6 +25,8 @@ fml_path: str = cast(str, config("CIRRUS_FML_PATH", default=""))
pings_path: str = "./telemetry/pings.yaml"
metrics_path: str = "./telemetry/metrics.yaml"
cirrus_sentry_dsn: str = cast(str, config("CIRRUS_SENTRY_DSN", default=""))
@dataclass
class MetricsConfiguration:

742
cirrus/server/poetry.lock сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -21,6 +21,7 @@ python-decouple = "^3.8"
glean-sdk = "^53.2.0"
pytest-mock = "^3.11.1"
mozilla-nimbus-shared = "^2.4.0"
sentry-sdk = "^1.30.0"
[tool.pyright]
typeCheckingMode = "strict"

Просмотреть файл

@ -96,7 +96,7 @@ def test_get_features_with_required_field(client):
"key2": {"key2.1": "value2", "key2.2": "value3"},
}
},
"url": "https://errors.pydantic.dev/2.1/v/missing",
"url": "https://errors.pydantic.dev/2.3/v/missing",
}
],
),
@ -114,7 +114,7 @@ def test_get_features_with_required_field(client):
"loc": ["body", "context"],
"msg": "Field required",
"input": {"client_id": "4a1d71ab-29a2-4c5f-9e1d-9d9df2e6e449"},
"url": "https://errors.pydantic.dev/2.1/v/missing",
"url": "https://errors.pydantic.dev/2.3/v/missing",
}
],
),
@ -127,14 +127,14 @@ def test_get_features_with_required_field(client):
"loc": ["body", "client_id"],
"msg": "Field required",
"input": {},
"url": "https://errors.pydantic.dev/2.1/v/missing",
"url": "https://errors.pydantic.dev/2.3/v/missing",
},
{
"type": "missing",
"loc": ["body", "context"],
"msg": "Field required",
"input": {},
"url": "https://errors.pydantic.dev/2.1/v/missing",
"url": "https://errors.pydantic.dev/2.3/v/missing",
},
],
),