#670·viztracer

Feature Request: Return mock object from `get_tracer()` when inactive

Author: aradzu10Created Feb 2, 2026Updated Feb 5, 2026

Feature Request: Return mock object from get_tracer() when inactive

Details

When running without viztracer, viztracer.get_tracer() returns None. This causes crashes when instrumentation code is present in the application but the tracer is not active.

It should instead return a mock or no-op object so that code execution continues without AttributeError.

Example: The following code currently crashes if viztracer is not running:

python
# AttributeError: 'NoneType' object has no attribute 'log_event'
with get_tracer().log_event("scope"):
    pass

Source: gaogaotiantian/viztracer