AWS lambda 上的 New Relic 不读取其配置文件
New Relic on AWS lambda not reading its config file
我正在使用 zappa 将 python/django wsgi 应用程序部署到 AWS API 网关和 Lambda。
我的环境中有所有这些:
NEW_RELIC_CONFIG_FILE: /var/task/newrelic.ini
NEW_RELIC_LICENSE_KEY: redacted
NEW_RELIC_ENVIRONMENT: dev-zappa
NEW_RELIC_STARTUP_DEBUG: "on"
NEW_RELIC_ENABLED: "on"
我在 wsgi.py
中做 "manual agent start" 作为 documented:
import newrelic.agent
# Will collect NEW_RELIC_CONFIG_FILE and NEW_RELIC_ENVIRONMENT from the environment
# Dear god why??!?!
# NB: Looks like this IS what makes it go
newrelic.agent.global_settings().enabled = True
newrelic.agent.initialize('/var/task/newrelic.ini', 'dev-zappa', log_file='stderr', log_level=logging.DEBBUG)
我没有使用@newrelic.agent.wsgi_application
,因为django应该被自动神奇地检测到
我已经添加了一个中间件来在 lambda 被冻结之前关闭代理,但是日志记录表明只有第一个请求被发送到 New Relic。没有关机,我从 New Relic 代理中得不到任何日志记录,APM 中也没有任何事件。
class NewRelicShutdownMiddleware(MiddlewareMixin):
"""Simple middleware that shutsdown the NR agent at the end of a request"""
def process_request(self, request):
pass
# really wait for the agent to register with collector
# Enabling this causes more log messages about starting data samplers, but only on the first request
# newrelic.agent.register_application(timeout=10)
def process_response(self, request, response):
newrelic.agent.shutdown_agent(timeout=2.5)
return response
def process_exception(self, request, exception):
pass
newrelic.agent.shutdown_agent(timeout=2.5)
在我的 newrelic.ini
中,我有以下内容,但是当我登录 newrelic.agent.global_settings()
时,它包含默认的应用程序名称(确实是在 APM 中创建的)和 enabled = False,这导致了一些上面的黑客攻击(环境变量,并在初始化之前编辑 newrelic.agent.global_settings()
:
[newrelic:dev-zappa]
app_name = DEV APP zappa
monitor_mode = true
TL;DR - 两个问题:
- 如何让 New Relic 在它不想读取它的 ini 文件时读取它?
- 如何让 New Relic 记录 AWS lambda 中所有请求的数据?
Zappa 不使用您的 wsgi.py 文件(当前),因此不会发生挂钩。看看这个允许它的 PR:https://github.com/Miserlou/Zappa/pull/1251
我正在使用 zappa 将 python/django wsgi 应用程序部署到 AWS API 网关和 Lambda。
我的环境中有所有这些:
NEW_RELIC_CONFIG_FILE: /var/task/newrelic.ini
NEW_RELIC_LICENSE_KEY: redacted
NEW_RELIC_ENVIRONMENT: dev-zappa
NEW_RELIC_STARTUP_DEBUG: "on"
NEW_RELIC_ENABLED: "on"
我在 wsgi.py
中做 "manual agent start" 作为 documented:
import newrelic.agent
# Will collect NEW_RELIC_CONFIG_FILE and NEW_RELIC_ENVIRONMENT from the environment
# Dear god why??!?!
# NB: Looks like this IS what makes it go
newrelic.agent.global_settings().enabled = True
newrelic.agent.initialize('/var/task/newrelic.ini', 'dev-zappa', log_file='stderr', log_level=logging.DEBBUG)
我没有使用@newrelic.agent.wsgi_application
,因为django应该被自动神奇地检测到
我已经添加了一个中间件来在 lambda 被冻结之前关闭代理,但是日志记录表明只有第一个请求被发送到 New Relic。没有关机,我从 New Relic 代理中得不到任何日志记录,APM 中也没有任何事件。
class NewRelicShutdownMiddleware(MiddlewareMixin):
"""Simple middleware that shutsdown the NR agent at the end of a request"""
def process_request(self, request):
pass
# really wait for the agent to register with collector
# Enabling this causes more log messages about starting data samplers, but only on the first request
# newrelic.agent.register_application(timeout=10)
def process_response(self, request, response):
newrelic.agent.shutdown_agent(timeout=2.5)
return response
def process_exception(self, request, exception):
pass
newrelic.agent.shutdown_agent(timeout=2.5)
在我的 newrelic.ini
中,我有以下内容,但是当我登录 newrelic.agent.global_settings()
时,它包含默认的应用程序名称(确实是在 APM 中创建的)和 enabled = False,这导致了一些上面的黑客攻击(环境变量,并在初始化之前编辑 newrelic.agent.global_settings()
:
[newrelic:dev-zappa]
app_name = DEV APP zappa
monitor_mode = true
TL;DR - 两个问题:
- 如何让 New Relic 在它不想读取它的 ini 文件时读取它?
- 如何让 New Relic 记录 AWS lambda 中所有请求的数据?
Zappa 不使用您的 wsgi.py 文件(当前),因此不会发生挂钩。看看这个允许它的 PR:https://github.com/Miserlou/Zappa/pull/1251