You can modify this app directly by editing index.htm## Install Install our Python SDK: ```bash pip install "sentry-sdk" ``` ## Configure SDK Import and initialize the Sentry SDK early in your application's setup: ```python import sentry_sdk sentry_sdk.init( dsn="https://62ae661f844c1f566b43f822e10f0e1b@o4511757130203136.ingest.us.sentry.io/4511757142392832", # Add data like request headers and IP for users, # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info send_default_pii=True, # Enable sending logs to Sentry enable_logs=True, # Set traces_sample_rate to 1.0 to capture 100% # of transactions for tracing. traces_sample_rate=1.0, # Set profile_session_sample_rate to 1.0 to profile 100% # of profile sessions. profile_session_sample_rate=1.0, ) def slow_function(): import time time.sleep(0.1) return "done" def fast_function(): import time time.sleep(0.05) return "done" # Manually call start_profiler and stop_profiler # to profile the code in between sentry_sdk.profiler.start_profiler() for i in range(0, 10): slow_function() fast_function() # Calls to stop_profiler are optional - if you don't stop the profiler, it will keep profiling # your application until the process exits or stop_profiler is called. sentry_sdk.profiler.stop_profiler() ``` Alternatively, you can also explicitly control continuous profiling or use transaction profiling. See our [documentation](https://docs.sentry.io/platforms/python/profiling/) for more information. ## Verify You can verify your setup by intentionally causing an error that breaks your application: ```python division_by_zero = 1 / 0 ``` You can send logs to Sentry using the Sentry logging APIs: ```python import sentry_sdk # Send logs directly to Sentry sentry_sdk.logger.info('This is an info log message') sentry_sdk.logger.warning('This is a warning message') sentry_sdk.logger.error('This is an error message') ``` You can also use Python's built-in logging module, which will automatically forward logs to Sentry: ```python import logging # Your existing logging setup logger = logging.getLogger(__name__) # These logs will be automatically sent to Sentry logger.info('This will be sent to Sentry') logger.warning('User login failed') logger.error('Something went wrong') ``` Send test metrics from your app to verify metrics are arriving in Sentry. ```python from sentry_sdk import metrics # Emit metrics metrics.count("checkout.failed", 1) metrics.gauge("queue.depth", 42) metrics.distribution("cart.amount_usd", 187.5) ```> in the Files and versions tab.
Also don't forget to check the Spaces documentation.