Coverage for mindsdb / utilities / sentry.py: 62%

19 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-21 00:36 +0000

1# Prepare sentry.io for error and exception tracking 

2import sentry_sdk 

3import os 

4from mindsdb.utilities import log 

5 

6logger = log.getLogger(__name__) 

7 

8# Provide your sentry.io DSN here 

9SENTRY_IO_DSN = os.environ.get("SENTRY_IO_DSN", "") 

10# Define the environment 

11SENTRY_IO_ENVIRONMENT = os.environ.get("SENTRY_IO_ENVIRONMENT", "local").lower() 

12# This is set to our SHA when deployed so we know what version this occurred in 

13SENTRY_IO_RELEASE = os.environ.get("SENTRY_IO_RELEASE", "local").lower() 

14# How often to capture traces, 1.0 means 100%. 

15SENTRY_IO_TRACE_SAMPLE_RATE = float(os.environ.get("SENTRY_IO_TRACE_SAMPLE_RATE", "1.0")) 

16# How often to capture profiling, 1.0 means 100%. 

17SENTRY_IO_PROFILING_SAMPLE_RATE = float(os.environ.get("SENTRY_IO_PROFILING_SAMPLE_RATE", "1.0")) 

18# By default we have sentry.io enabled on all envs, except for local which is disabled by default 

19# If you want to enable sentry.io on local for some reason (eg: profiling) please set SENTRY_IO_FORCE_RUN to true 

20SENTRY_IO_DISABLED = True if (os.environ.get("SENTRY_IO_DISABLED", "false").lower() == "true" or SENTRY_IO_ENVIRONMENT == "local") else False 

21SENTRY_IO_FORCE_RUN = True if os.environ.get("SENTRY_IO_FORCE_RUN", "false").lower() == "true" else False 

22 

23 

24# If we're not disabled, or if we have forced sentry to run 

25if SENTRY_IO_DSN and (not SENTRY_IO_DISABLED or SENTRY_IO_FORCE_RUN): 25 ↛ 26line 25 didn't jump to line 26 because the condition on line 25 was never true

26 logger.info("Sentry.io enabled") 

27 logger.info(f"SENTRY_IO_DSN: {SENTRY_IO_DSN}") 

28 logger.info(f"SENTRY_IO_ENVIRONMENT: {SENTRY_IO_ENVIRONMENT}") 

29 logger.info(f"SENTRY_IO_RELEASE: {SENTRY_IO_RELEASE}") 

30 logger.info(f"SENTRY_IO_TRACE_SAMPLE_RATE: {SENTRY_IO_TRACE_SAMPLE_RATE * 100}%") 

31 logger.info(f"SENTRY_IO_PROFILING_SAMPLE_RATE: {SENTRY_IO_PROFILING_SAMPLE_RATE * 100}%") 

32 

33 sentry_sdk.init( 

34 dsn=SENTRY_IO_DSN, 

35 # Set traces_sample_rate to 1.0 to capture 100% 

36 # of transactions for tracing. 

37 traces_sample_rate=SENTRY_IO_TRACE_SAMPLE_RATE, 

38 # Set profiles_sample_rate to 1.0 to profile 100% 

39 # of sampled transactions. 

40 # We recommend adjusting this value in production. 

41 profiles_sample_rate=SENTRY_IO_PROFILING_SAMPLE_RATE, 

42 # What environment we're on, by default development 

43 environment=SENTRY_IO_ENVIRONMENT, 

44 # What release/image/etc we're using, injected in Helm/Kubernetes to be the image tag 

45 release=SENTRY_IO_RELEASE, 

46 )