diff --git a/docs/installation/config.rst b/docs/installation/config.rst index 01dac6fb..c88b83ad 100644 --- a/docs/installation/config.rst +++ b/docs/installation/config.rst @@ -43,6 +43,18 @@ Database settings * ``DB_PORT``: Port number of the database. Defaults to ``5432``. +Elastic APM settings +-------------------- + +An integration with `Elastic APM `_ +can be configured by setting the following environment variables + +* ``ELASTIC_APM_SERVICE_NAME``: the name of the service in APM, i.e. "Objects API - staging" + +* ``ELASTIC_APM_SERVER_URL``: the URL of the APM instance to connect with + +* ``ELASTIC_APM_SECRET_TOKEN``: the token that is required to communicate with the APM instance + Other settings -------------- diff --git a/src/objects/conf/base.py b/src/objects/conf/base.py index 61940296..2498e7a8 100644 --- a/src/objects/conf/base.py +++ b/src/objects/conf/base.py @@ -388,13 +388,23 @@ **SENTRY_CONFIG, integrations=SENTRY_SDK_INTEGRATIONS, send_default_pii=True ) +# # Elastic APM - +# +ELASTIC_APM_SERVER_URL = os.getenv("ELASTIC_APM_SERVER_URL", None) ELASTIC_APM = { - "SERVICE_NAME": "objects", + "SERVICE_NAME": os.getenv("ELASTIC_APM_SERVICE_NAME", "Objects API"), "SECRET_TOKEN": os.getenv("ELASTIC_APM_SECRET_TOKEN", "default"), - "SERVER_URL": os.getenv("ELASTIC_APM_SERVER_URL", "http://example.com"), + "SERVER_URL": ELASTIC_APM_SERVER_URL, } +if not ELASTIC_APM_SERVER_URL: + ELASTIC_APM["ENABLED"] = False + ELASTIC_APM["SERVER_URL"] = None +else: + MIDDLEWARE = ["elasticapm.contrib.django.middleware.TracingMiddleware"] + MIDDLEWARE + INSTALLED_APPS = INSTALLED_APPS + [ + "elasticapm.contrib.django", + ] SITE_ID = os.getenv("SITE_ID", 1)