newrelic / newrelic-php-agent

The New Relic PHP Agent
https://opensource.newrelic.com/projects/newrelic/newrelic-php-agent
Apache License 2.0
119 stars 61 forks source link

configure via environment variables #969

Open Jimbolino opened 4 days ago

Jimbolino commented 4 days ago

Summary

In our current setup we build a docker image that includes the newrelic-php-agent. The same docker image is deployed to different environments (testing, staging, production) During the docker build stage, we write a newrelic.appname to the newrelic.ini file, this works, but we would like to add a variable from the environment to this, so we can more easily differentiate between staging and production environments.

Possible Solution

I've tried a solution where i've added the following lines to my php scripts

if (extension_loaded('newrelic')) {
    newrelic_set_appname('Dashboard PHP '.getenv('APP_ENV_NAME'));
}

But for some reason this does not seem to work with our laravel artisan queue worker (maybe because the queue runner forks a new worker process)

A better solution would be the possibility to use environment variables, either through the .ini file, or let the agent read the environment directly.

Additional context

Some people think the best way for configuration is via environment variables (https://12factor.net/config) But maybe i missed something or there is a better solutions to this problem 😄

workato-integration[bot] commented 4 days ago

https://new-relic.atlassian.net/browse/NR-322495