diff --git a/Pipfile b/Pipfile index 1bd335c..d859dc8 100644 --- a/Pipfile +++ b/Pipfile @@ -26,6 +26,7 @@ djangorestframework = "*" certifi = ">2022.9.24" django-cors-headers = "*" typing-extensions = ">=3.7.4" +dc-logging-utils = {file = "https://github.com/DemocracyClub/dc_logging/archive/refs/tags/1.0.2.tar.gz"} [dev-packages] pre-commit = "*" @@ -50,7 +51,6 @@ python_version = "3.10" allow_prereleases = true [scripts] - collectstatic = "python manage.py collectstatic -c --noinput" pytest = "pytest" coveralls = "coveralls" diff --git a/Pipfile.lock b/Pipfile.lock index 42157aa..b29b320 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "e60827fbd05293d39cd361c1155ca5f036bc1391e75c43367cf37fc59140e7fa" + "sha256": "9dad81918ac05c4d01c2f2636c44b04e9c276b7a068d94607e84152146c5a70d" }, "pipfile-spec": 6, "requires": { @@ -44,6 +44,14 @@ "markers": "python_version >= '3.7'", "version": "==1.32.4" }, + "cachetools": { + "hashes": [ + "sha256:086ee420196f7b2ab9ca2db2520aca326318b68fe5ba8bc4d49cca91add450f2", + "sha256:861f35a13a451f94e301ce2bec7cac63e881232ccce7ed67fab9b5df4d3beaa1" + ], + "markers": "python_version >= '3.7'", + "version": "==5.3.2" + }, "certifi": { "hashes": [ "sha256:9b469f3a900bf28dc19b8cfbf8019bf47f7fdd1a65a1d4ffb98fc14166beb4d1", @@ -211,6 +219,9 @@ "git": "https://github.com/DemocracyClub/design-system.git", "ref": "09bcc3eb4eccc189b3a19d91dae5b777be52f253" }, + "dc-logging-utils": { + "file": "https://github.com/DemocracyClub/dc_logging/archive/refs/tags/1.0.2.tar.gz" + }, "django": { "hashes": [ "sha256:8e0f1c2c2786b5c0e39fe1afce24c926040fad47c8ea8ad30aaf1188df29fc41", @@ -733,7 +744,7 @@ "sha256:637996211036b6385ef91435e4fae22989472f9d571faba8927ba8253acbc330", "sha256:b8c3f85900b9dc423225913c5aace94729fe1fa9763b38939a95226f02d37186" ], - "markers": "python_version < '3.11' and python_version >= '3.7'", + "markers": "python_version > '3.6' and python_version < '3.11'", "version": "==5.1.1" }, "distlib": { diff --git a/api_endpoints/v1_postcode_lookup/app.py b/api_endpoints/v1_postcode_lookup/app.py index 7dd5540..9277742 100644 --- a/api_endpoints/v1_postcode_lookup/app.py +++ b/api_endpoints/v1_postcode_lookup/app.py @@ -1,5 +1,6 @@ import os +from dc_logging_client import DCWidePostcodeLoggingClient from mangum import Mangum from middleware import MIDDLEWARE from starlette.applications import Starlette @@ -13,9 +14,22 @@ init_sentry() +if logger_arn := os.environ.get("LOGGER_ARN"): + POSTCODE_LOGGER = DCWidePostcodeLoggingClient(function_arn=logger_arn) +else: + POSTCODE_LOGGER = DCWidePostcodeLoggingClient(fake=True) + def get_postcode_response(request: Request): postcode = request.path_params["postcode"] + + # Log this request + POSTCODE_LOGGER.entry_class( + postcode=postcode, + dc_product=POSTCODE_LOGGER.dc_product.ec_api, + calls_devs_dc_api=True, + ) + try: response = client.get_postcode_response(request, postcode) except DevsDCException as error: diff --git a/api_endpoints/v1_postcode_lookup/requirements.txt b/api_endpoints/v1_postcode_lookup/requirements.txt index b23a3c5..231cc16 100644 --- a/api_endpoints/v1_postcode_lookup/requirements.txt +++ b/api_endpoints/v1_postcode_lookup/requirements.txt @@ -2,3 +2,4 @@ sentry-sdk[starlette]==1.19.1 starlette==0.26.1 mangum==0.17.0 requests==2.31.0 +https://github.com/DemocracyClub/dc_logging/archive/refs/tags/1.0.2.tar.gz diff --git a/template.yaml b/template.yaml index 005967e..c31d3e1 100644 --- a/template.yaml +++ b/template.yaml @@ -75,6 +75,11 @@ Parameters: Description: "The domain the app is on." Type: String + AppLoggerArn: + Default: AppLoggerArn + Description: "The ARN of the Lambda function to log to" + Type: AWS::SSM::Parameter::Value + Resources: DependenciesLayer: Type: AWS::Serverless::LayerVersion @@ -110,6 +115,7 @@ Resources: DC_API_TOKEN: !Ref AppDCAPIToken SAM_LAMBDA_CONFIG_ENV: !Ref AppSamLambdaConfigEnv APP_DOMAIN: !Ref AppDomain + LOGGER_ARN: !Ref AppLoggerArn Events: HTTPRequests: Type: Api