diff --git a/api/app/settings/common.py b/api/app/settings/common.py index 23ae93804e5b..e7502412cfd3 100644 --- a/api/app/settings/common.py +++ b/api/app/settings/common.py @@ -297,12 +297,15 @@ USE_POSTGRES_FOR_ANALYTICS = env.bool("USE_POSTGRES_FOR_ANALYTICS", default=False) -# NOTE: Because we use Postgres for analytics data in staging and Influx for tracking SSE data, -# we need to support setting the influx configuration alongside using postgres for analytics. -if USE_POSTGRES_FOR_ANALYTICS: - MIDDLEWARE.append("app_analytics.middleware.APIUsageMiddleware") -elif INFLUXDB_TOKEN: - MIDDLEWARE.append("app_analytics.middleware.InfluxDBMiddleware") +ENABLE_API_USAGE_TRACKING = env.bool("ENABLE_API_USAGE_TRACKING", default=True) + +if ENABLE_API_USAGE_TRACKING: + # NOTE: Because we use Postgres for analytics data in staging and Influx for tracking SSE data, + # we need to support setting the influx configuration alongside using postgres for analytics. + if USE_POSTGRES_FOR_ANALYTICS: + MIDDLEWARE.append("app_analytics.middleware.APIUsageMiddleware") + elif INFLUXDB_TOKEN: + MIDDLEWARE.append("app_analytics.middleware.InfluxDBMiddleware") ALLOWED_ADMIN_IP_ADDRESSES = env.list("ALLOWED_ADMIN_IP_ADDRESSES", default=list()) diff --git a/docs/docs/deployment/hosting/locally-api.md b/docs/docs/deployment/hosting/locally-api.md index b029425dac38..5debcb744f00 100644 --- a/docs/docs/deployment/hosting/locally-api.md +++ b/docs/docs/deployment/hosting/locally-api.md @@ -107,8 +107,9 @@ application. Further information on the admin pages can be found [here](/deployment/configuration/django-admin). [^1]: - Your Flagsmith's domain can also be configured via the `FLAGSMITH_DOMAIN` environment variable. See the - [full list](#application-environment-variables) of variables used for configuration. + +Your Flagsmith's domain can also be configured via the `FLAGSMITH_DOMAIN` environment variable. See the +[full list](#application-environment-variables) of variables used for configuration. ## Deploying @@ -251,6 +252,9 @@ the below variables will be ignored. and hence should not be modified for already running instances of flagsmith. It should only be used for new installations, and should not be modified. WARNING: setting this to a higher limit may prevent imports to our SaaS platform if required in the future. +- `ENABLE_API_USAGE_TRACKING`: Enable tracking of all API requests in Postgres / Influx. Default is True. Setting to + False will mean that the Usage tab in the Organisation Settings will not show any data. Useful when using Postgres for + analytics in high traffic environments to limit the size of database. #### Security Environment Variables