Skip to content
Snippets Groups Projects
Commit a0ecd181 authored by Neda Moeini's avatar Neda Moeini
Browse files

- Added an environment variable (TESTING) to prevent Sentry from initializing during test runs.

- Configured Sentry to include environment information in its setup.
parent b6a81f88
No related branches found
No related tags found
No related merge requests found
Pipeline #88154 passed
This commit is part of merge request !237. Comments created here will be created in the context of that merge request.
"""The main entrypoint for :term:`GSO`, and the different ways in which it can be run.""" """The main entrypoint for :term:`GSO`, and the different ways in which it can be run."""
import os
import sentry_sdk import sentry_sdk
import typer import typer
from orchestrator import OrchestratorCore, app_settings from orchestrator import OrchestratorCore, app_settings
...@@ -13,16 +15,10 @@ from gso.api import router as api_router ...@@ -13,16 +15,10 @@ from gso.api import router as api_router
from gso.auth.oidc import oidc_instance from gso.auth.oidc import oidc_instance
from gso.auth.opa import graphql_opa_instance, opa_instance from gso.auth.opa import graphql_opa_instance, opa_instance
from gso.graphql_api.types import GSO_SCALAR_OVERRIDES from gso.graphql_api.types import GSO_SCALAR_OVERRIDES
from gso.settings import load_oss_params
SCALAR_OVERRIDES.update(GSO_SCALAR_OVERRIDES) SCALAR_OVERRIDES.update(GSO_SCALAR_OVERRIDES)
sentry_sdk.init(
dsn="https://2b0b82245bfa6631041802c997ed8b58@test-observer01.geant.org/3",
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
traces_sample_rate=1.0,
)
def init_gso_app() -> OrchestratorCore: def init_gso_app() -> OrchestratorCore:
"""Initialise the :term:`GSO` app.""" """Initialise the :term:`GSO` app."""
...@@ -47,3 +43,12 @@ def init_cli_app() -> typer.Typer: ...@@ -47,3 +43,12 @@ def init_cli_app() -> typer.Typer:
cli_app.add_typer(imports.app, name="import-cli") cli_app.add_typer(imports.app, name="import-cli")
cli_app.add_typer(netbox.app, name="netbox-cli") cli_app.add_typer(netbox.app, name="netbox-cli")
return cli_app() return cli_app()
def init_sentry() -> None:
"""Only initialize Sentry if not in testing mode."""
if os.getenv("TESTING", "false").lower() == "false" and (sentry_config := load_oss_params().SENTRY):
sentry_sdk.init(dsn=sentry_config.DSN, environment=sentry_config.environment, traces_sample_rate=1.0)
init_sentry()
...@@ -12,7 +12,7 @@ from pathlib import Path ...@@ -12,7 +12,7 @@ from pathlib import Path
from typing import Annotated from typing import Annotated
from pydantic import Field from pydantic import Field
from pydantic_forms.types import UUIDstr from pydantic_forms.types import UUIDstr, strEnum
from pydantic_settings import BaseSettings from pydantic_settings import BaseSettings
from typing_extensions import Doc from typing_extensions import Doc
...@@ -190,6 +190,22 @@ class KentikParams(BaseSettings): ...@@ -190,6 +190,22 @@ class KentikParams(BaseSettings):
md5_password: str md5_password: str
class EnvironmentEnum(strEnum):
"""The different environments in which the GSO system can run."""
DEVELOPMENT = "development"
TEST = "test"
UAT = "uat"
PRODUCTION = "production"
class SentryParams(BaseSettings):
"""Settings for Sentry."""
DSN: str
environment: EnvironmentEnum
class OSSParams(BaseSettings): class OSSParams(BaseSettings):
"""The set of parameters required for running :term:`GSO`.""" """The set of parameters required for running :term:`GSO`."""
...@@ -203,6 +219,7 @@ class OSSParams(BaseSettings): ...@@ -203,6 +219,7 @@ class OSSParams(BaseSettings):
EMAIL: EmailParams EMAIL: EmailParams
SHAREPOINT: SharepointParams SHAREPOINT: SharepointParams
KENTIK: KentikParams KENTIK: KentikParams
SENTRY: SentryParams | None = None
def load_oss_params() -> OSSParams: def load_oss_params() -> OSSParams:
......
import os
from uuid import uuid4 from uuid import uuid4
LSO_RESULT_SUCCESS = { LSO_RESULT_SUCCESS = {
...@@ -19,3 +20,5 @@ LSO_RESULT_FAILURE = { ...@@ -19,3 +20,5 @@ LSO_RESULT_FAILURE = {
} }
USER_CONFIRM_EMPTY_FORM = [{}] USER_CONFIRM_EMPTY_FORM = [{}]
os.environ["TESTING"] = "true"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment