• Stars
    star
    280
  • Rank 144,391 (Top 3 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 12 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Add NewRelic support to Symfony

Ekino NewRelic Bundle

Build Status Latest Version Code Coverage Quality Score Total Downloads

This bundle integrates the NewRelic PHP API into Symfony. For more information about NewRelic, please visit http://newrelic.com. The built-in New Relic agent doesn't add as much Symfony integration as it claims. This bundle adds a lot more essentials. Here's a quick list:

  1. Better transaction naming strategy: Your transaction traces can be named accurately by route names, the controller name or you can decide on a custom naming strategy via a seamless interface that uses any naming convention you deem fit. While running console commands, it also sets the transaction name as the command name.

  2. Console Commands Enhancements: While running console commands, its sets the options and arguments passed via the CLI as custom parameters to the transaction trace for easier debugging.

  3. Exception Listening: It also captures all Symfony exceptions in web requests and console commands and sends them to New Relic (something new relic doesn't do too well itself as symfony aggressively catches all exceptions/errors). It also ensures all HTTP Exceptions (4xx codes) are logged as notices in New Relic and not exceptions to reduce the noise in New Relic.

  4. Interactor Service: It provides you the New Relic PHP Agent API via a Service class NewRelicInteractorInterface::class so in my code, I can inject it into any class, controller, service and do stuff like -

    // Bundle
    $this->newRelic->addCustomParameter('name', 'john');
    
    // Extension
    if (extension_loaded('newrelic')) {
        \newrelic_add_custom_parameter('name', 'john');
    }
  5. Logging Support: In development, you are unlikely to have New Relic setup. There's a configuration to enable logging which outputs all New Relic actions to your Symfony log, hence emulating what it would actually do in production.

  6. Ignored Routes, Paths, Commands: You can configure a list of route name, url paths and console commands to be ignored from New Relic traces.

    image

  7. Misc: There are other useful configuration like your New Relic API Key, explicitly defining your app name instead of php.ini, notifying New Relic about new deployments via capifony, etc.

Ekino NewRelicBundle

Installation

Step 0 : Install NewRelic

review http://newrelic.com ...

Step 1: add dependency

$ composer require ekino/newrelic-bundle

Step 2 : Register the bundle

Then register the bundle with your kernel:

<?php

// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new Ekino\NewRelicBundle\EkinoNewRelicBundle(),
    // ...
);

Step 3 : Configure the bundle

In New Relic's web interface, make sure to get a valid (REST) API Key, not to be confused with your License key : New Relic Dashboard > Account settings > Integration > API Keys

# app/config/config.yml

ekino_new_relic:
    enabled: true                         # Defaults to true
    application_name: Awesome Application # default value in newrelic is "PHP Application", or whatever is set
                                          # as php ini-value
    deployment_names: ~                   # default value is 'application_name', supports string array or semi-colon separated string
    api_key:                              # New Relic API
    api_host: ~                           # New Relic API Host (default value is api.newrelic.com, for EU should be set to api.eu.newrelic.com )
    license_key:                          # New Relic license key (optional, default value is read from php.ini)
    xmit: false                           # if you want to record the metric data up to the point newrelic_set_appname is called, set this to true (default: false)
    logging: false                        # If true, logs all New Relic interactions to the Symfony log (default: false)
    interactor: ~                         # The interactor service that is used. Setting enabled=false will override this value 
    twig: true                            # Allows you to disable twig integration (falls back to class_exists(\Twig_Environment::class))
    exceptions: true                      # If true, sends exceptions to New Relic (default: true)
    deprecations: true                    # If true, reports deprecations to New Relic (default: true)
    instrument: false                     # If true, uses enhanced New Relic RUM instrumentation (see below) (default: false)
    http:
        enabled: true
        using_symfony_cache: false        # Symfony HTTP cache (see below) (default: false)
        transaction_naming: route         # route, controller or service (see below)
        transaction_naming_service: ~     # Transaction naming service (see below)
        ignored_routes: []                # No transaction recorded for this routes
        ignored_paths: []                 # No transaction recorded for this paths
    monolog: 
        enabled: false                    # When enabled, send application's logs to New Relic (default: disabled)
        channels: [app]                   # Channels to listen (default: null). [See Symfony's documentation](http://symfony.com/doc/current/logging/channels_handlers.html#yaml-specification)
        level: error                      # Report only logs higher than this level (see \Psr\Log\LogLevel) (default: error)
        service: app.my_custom_handler    # Define a custom log handler (default: ekino.new_relic.monolog_handler)
    commands: 
        enabled: true                     # If true, logs CLI commands to New Relic as Background jobs (>2.3 only) (default: true)
        ignored_commands: []              # No transaction recorded for this commands (background tasks)

Enhanced RUM instrumentation

The bundle comes with an option for enhanced real user monitoring. Ordinarily the New Relic extension (unless disabled by configuration) automatically adds a tracking code for RUM instrumentation to all HTML responses. Using enhanced RUM instrumentation, the bundle allows you to selectively disable instrumentation on certain requests.

This can be useful if, e.g. you're returning HTML verbatim for an HTML editor.

If enhanced RUM instrumentation is enabled, you can disable instrumentation for a given request by passing along a _instrument request parameter, and setting it to false. This can be done e.g. through the routing configuration.

Transaction naming strategies

The bundle comes with two built-in transaction naming strategies. route and controller, naming the New Relic transaction after the route or controller respectively. However, the bundle supports custom transaction naming strategies through the service configuration option. If you have selected the service configuration option, you must pass the name of your own transaction naming service as the transaction_naming_service configuration option.

The transaction naming service class must implement the Ekino\NewRelicBundle\TransactionNamingStrategy\TransactionNamingStrategyInterface interface. For more information on creating your own services, see the Symfony documentation on Creating/Configuring Services in the Container.

Symfony HTTP Cache

When you are using Symfony's HTTP cache your app/AppCache.php will build up a response with your Edge Side Includes (ESI). This will look like one transaction in New Relic. When you set using_symfony_cache: true will these ESI request be separate transaction which improves the statistics. If you are using some other reverse proxy cache or no cache at all, leave this to false.

If true is required to set the application_name.

Deployment notification

You can use the newrelic:notify-deployment command to send deployment notifications to New Relic. This requires the api_key configuration to be set.

The command has a bunch of options, as displayed in the help data.

$ app/console newrelic:notify-deployment --help
Usage:
 newrelic:notify-deployment [--user[="..."]] [--revision[="..."]] [--changelog[="..."]] [--description[="..."]]

Options:
 --user         The name of the user/process that triggered this deployment
 --revision     A revision number (e.g., git commit SHA)
 --changelog    A list of changes for this deployment
 --description  Text annotation for the deployment — notes for you

The bundle provide a Capifony recipe to automate the deployment notifications (see Resources/recipes/newrelic.rb).

It makes one request per app_name, due roll-up names are not supported by Data REST API.

Interactor services

The config keyekino_new_relic.interactor will accept a service ID to a service implementing NewRelicInteractorInterface. This bundle comes with a few services that may be suitable for you.

Configuration value Description
Ekino\NewRelicBundle\NewRelic\AdaptiveInteractor This is the default interactor. It will check once per request if the NewRelic PHP extension is installed or not. It is a decorator for the NewRelicInteractor
Ekino\NewRelicBundle\NewRelic\NewRelicInteractor This interactor communicates with NewRelic. It is the one decorator that actually does some work.
Ekino\NewRelicBundle\NewRelic\BlackholeInteractor This interactor does nothing.
auto This value will check if the NewRelic PHP extension is installed when you build your container.

Note that if you set ekino_new_relic.enabled: false you will always use the BlackholeInteractor no matter what value used for ekino_new_relic.interactor.

Flow of the Request

  1. A request comes in and the first thing we do is to setApplicationName so that we use the correct license key and name.
  2. The RouterListener might throw a 404 or add routing values to the request.
  3. If no 404 was thrown we setIgnoreTransaction which means that we call NewRelicInteractorInterface::ignoreTransaction() if we have configured to ignore the route.
  4. The Firewall is the next interesting thing that will happen. It could change the controller or throw a 403.
  5. The developer might have configured many more request listeners that will now execute and possibly add stuff to the request.
  6. We will execute setTransactionName to use our TransactionNamingStrategyInterface to set a nice name.

All 6 steps will be executed for a normal request. Exceptions to this is 404 and 403 responses that will be created in step 2 and step 4 respectively. If an exception to these step occurs (I'm not talking about \Exception) you will have the transaction logged with the correct license key but you do not have the proper transaction name. The setTransactionName may have dependencies on data set by other listeners that is why it has such low priority.

More Repositories

1

EkinoWordpressBundle

Integrate Symfony with WordPress and WordPress with Symfony
PHP
309
star
2

phpstan-banned-code

Detect banned code through PHPStan
PHP
194
star
3

veggies

✨ 🚀 Veggies is an awesome cucumberjs library for API/CLI testing. Great for testing APIs built upon Express, Koa, HAPI, Loopback and others. It's also the perfect companion for testing CLI applications built with commander, meow & Co.
JavaScript
89
star
4

EkinoDrupalBundle

Integrate Symfony2 with Drupal 7 and vice-versa.
PHP
72
star
5

php-mirroring

[deprecated] Packagist and Github mirroring
PHP
55
star
6

docker-buildbox

Docker images for GitLab CI's jobs
Dockerfile
55
star
7

ekino-wordpress-symfony

PHP
43
star
8

docker-neo4j-cluster

🐳 Up & Running Neo4j cluster in no time
Shell
41
star
9

php-hal-client

HalClient is a lightweight PHP library to consume HAL resources.
PHP
33
star
10

php-metric

This library provides base classes to collect and publish metrics.
PHP
33
star
11

drupal-debug

Alternative Kernel for Drupal 8 to improve the Developer eXperience during the development process.
PHP
31
star
12

docker-wiremock

🐳 WireMock is a flexible library for stubbing and mocking web services
25
star
13

jcv

JSON Content Validator (JCV) allows you to compare JSON contents with embedded validation.
Kotlin
21
star
14

docker-monitoring-stack

🐳 Full monitoring stack : Collectd > InfluxDB > Grafana
Shell
19
star
15

node-logger

A Lightweight logger that combines debug namespacing capabilities with winston levels and multioutput
JavaScript
18
star
16

EkinoMetricBundle

Integrate Ekino PHP Metric into Symfony2
PHP
14
star
17

ek-winjs-kinect

Kinect V2 project for javascript web application
PowerShell
13
star
18

webpack-cheatsheet

🔷 Ekino Webpack Cheat Sheet Project
JavaScript
13
star
19

golisten

Listen and notify on files change
Go
9
star
20

spring-boot-starter-errors

Opiniated Spring Boot starter that handles common exceptions and returns them in a standardize json format
Kotlin
9
star
21

ekino-tools-version

Scala
8
star
22

node-config

Lightweight config module based on yaml that supports overrides based on environment (prod, dev ..) and environment values
JavaScript
8
star
23

jcv-idea-plugin

IntelliJ IDEA plugin for an enhanced coding experience on JCV based projects.
Kotlin
7
star
24

git-hooks

git hooks used in our PHP team
Shell
7
star
25

wiremock-unused-stubs-junit

Kotlin
7
star
26

devbox

Shell
6
star
27

jcv-db

JSON Content Validator for Database (JCV-DB) allow you to compare database contents against a JSON with JCV validators.
Kotlin
6
star
28

ekino_drupal_symfony2

A drupal module which integrates the EkinoDrupalBundle
PHP
6
star
29

knex-extra

A set of helpers to be used with knexjs
TypeScript
6
star
30

hands-on-react

hands-on-react
CSS
6
star
31

golang-hands-on

Go
5
star
32

rendr

A SSR toolkit for Headless CMS and more.
PHP
5
star
33

hibernate-crypto-types

Provides new hibernate column types to encrypt your column data before being stored in your database
Kotlin
5
star
34

docker-elk-stack

🐳 A decoupled ELK stack using docker : Elasticsearch Logstash on one side / Kibana on the other
Shell
5
star
35

gradle-quality-plugin

Quality plugin applying some configuration for your builds (checkstyle, jacoco, sonarqube)
Kotlin
5
star
36

wp-oam-renderer

Allows and renders OAM (Adobe Edge Animate) files in your Wordpress posts
PHP
5
star
37

gradle-java-plugin

Java plugin applying some configuration for your builds (mavenPublish, testSets, etc ...)
Kotlin
5
star
38

node-api-toolkit

A set of Node.js modules to ease Node.js API development
TypeScript
5
star
39

oh-my-mustache

Kotlin
4
star
40

sonata

PHP
4
star
41

kotlin-quality-plugin

Gradle quality plugin for kotlin projects
Kotlin
4
star
42

EkinoDataProtectionBundle

A Symfony bundle to protect data through encryption
PHP
4
star
43

docker-newman

🐳 Docker image to easily start Newman, the command-line collection runner for Postman
3
star
44

godim

Golang Dependency Injection Management
Go
3
star
45

jcv-examples

Examples of the JCV library usages (see: https://github.com/ekino/jcv )
Kotlin
3
star
46

docker-symfony-wordpress

PHP
3
star
47

phpstan-sonata

PHP
3
star
48

docker-gcsfuse

Docker image that contains gcsfuse. Can be used as a side container to mount a GCS bucket
Dockerfile
3
star
49

NewsFakeToken

An NFT for tracing Fake News
TypeScript
3
star
50

docker-compose-elk

🐳 Up&Running elasticsearch+logstash+kibana application (official images)
Shell
3
star
51

test-end2end-jmeter

JavaScript
2
star
52

webpack-plugin-assets-to-map

Create a Json or TOML or YAML file with webpack chunks
JavaScript
2
star
53

docker-rp-lb

🐳 Reverse Proxies and Load Balancers inside containers
Shell
2
star
54

behat-helpers

Helpers for Behat
PHP
2
star
55

starfight

Java
2
star
56

gradle-docker-plugin

Docker plugin applying some configuration for your builds
Kotlin
2
star
57

JTrans4mers

JTrans4mers : A Java tool to easily map an Object to an Enum.
Java
1
star
58

docker-nginx-brotli

Provide a nginx with brotli support
Python
1
star
59

expresso

TypeScript
1
star
60

post-3-nlp

The repository for an Ekino blog post on NLP
Jupyter Notebook
1
star
61

docker-chefdk

🐳 Docker image with ChefDK
Vim Script
1
star
62

spring-reactive-perf

HTML
1
star
63

EkinoTinyPngSonataMediaBundle

A Symfony bundle to optimize sonata media images through tinyPNG API
PHP
1
star
64

terraform-provider-greseller

Terraform provider to add Google Reseller resources
Go
1
star
65

smuggler

A simple interface to manipulate Nock HTTP mocks.
TypeScript
1
star