Skip to content

Commit

Permalink
Upgraded NewRelic to v10.3.0 (#2367)
Browse files Browse the repository at this point in the history
* Upgraded NewRelic to v10.3.0 and disable package reporting in all environments

* Tweak log msg for gunicorn total time

* Tweaked environment variables reuse

* Pass environment to NewRelic of Celery

* Fixed import sorting
  • Loading branch information
jimleroyer authored Nov 21, 2024
1 parent d2081d1 commit 7da719b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 27 deletions.
9 changes: 6 additions & 3 deletions gunicorn_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import gunicorn # type: ignore
import newrelic.agent # See https://bit.ly/2xBVKBH

newrelic.agent.initialize(environment=os.getenv("NOTIFY_ENVIRONMENT")) # noqa: E402
environment = os.environ.get("NOTIFY_ENVIRONMENT")
newrelic.agent.initialize(environment=environment) # noqa: E402

workers = 4
worker_class = "gevent"
Expand All @@ -16,7 +17,7 @@
# Guincorn sets the server type on our app. We don't want to show it in the header in the response.
gunicorn.SERVER = "Undisclosed"

on_aws = os.environ.get("NOTIFY_ENVIRONMENT", "") in [
on_aws = environment in [
"production",
"staging",
"scratch",
Expand Down Expand Up @@ -69,7 +70,9 @@ def worker_abort(worker):
def on_exit(server):
elapsed_time = time.time() - start_time
server.log.info("Stopping Notifications API")
server.log.info("Total gunicorn running time: {:.2f} seconds".format(elapsed_time))
server.log.info(
"Total gunicorn API running time: {:.2f} seconds".format(elapsed_time)
)


def worker_int(worker):
Expand Down
3 changes: 0 additions & 3 deletions newrelic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,11 @@ package_reporting.enabled = false
[newrelic:development]
# monitor_mode = false
log_level = debug
package_reporting.enabled = true

[newrelic:staging]
# app_name = Python Application (Staging)
# monitor_mode = true
log_level = debug
package_reporting.enabled = true

[newrelic:production]
# monitor_mode = true
Expand All @@ -219,6 +217,5 @@ package_reporting.enabled = true
[newrelic:dev]
# monitor_mode = false
log_level = debug
package_reporting.enabled = true

# ---------------------------------------------------------------------------
52 changes: 33 additions & 19 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ PyYAML = "6.0.1"

cachelib = "0.12.0"
SQLAlchemy = "1.4.52"
newrelic = "9.2.0"
newrelic = "10.3.0"
notifications-python-client = "6.4.1"
python-dotenv = "1.0.1"
pwnedpasswords = "2.0.0"
Expand Down
5 changes: 4 additions & 1 deletion run_celery.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env python
import os

import newrelic.agent # See https://bit.ly/2xBVKBH
from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.ext.flask.middleware import XRayMiddleware
Expand All @@ -7,7 +9,8 @@

from app.aws.xray.context import NotifyContext

newrelic.agent.initialize() # noqa: E402
environment = os.environ.get("NOTIFY_ENVIRONMENT")
newrelic.agent.initialize(environment=environment) # noqa: E402

# notify_celery is referenced from manifest_delivery_base.yml, and cannot be removed
from app import create_app, notify_celery # noqa
Expand Down

0 comments on commit 7da719b

Please sign in to comment.