AWS lambda上的newrelic没有读取它的配置fi

2024-06-16 09:26:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用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执行“手动代理启动”:

^{pr2}$

我不使用@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-两个问题:

  1. 如何让newrelic在不想读的时候读取它的ini文件?在
  2. 如何让newrelic在AWS lambda中记录所有请求的数据?在

Tags: theselfwsgi代理newonrequestdef