Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Elastic-APM optional #65

Merged
merged 1 commit into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions haystack/api/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fastapi import FastAPI, HTTPException
from starlette.middleware.cors import CORSMiddleware

from haystack.api.config import DB_HOST, DB_USER, DB_PW, APM_SERVER
from haystack.api.config import DB_HOST, DB_USER, DB_PW, APM_SERVER, APM_SERVICE_NAME
from haystack.api.controller.errors.http_error import http_error_handler
from haystack.api.controller.router import router as api_router

Expand All @@ -25,9 +25,11 @@ def get_application() -> FastAPI:
application.add_middleware(
CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"],
)
apm_config = {"SERVICE_NAME": "haystack-backend", "SERVER_URL": APM_SERVER, "CAPTURE_BODY": "all"}
elasticapm = make_apm_client(apm_config)
application.add_middleware(ElasticAPM, client=elasticapm)

if APM_SERVER:
apm_config = {"SERVICE_NAME": APM_SERVICE_NAME, "SERVER_URL": APM_SERVER, "CAPTURE_BODY": "all"}
elasticapm = make_apm_client(apm_config)
application.add_middleware(ElasticAPM, client=elasticapm)

application.add_exception_handler(HTTPException, http_error_handler)

Expand Down
3 changes: 2 additions & 1 deletion haystack/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
EMBEDDING_MODEL_PATH = os.getenv("EMBEDDING_MODEL_PATH", None)

# Monitoring
APM_SERVER = "http://localhost:8200"
APM_SERVER = os.getenv("APM_SERVER", None)
APM_SERVICE_NAME = os.getenv("APM_SERVICE_NAME", "haystack-backend")