Skip to content

Commit

Permalink
🐛 Fix Elastic APM configuration
Browse files Browse the repository at this point in the history
previously, MIDDLEWARE and INSTALLED_APPS were not updated, so the integration did not work
  • Loading branch information
stevenbal committed Apr 8, 2022
1 parent 823c027 commit 546c140
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
12 changes: 12 additions & 0 deletions docs/installation/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ Database settings

* ``DB_PORT``: Port number of the database. Defaults to ``5432``.

Elastic APM settings
--------------------

An integration with `Elastic APM <https://www.elastic.co/observability/application-performance-monitoring>`_
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
--------------

Expand Down
16 changes: 13 additions & 3 deletions src/objects/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 546c140

Please sign in to comment.