Toggle analytics events
In order to determine if analytics should be enabled, GX Core checks two sources:
- The environment variable
GX_ANALYTICS_ENABLED
- The Data Context variable
analytics_enabled
If either variable is set to False, analytics collection will be disabled. If the variables are not explicitly set to False, they are assumed to be True.
Methods for toggling analytics collection
Select one of the following methods for toggling analytics collection:
- Environment Variable
- Data Context Variable
The environment variable GX_ANALYTICS_ENABLED
can be used to toggle the collection of analytics information. This is particularly useful when using an Ephemeral Data Context because an Ephemeral Data Context does not persist between Python sessions and therefore won't persist configuration changes made using context.variables
in Python.
GX_ANALYTICS_ENABLED
will also work to toggle analytics collection when using a GX Cloud Data Context or a File Data Context.
Prerequisites
- Python version 3.9 to 3.12
- An installation of GX Core
- Permissions necessary to set local Environment Variables.
Procedure
-
Set the environment variable
GX_ANALYTICS_ENABLED
.You can set environment variables through terminal commands or by adding the equivalent commands to your
~/.bashrc
file. If you set the environment variable directly from the terminal, the environment variable will not persist beyond the current session. If you add them to the~/.bashrc
file, the variable will be exported each time you log in.To set the
GX_ANALYTICS_ENABLED
environment variable, use the command:Terminal or ~/.bashrcexport GX_ANALYTICS_ENABLED=False
or:
Terminal or ~/.bashrcexport GX_ANALYTICS_ENABLED=True
-
Initialize a Data Context in Python.
Analytics settings are checked when a Data Context is initialized. Therefore, for a change to
GX_ANALYTICS_ENABLED
to take effect, the Data Context must be initialized after the environment variable has been set.If you already have a Data Context in a Python environment when you make a change to
GX_ANALYTICS_ENABLED
, you can re-initialize it by updating the value ofmy_mode
withephemeral
,file
, orcloud
and executing the following code:Pythonmy_mode = "file"
context = gx.get_context(mode=my_mode)For more information on initializing a Data Context, see Create a Data Context.
The Data Context variable analytics_enabled
can be used to toggle the collection of analytics information. Because the analytics configuration is loaded when a Data Context is initialized this method is only suitable when working with a File Data Context. For other types of Data Context, use the Environment Variable method for toggling analytics collection.
Prerequisites
Procedure
- Tutorial
- Sample code
-
Set the Data Context variable
analytics_enabled
.With a File Data Context you can set the
analytics_enabled
Data Context variable and your setting will persist between sessions.To set the
analytics_enabled
Data Context variable, use the command:Pythoncontext.variables.analytics_enabled = False
or:
Pythoncontext.variables.analytics_enabled = True
-
Save changes to
analytics_enabled
.Changes to your File Data Context's variables reside in memory and will not persist between sessions unless they are explicitly pushed to the Data Context's configuration file. To push your changes to the Data Context's configuration file execute the following code:
Pythoncontext.variables.save()
-
Re-initialize the Data Context.
Analytics settings are checked when a Data Context is initialized. Therefore, for a change to
analytics_enabled
to take effect, the File Data Context must be re-initialized after the change has been saved to the Data Context's configuration file.Pythoncontext = gx.get_context(mode="file")
For more information on initializing a Data Context, see Create a Data Context.
import great_expectations as gx
# Get a File Data Context:
context = gx.get_context(mode="file")
# Set the `analytics_enabled` Data Context variable:
context.variables.analytics_enabled = True
# or:
context.variables.analytics_enabled = False
# Save the change to the Data Context's config file:
context.variables.save()
# Re-initialize the Data Context using the updated
# `analytics_enabled` configuration:
context = gx.get_context(mode="file")