Technical Prerequisites
- Runtime: CPython 3.7 and later. Python 3.12 and later uses
sys.monitoring; Python 3.7–3.11 uses bytecode instrumentation. - Metadata: Access to the active git commit SHA (mandatory for matching local source coordinates to production builds).
Installation
Add the SDK as a dependency using your package manager:Initialization Walkthrough
Follow these steps to initialize the InSitu agent inside your application:1
Create your initialization file
Create a dedicated file named
InSitu_init.py in your project source root:InSitu_init.py
2
Import it in your entrypoint
In your main application file, import
InSitu_init as early as possible before starting your application:main.py
3
Configure preloaded workers (Gunicorn)
If your server loads the application before forking workers, such as Gunicorn with The parent defers initialization and each worker starts its own agent. Use this setting only when the application is loaded before workers fork. Inside the workers, use the
--preload, set this variable before starting the server:spawn process start method instead of creating additional children with fork.4
Configure your Dockerfile
To enable Docker-based deployments, define a
GIT_COMMIT build argument inside your Dockerfile with a default value of unknown:Dockerfile
5
Run local Docker builds
For building and testing Docker containers locally, inject your active git commit:
6
Inject the correct SHA in CI/CD
InSitu does not start if
commit_sha is missing or unknown. Pass the commit SHA of the source used to build the application to GIT_COMMIT during deployment.You can use your CI/CD platform’s commit SHA variable when it matches the checked-out source:Configuration & Environment Variables Reference
You can configure the agent by passing properties inside yourInSitu.start() options object, or by using environment variables.
The following example includes the available programmatic options and their corresponding environment variables:
InSitu_init.py
Redaction
redact_keys and redact_values are lists of case-insensitive regular expressions. Their environment variables accept comma-separated patterns. A custom key list replaces the defaults, so include the defaults when adding keys.
Safe evaluation
Safe evaluation is enabled by default and restricts calls in probe expressions. It is not a security sandbox: properties and operators can still run application code. Use trusted probes. To allow arbitrary function and method calls, setInSitu_DISABLE_SAFE_EVALUATION=true or pass "disable_safe_evaluation": True to InSitu.start().
Safety shields
The Python agent monitors scheduler lag and the time spent handling probes:- Yellow threshold: The pause budget exceeds 50%, four of the last ten lag readings exceed 50 ms, or one of the last five readings exceeds 200 ms.
- Red threshold: The pause budget exceeds 15 ms per second, seven of the last ten lag readings exceed 50 ms, or three of the last five readings exceed 200 ms. The agent suspends instrumentation.
- Auto-recovery: Resumes probes after the cooldown period (default 10 seconds), once health returns to GREEN.
DEBUG=InSitu:agent before startup to see safety logs.