pure_eval
Learn about pure_eval and how to add it to your integrations list.
This integration uses pure_eval
to safely evaluate additional expressions in the source code and display their values alongside other local variables.
Install sentry-sdk
from PyPI with the pure_eval
extra or pip install pure_eval executing asttokens
.
Copied
pip install "sentry-sdk[pure_eval]"
Add PureEvalIntegration()
to your integrations
list:
Copied
import sentry_sdk
from sentry_sdk.integrations.pure_eval import PureEvalIntegration
sentry_sdk.init(
dns="https://examplePublicKey@o0.ingest.sentry.io/0",
# Add data like request headers and IP for users, if applicable;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
integrations=[
PureEvalIntegration(),
],
)
Copied
from types import SimpleNamespace
def main():
sentry_sdk.init(...) # same as above
namespace = SimpleNamespace()
namespace.d = {1: 2}
print(namespace.d[1] / 0)
main()
When you run this example script an error will be sent to Sentry. Through the PureEvalIntegration
the stack trace of the error will include the values of namespace.d
and namespace.d[1]
which would not be shown without PureEvalIntegration
.
- Python: 3.6+
The versions above apply for the current major version of the Python SDK. If you're looking to use Sentry with older Python or framework versions, consider using an older major version of the SDK.
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").