-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
45 lines (40 loc) · 1.65 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from src.infrastructure import tracing_service
from src.domain.use_cases.send_metrics_use_case import SendPypiStatsUseCase
from src.infrastructure.utils.logger_module import logger, log_extra_info, LogStatus
if __name__ == "__main__":
tracer = tracing_service.get_tracer()
with tracer.start_as_current_span("application.controller") as span:
try:
send_pypi_stats_use_case = SendPypiStatsUseCase()
except Exception as e:
span.set_attribute("error", str(e))
span.record_exception(exception=e)
logger.error(
"Error Instance of SendPypiStatsUseCase",
extra=log_extra_info(status=LogStatus.ERROR),
)
try:
df, err = send_pypi_stats_use_case.get_stats()
if err:
logger.error(
"Error Getting Stats from DW",
extra=log_extra_info(status=LogStatus.ERROR),
)
raise Exception(str(err))
except Exception as e:
span.set_attribute("error", str(e))
span.record_exception(exception=e)
logger.error(
"Error Getting Stats from DW", extra=log_extra_info(status=LogStatus.ERROR)
)
raise Exception(str(e))
try:
send_pypi_stats_use_case.send_stats(df=df)
except Exception as e:
logger.error(
"Error Sending Stats to DataDog",
extra=log_extra_info(status=LogStatus.ERROR),
)
span.set_attribute("error", str(e))
span.record_exception(exception=e)
raise Exception(str(e))