Skip to content

Commit

Permalink
Add debug option to SentryConfig (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
droserasprout authored Jul 29, 2021
1 parent 05c29ed commit 4ee1967
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/dipdup/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from dotenv import load_dotenv
from fcache.cache import FileCache # type: ignore
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
from sentry_sdk.integrations.logging import LoggingIntegration

from dipdup import __spec_version__, __version__, spec_reindex_mapping, spec_version_mapping
from dipdup.codegen import DEFAULT_DOCKER_ENV_FILE, DEFAULT_DOCKER_IMAGE, DEFAULT_DOCKER_TAG, DipDupCodeGenerator
Expand All @@ -29,6 +30,29 @@ class CLIContext:
logging_config: LoggingConfig


def init_sentry(config: DipDupConfig) -> None:
if not config.sentry:
return
if config.sentry.debug:
level, event_level = logging.DEBUG, logging.WARNING
else:
level, event_level = logging.INFO, logging.ERROR

integrations = [
AioHttpIntegration(),
LoggingIntegration(
level=level,
event_level=event_level,
),
]
sentry_sdk.init(
dsn=config.sentry.dsn,
environment=config.sentry.environment,
integrations=integrations,
release=__version__,
)


@click.group()
@click.version_option(__version__)
@click.option('--config', '-c', type=str, multiple=True, help='Path to dipdup YAML config', default=['dipdup.yml'])
Expand All @@ -44,6 +68,7 @@ async def cli(ctx, config: List[str], env_file: List[str], logging_config: str):
_logging_config = LoggingConfig.load(path)
_logging_config.apply()

# NOTE: Apply env files before loading config
for env_path in env_file:
env_path = join(os.getcwd(), env_path)
if not exists(env_path):
Expand All @@ -52,19 +77,14 @@ async def cli(ctx, config: List[str], env_file: List[str], logging_config: str):
load_dotenv(env_path, override=True)

_config = DipDupConfig.load(config)
init_sentry(_config)

if _config.spec_version not in spec_version_mapping:
raise ConfigurationError('Unknown `spec_version`, correct ones: {}')
if _config.spec_version != __spec_version__ and ctx.invoked_subcommand != 'migrate':
reindex = spec_reindex_mapping[__spec_version__]
raise MigrationRequiredError(None, _config.spec_version, __spec_version__, reindex)

if _config.sentry:
sentry_sdk.init(
dsn=_config.sentry.dsn,
environment=_config.sentry.environment,
integrations=[AioHttpIntegration()],
)

ctx.obj = CLIContext(
config_paths=config,
config=_config,
Expand Down
1 change: 1 addition & 0 deletions src/dipdup/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ def __post_init_post_parse__(self):
class SentryConfig:
dsn: str
environment: Optional[str] = None
debug: bool = False


@dataclass
Expand Down

0 comments on commit 4ee1967

Please sign in to comment.