Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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