Skip to content

Commit

Permalink
Move packages / PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehgrantsgov committed Dec 6, 2024
1 parent 678937a commit 1fbdac8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import sys
from types import TracebackType
from typing import Any, Dict, Optional, Tuple, Union
from typing import Any

import newrelic.agent

Expand All @@ -11,15 +11,13 @@
EVENT_API_ATTRIBUTE_LIMIT = 255


def record_custom_event(event_type: str, params: Dict[Any, Any]) -> None:
def record_custom_event(event_type: str, params: dict[Any, Any]) -> None:
# legacy aliases
params["request.uri"] = params.get("request.path")
params["request.headers.x-amzn-requestid"] = params.get("request_id")

# legacy FineosError attribute aliases
params["api.request.method"] = params.get("request.method")
params["api.request.uri"] = params.get("request.path")
params["api.request.headers.x-amzn-requestid"] = params.get("request_id")

# If there are more custom attributes than the limit, the agent will upload
# a partial payload, dropping keys after hitting its limit
Expand All @@ -41,9 +39,7 @@ def record_custom_event(event_type: str, params: Dict[Any, Any]) -> None:
)


def log_and_capture_exception(
msg: str, extra: Optional[Dict] = None, only_warn: bool = False
) -> None:
def log_and_capture_exception(msg: str, extra: dict | None = None, only_warn: bool = False) -> None:
"""
Sometimes we want to record custom messages that do not match an exception message. For example, when a ValidationError contains
multiple issues, we want to log and record each one individually in New Relic. Injecting a new exception with a
Expand All @@ -53,9 +49,7 @@ def log_and_capture_exception(
"""

info = sys.exc_info()
info_with_readable_msg: Union[
BaseException, Tuple[type, BaseException, Optional[TracebackType]]
]
info_with_readable_msg: BaseException | tuple[type, BaseException, TracebackType | None]

if info[0] is None:
exc = Exception(msg)
Expand Down
6 changes: 3 additions & 3 deletions api/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import src.api.feature_flags.feature_flag_config as feature_flag_config
import src.logging
import src.logging.flask_logger as flask_logger
from src.adapters.newrelic import init_newrelic
from src.api.agencies_v1 import agency_blueprint as agencies_v1_blueprint
from src.api.extracts_v1 import extract_blueprint as extracts_v1_blueprint
from src.api.healthcheck import healthcheck_blueprint
Expand All @@ -29,10 +30,11 @@
from src.search.backend.load_search_data_blueprint import load_search_data_blueprint
from src.task import task_blueprint
from src.util.env_config import PydanticBaseEnvConfig
from src.util.newrelic import init_newrelic

logger = logging.getLogger(__name__)

init_newrelic()

TITLE = "Simpler Grants API"
API_OVERALL_VERSION = "v0"
API_DESCRIPTION = """
Expand Down Expand Up @@ -68,8 +70,6 @@ def create_app() -> APIFlask:
if os.getenv("ENVIRONMENT") == "local":
initialize_jwt_auth()

init_newrelic()

return app


Expand Down

0 comments on commit 1fbdac8

Please sign in to comment.