Code variables in Python
Contents
The Python SDK (v6.9.1+) supports automatic code variables capture, allowing you to see the state of local variables when exceptions occur.
Enabling code variables capture
Code variables capture can be enabled globally during PostHog initialization:
Scoped capture with contexts
You can enable or disable code variables capture for specific code blocks using contexts:
Configuration options
Masking sensitive variables
Variable names matching mask patterns will have their values replaced with *** in the UI.
The SDK includes sensible defaults for common sensitive variable names:
Customizing mask patterns
Scoped mask patterns
You can set mask patterns for specific code blocks using contexts:
Ignoring variables
Variable names matching ignore patterns are not captured at all. This is useful for excluding internal variables, temporary data, or framework-specific variables that don't provide debugging value.
By default, Python internal variables (starting with __) are ignored.
Customizing ignore patterns
Scoped ignore patterns
You can set ignore patterns for specific code blocks using contexts: