|
28 | 28 | patch_all() |
29 | 29 |
|
30 | 30 | 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 | | - |
33 | 31 | 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) |
43 | 32 |
|
44 | 33 | application = Flask("api") |
45 | 34 | application.wsgi_app = ProxyFix(application.wsgi_app) # type: ignore |
|
51 | 40 | xray_recorder.configure(service="Notify-API", context=NotifyContext()) |
52 | 41 | XRayMiddleware(app, xray_recorder) |
53 | 42 |
|
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 | | - |
60 | 43 | apig_wsgi_handler = make_lambda_handler( |
61 | 44 | app, binary_support=True, non_binary_content_type_prefixes=["application/yaml", "application/json"] |
62 | 45 | ) |
|
0 commit comments