diff --git a/chatbot_ner/settings.py b/chatbot_ner/settings.py index fd75dfa0e..84b9ff273 100755 --- a/chatbot_ner/settings.py +++ b/chatbot_ner/settings.py @@ -16,6 +16,7 @@ from chatbot_ner.setup_sentry import setup_sentry BASE_DIR = os.path.dirname(os.path.dirname(__file__)) +ENVIRONMENT = os.environ.get('ENVIRONMENT') or os.environ.get('HAPTIK_ENV') # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ @@ -59,6 +60,28 @@ 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] +# APM +_elastic_apm_enabled = (os.environ.get('ELASTIC_APM_ENABLED') or '').strip().lower() +ELASTIC_APM_ENABLED = (_elastic_apm_enabled == 'true') and 'test' not in sys.argv +ELASTIC_APM_SERVER_URL = os.environ.get('ELASTIC_APM_SERVER_URL') +if ELASTIC_APM_ENABLED: + ELASTIC_APM = { + 'DEBUG': DEBUG, + 'SERVICE_NAME': 'chatbot_ner', + 'SERVER_URL': ELASTIC_APM_SERVER_URL, + 'SPAN_FRAMES_MIN_DURATION': '5ms', + 'STACK_TRACE_LIMIT': 500, + 'ENVIRONMENT': ENVIRONMENT, + 'TRANSACTION_SAMPLE_RATE': '0.1', + 'TRANSACTION_MAX_SPANS': 500, + 'INSTRUMENT': 'True', + 'DISABLE_SEND': 'False', + 'CAPTURE_BODY': 'off', + 'SERVER_TIMEOUT': '2s', + } + INSTALLED_APPS.append('elasticapm.contrib.django') + MIDDLEWARE.append('elasticapm.contrib.django.middleware.TracingMiddleware') + ROOT_URLCONF = 'chatbot_ner.urls' WSGI_APPLICATION = 'chatbot_ner.wsgi.application' diff --git a/requirements.txt b/requirements.txt index dfd947946..13ecaa3bb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,7 @@ pytz==2014.2 nltk==3.4.5 numpy==1.16 elasticsearch==5.5.0 +elastic-apm==5.10.0 requests==2.20.0 requests-aws4auth==0.9 Django==1.11.29