Skip to content

Commit 7c0164d

Browse files
ben851Ben Larabie
andauthored
Remove new relic from API (#2828)
* Format * remove environment * remove import --------- Co-authored-by: Ben Larabie <ben.larabie@blarabie-jtfk.home>
1 parent 15bf967 commit 7c0164d

10 files changed

Lines changed: 2 additions & 337 deletions

File tree

.github/workflows/lambda_staging.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,7 @@ jobs:
4545
- name: Build container
4646
run: |
4747
set -euo pipefail
48-
PARAM_NAME="ENVIRONMENT_VARIABLES"
49-
RAW=$(aws ssm get-parameter \
50-
--name "$PARAM_NAME" \
51-
--with-decryption \
52-
--query 'Parameter.Value' \
53-
--output text || true)
54-
# Fallback to false if not present
55-
NEW_RELIC_ENABLED=$(printf '%s' "$RAW" | grep -E '^NEW_RELIC_ENABLED=' | head -n1 | cut -d '=' -f2- || true)
56-
if [ -z "${NEW_RELIC_ENABLED}" ]; then NEW_RELIC_ENABLED=false; fi
5748
DOCKERFILE="ci/Dockerfile.lambda"
58-
if [ "${NEW_RELIC_ENABLED}" = "true" ] || [ "${NEW_RELIC_ENABLED}" = "TRUE" ]; then
59-
DOCKERFILE="ci/Dockerfile.newrelic.lambda"
60-
echo "NEW_RELIC_ENABLED=$NEW_RELIC_ENABLED -> using ${DOCKERFILE}" >&2
61-
else
62-
echo "NEW_RELIC_ENABLED=$NEW_RELIC_ENABLED -> using plain ${DOCKERFILE}" >&2
63-
fi
6449
docker buildx build \
6550
--provenance=false \
6651
--build-arg GIT_SHA=${GITHUB_SHA::7} \

application.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,7 @@
2828
patch_all()
2929

3030
is_lambda = os.environ.get("AWS_LAMBDA_RUNTIME_API") is not None
31-
enable_newrelic = env.bool("ENABLE_NEW_RELIC", default=False) and not ff_enable_otel
32-
3331
print("is_lambda =", is_lambda)
34-
print("enable_newrelic =", enable_newrelic)
35-
36-
if is_lambda and enable_newrelic:
37-
import newrelic.agent
38-
39-
# Initialize New Relic early, before creating the Flask app
40-
print("Lambda detected, and New Relic enabled - initializing New Relic agent")
41-
environment = os.getenv("NOTIFY_ENVIRONMENT", "dev")
42-
newrelic.agent.initialize("newrelic.ini", environment=environment)
4332

4433
application = Flask("api")
4534
application.wsgi_app = ProxyFix(application.wsgi_app) # type: ignore
@@ -51,12 +40,6 @@
5140
xray_recorder.configure(service="Notify-API", context=NotifyContext())
5241
XRayMiddleware(app, xray_recorder)
5342

54-
# It's annoying that we have to do this here, but order matters
55-
# so we need to check if is lambda twice.
56-
if is_lambda and enable_newrelic:
57-
# Wrap the Flask app with New Relic's WSGI wrapper
58-
app = newrelic.agent.WSGIApplicationWrapper(app)
59-
6043
apig_wsgi_handler = make_lambda_handler(
6144
app, binary_support=True, non_binary_content_type_prefixes=["application/yaml", "application/json"]
6245
)

bin/entry.sh

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,4 @@ else
66
RUNTIME_CMD="$(which python)"
77
fi
88

9-
## IMPORTANT: NEW RELIC CONFIGURATION -- WE ALWAYS WANT TO USE APM MODE!
10-
# Force classic New Relic agent mode for Lambda so data flows to APM instead of the serverless extension
11-
unset NEW_RELIC_LAMBDA_EXTENSION_ENABLED
12-
unset NEW_RELIC_LAMBDA_HANDLER
13-
unset NEW_RELIC_EXTENSION_LOGS_ENABLED
14-
unset NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS
15-
export NEW_RELIC_SERVERLESS_MODE_ENABLED=false
16-
export NEW_RELIC_CONFIG_FILE=${NEW_RELIC_CONFIG_FILE:-/app/newrelic.ini}
17-
189
exec ${RUNTIME_CMD} -m awslambdaric $1

ci/Dockerfile.lambda

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,6 @@ RUN python -m venv ${APP_VENV} \
2828
&& poetry install \
2929
&& poetry add awslambdaric wheel
3030

31-
# Now install NewRelic manually using the setuptools from Poetry
32-
RUN . ${APP_VENV}/bin/activate \
33-
&& wget https://download.newrelic.com/python_agent/release/newrelic-11.0.1.tar.gz \
34-
&& tar -xzf newrelic-11.0.1.tar.gz \
35-
&& cd newrelic-11.0.1 \
36-
&& python setup.py install \
37-
&& cd .. \
38-
&& rm -rf newrelic-11.0.1 newrelic-11.0.1.tar.gz
39-
4031
COPY . ${TASK_ROOT}/
4132

4233
RUN . ${APP_VENV}/bin/activate \

gunicorn_config.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,10 @@
1010

1111
# Ensure these are always defined so other code can rely on them.
1212
os.environ.setdefault("FF_ENABLE_OTEL", os.getenv("FF_ENABLE_OTEL", "False"))
13-
os.environ.setdefault("ENABLE_NEW_RELIC", os.getenv("ENABLE_NEW_RELIC", "False"))
14-
os.environ.setdefault("NEW_RELIC_CONFIG_FILE", os.getenv("NEW_RELIC_CONFIG_FILE", "newrelic.ini"))
1513

1614
env = Env()
1715

1816
ff_enable_otel = env.bool("FF_ENABLE_OTEL", default=False)
19-
enable_newrelic = env.bool("ENABLE_NEW_RELIC", default=False) and not ff_enable_otel
20-
21-
print("enable_newrelic =", enable_newrelic)
22-
23-
if enable_newrelic:
24-
import newrelic.agent
25-
26-
newrelic.agent.initialize(environment=environment) # noqa: E402
2717

2818
default_worker_class = "gevent_otel_worker.OTelAwareGeventWorker" if ff_enable_otel else "gevent"
2919

@@ -61,9 +51,7 @@
6151
# will not be able to finish processing the request. This can lead to
6252
# 502 errors being returned to the client.
6353
#
64-
# Also, some libraries such as NewRelic might need some time to finish
65-
# initialization before the worker can start processing requests. The
66-
# timeout values should consider these factors.
54+
# The timeout values should consider initialization time for libraries.
6755
#
6856
# Gunicorn config:
6957
# https://docs.gunicorn.org/en/stable/settings.html#graceful-timeout

mypy.ini

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[mypy]
22
python_version = 3.12
33
exclude = ^.*/site-packages/.*$
4-
54
[mypy-pytest.*]
65
ignore_missing_imports = True
76

@@ -68,9 +67,6 @@ ignore_missing_imports = True
6867
[mypy-phonenumbers.*]
6968
ignore_missing_imports = True
7069

71-
[mypy-newrelic.*]
72-
ignore_missing_imports = True
73-
7470
[mypy-docopt.*]
7571
ignore_missing_imports = True
7672

newrelic.ini

Lines changed: 0 additions & 221 deletions
This file was deleted.

0 commit comments

Comments
 (0)