Google Cloud Snapshot Debugger for Python
The Python Cloud Debugger client library (now known as Google Cloud Snapshot Debugger) allows you to inspect the state of a running Python application in Google Cloud without stopping or slowing it down. It works by capturing snapshots of application state. The current version is 4.1, with releases typically aligning with significant feature updates or bug fixes.
Warnings
- breaking Version 4.0 of `google-python-cloud-debugger` removes support for the deprecated Cloud Debugger API backend. It now exclusively uses the Firebase Realtime Database backend.
- gotcha The PyPI package name is `google-python-cloud-debugger`, but the module you import and use is `snapshot_debugger`.
- deprecated The original Cloud Debugger API has been deprecated by Google. The `google-python-cloud-debugger` library has shifted to use Firebase Realtime Database as its backend for snapshot debugging.
- gotcha Python 2.7 support was dropped in version 2.19. Modern versions of the library (>=3.x) require Python 3.7 or newer.
Install
-
pip install google-python-cloud-debugger
Imports
- start
from snapshot_debugger import start
Quickstart
import snapshot_debugger
import os
# snapshot_debugger.start() attempts to auto-detect project ID and config.
# For local testing, you might need to specify it or set environment variables.
# Example for App Engine, Cloud Functions, GKE etc. it usually works out of the box.
# For manual configuration if needed:
# snapshot_debugger.start(project_id='your-gcp-project-id', module='your-app-name', version='1.0')
# In a typical cloud environment, simply calling start() is sufficient.
# Ensure your service account has 'Cloud Debugger' role.
# For Firebase backend, the service account needs 'Firebase Realtime Database Admin' role.
snapshot_debugger.start()
print('Snapshot Debugger started. You can now set breakpoints in the Google Cloud Console.')
def main():
x = 10
y = 20
z = x + y # Set a breakpoint here in Google Cloud Console
print(f'Result: {z}')
if __name__ == '__main__':
main()