Skip to content

typisttech/trellis-newrelic-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trellis New Relic PHP Agent

Ansible Role GitHub tag (latest SemVer) Ansible Role Ansible Quality Score GitHub GitHub Sponsor Sponsor via PayPal Hire Typist Tech Twitter Follow @TangRufus

Install New Relic PHP agent on Trellis servers.

Role Variables

# group_vars/<environment>/vault.yml
# This file should be encrypted. See: https://roots.io/trellis/docs/vault/
##########################################################################

# New Relic License Key
## See: https://docs.newrelic.com/docs/accounts-partnerships/accounts/account-setup/license-key
vault_newrelic_license: xxxxxxxxxxx

# group_vars/<environment>/main.yml
###################################

# Indicates the desired package state.
# `latest` ensures that the latest version is installed.
# `present` does not update if already installed.
# Choices: present|latest
# Default: latest
newrelic_package_state: present

# Check for default values here: https://github.com/TypistTech/trellis-newrelic-php/blob/master/defaults/main.yml
# See also: https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-configuration
newrelic_config:
  appname: "My Awesome App {{ env }}"
  framework: no_framework
  transaction_tracer.detail: 1
  datastore_tracer.database_name_reporting.enabled: true

Hacking Trellis' Playbook

Add this role to dev.yml and server.yml immediately after role: php:

  # `dev.yml` & `server.yml`

  roles:
      # Some other Trellis roles ...
      - { role: php, tags: [php] }
+     - { role: TypistTech.trellis-newrelic-php, tags: [php, newrelic-php] }
      # Some other Trellis roles ...

Requirements

Installation

Add this role to galaxy.yml:

- src: TypistTech.trellis-newrelic-php # Case-sensitive!
  version: XXX.YYY.ZZZ # Check for latest version!

Run $ trellis galaxy install to install this new role.

Common Errors

vault_newrelic_license is not defined

Encrypt your New Relic license key in group_vars/<environment>/vault.yml. See role variables.

New Relic merges multiple environments into single application

Solution: Define different appname for different environments.

Tips:

# group_vars/all/main.yml
#########################

newrelic_config:
  appname: "My Awesome App {{ env }}"

Error after upgrading PHP version

New Relic would fail and causes provision end up in errors when upgrading PHP major or minor releases (e.g: from 7.4 to 8.0, from 8.0 to 8.1).

non-zero return code
PHP Warning:  PHP Startup: Unable to load dynamic library 'newrelic.so'
(tried: /usr/lib/php/20180731/newrelic.so (/usr/lib/php/20180731/newrelic.so:
cannot open shared object file: No such file or directory),
/usr/lib/php/20180731/newrelic.so.so (/usr/lib/php/20180731/newrelic.so.so:
cannot open shared object file: No such file or directory)) in Unknown on

After each PHP major or minor release upgrade (i.e: when you see the above error):

# For multi-server setups, perform the following steps on each server.
ssh admin@123.456.789
sudo newrelic-install install
sudo reboot

# Wait for the server(s) to reboot and then re-provision
# For multi-server setups, you only need to re-provision once only
trellis provision production

Limitations

  • Only one New Relic APM application per server by default.

Extends the fastcgi_basic block to include fastcgi_param PHP_VALUE "newrelic.appname={{ item.key }} ({{ env }})"; right after the line include fastcgi_params; to work around this limitation.

Pull requests are welcomed.

FAQs

It looks awesome. Where can I find some more goodies like this?

This package isn't on wp.org. Where can I give a ⭐⭐⭐⭐⭐ review?

Thanks! Glad you like it. It's important to let me know somebody is using this project. Since this is not hosted on wordpress.org, please consider:

Sponsoring ❤️

Love trellis-newrelic-php? Help me maintain it, a sponsorship here can help with it.

GitHub Sponsors Matching Fund

Do you know GitHub is going to match your sponsorship?

Sponsor now via GitHub to double your greatness.

Why don't you hire me?

Ready to take freelance WordPress jobs. Contact me via the contact form here or, via email info@typist.tech

Want to help in other way? Want to be a sponsor?

Contact: Tang Rufus

Feedback

Please provide feedback! We want to make this library useful in as many projects as possible. Please submit an issue and point out what you do and don't like, or fork the project and make suggestions. No issue is too small.

Security

If you discover any security related issues, please email trellis-newrelic-php@typist.tech instead of using the issue tracker.

Credits

Trellis New Relic PHP Agent is a Typist Tech project and maintained by Tang Rufus, freelance developer for hire.

Full list of contributors can be found here.

Special thanks to the Roots team whose Trellis make this project possible.

Contributing

Please see CODE_OF_CONDUCT for details.

License

Trellis New Relic PHP Agent is released under the MIT License.