Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Add Sentry, allow different env configs
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Jun 19, 2024
1 parent db5a8f3 commit 6da2313
Show file tree
Hide file tree
Showing 7 changed files with 403 additions and 236 deletions.
24 changes: 22 additions & 2 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
from config import Config
import os

import sentry_sdk
from fastapi import FastAPI


def get_config():
config_class = os.getenv("CONFIG", "config.Production")
components = config_class.split(".")
mod = __import__(components[0])
for comp in components[1:]:
mod = getattr(mod, comp)
return mod()


def create_app():
config = Config()
config = get_config()

if config.SENTRY_DSN:
sentry_sdk.init(
dsn=config.SENTRY_DSN,
traces_sample_rate=config.SENTRY_SAMPLE_RATE,
profiles_sample_rate=config.SENTRY_SAMPLE_RATE,
)

app = FastAPI(title="ETNA Search API", log_level=config.LOG_LEVEL)
app.state.config = config
base_uri = "/api/v1"

@app.get("/healthcheck/live/", include_in_schema=False)
Expand Down
5 changes: 3 additions & 2 deletions app/sources/rosetta/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
RecordSearchResults,
)
from app.schemas import Filter
from config import Config

from app import get_config

from .lib import RosettaResponseParser, RosettaSourceParser

# from pydash import objects


class RosettaRecords(GetAPI):
api_base_url = Config().ROSETTA_API_URL
api_base_url = get_config().ROSETTA_API_URL


class RosettaRecordsSearch(RosettaRecords):
Expand Down
5 changes: 3 additions & 2 deletions app/sources/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from app.articles.schemas import Article, ArticleSearchResults
from app.lib.api import GetAPI
from app.schemas import Filter
from config import Config

from app import get_config


class WagtailAPI(GetAPI):
api_base_url = Config().WAGTAIL_API_URL
api_base_url = get_config().WAGTAIL_API_URL

def __init__(self):
self.api_base_url
Expand Down
28 changes: 27 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,39 @@
from app.lib.util import strtobool


class Config:
class Base(object):
ENVIRONMENT = os.environ.get("ENVIRONMENT", "production")

SECRET_KEY = os.environ.get("SECRET_KEY")

DEBUG = strtobool(os.getenv("DEBUG", "False"))
LOG_LEVEL = os.getenv("LOG_LEVEL", "info")

SENTRY_DSN = os.getenv("SENTRY_DSN", "")
SENTRY_SAMPLE_RATE = float(os.getenv("SENTRY_SAMPLE_RATE", "1.0"))
SENTRY_JS = os.getenv("SENTRY_JS", "")

ROSETTA_API_URL = os.environ.get("ROSETTA_API_URL").rstrip("/")
WAGTAIL_API_URL = os.environ.get("WAGTAIL_API_URL").rstrip("/")

ELASTICSEARCH_RESULTS_LIMIT = int(
os.environ.get("ELASTICSEARCH_RESULTS_LIMIT", "10000")
)


class Production(Base):
pass


class Staging(Base):
pass


class Develop(Base):
DEBUG = strtobool(os.getenv("DEBUG", "True"))


class Test(Base):
ENVIRONMENT = "test"

DEBUG = True
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:
IMAGE_TAG: preview
environment:
- ENVIRONMENT=develop
- CONFIG=config.Develop
- SECRET_KEY=abc123
- LOG_LEVEL=debug
- ROSETTA_API_URL=http://afa13a7c0067b4f01991b0bad9e003a4-edf0e30af2b95f5f.elb.eu-west-2.amazonaws.com/api/v1
Expand Down
575 changes: 346 additions & 229 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ requests = "^2.31.0"
fastapi = "^0.110.0"
pyquery = "^2.0.0"
pydash = "^7.0.6"
sentry-sdk = {extras = ["fastapi"], version = "^2.5.1"}

[build-system]
requires = ["poetry-core"]
Expand Down

0 comments on commit 6da2313

Please sign in to comment.