我使用zappa将python/django wsgi应用程序部署到awsapi网关和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
作为documented执行“手动代理启动”:
我不使用@newrelic.agent.wsgi_application
,因为django应该是自动检测到的
我添加了一个中间件来在lambda冻结之前关闭代理,但是日志显示只有第一个请求被发送到newrelic。如果没有关闭,就不会从newrelic代理获取日志记录,并且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,这导致了上面的一些黑客行为(environment var,在初始化之前只编辑newrelic.agent.global_settings()
:
[newrelic:dev-zappa]
app_name = DEV APP zappa
monitor_mode = true
TL;DR-两个问题:
Zappa不使用wsgi.py文件(当前),所以那里的钩子没有发生。看看这个PR允许它:https://github.com/Miserlou/Zappa/pull/1251
相关问题 更多 >
编程相关推荐