Skip to content

Commit 8e06b90

Browse files
author
Patrick Leckey
committed
fixed slashes in metric names
1 parent b3138d0 commit 8e06b90

File tree

4 files changed

+35
-24
lines changed

4 files changed

+35
-24
lines changed

README.md

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
#Laravel NewRelic package
2-
3-
### Note
4-
5-
**`master` is currently undergoing updates to support Laravel 5**
6-
7-
For **Laravel 4.1/4.2** support, please use the latest 1.1.x tag.
8-
For **Laravel 4.0** support, please use the latest 1.0.x tag. Laravel 4.0 support is deprecated and will not be
9-
updated.
1+
# Laravel 5 NewRelic Service Provider
2+
*see below for Laravel 4.x support*
103

114
### Installation
125

136
Using `composer`, run:
147

15-
composer require intouch/laravel-newrelic:dev-master
8+
composer require intouch/laravel-newrelic:"~2.0"
169

1710
Or add `intouch/laravel-newrelic` to your composer requirements:
1811

1912
"require": {
20-
"intouch/laravel-newrelic": "dev-master"
13+
"intouch/laravel-newrelic": "~2.0"
2114
}
2215

2316
... and then run `composer install`
@@ -67,27 +60,34 @@ Both observers take two optional parameters to their constructors: `$name` and `
6760
to give to your custom metric, and if unset will default to the class name of the model object it is observing. If you
6861
want to change the `$care` array without changing the naming, simply pass `null` as the first constructor argument.
6962

70-
`$care` is an array of event names you want to care about. This differs slightly between the ___Counting___ and
71-
___Timing___ observers. For the ___Counting___ observer, any event can be counted independently. For the ___Timing___
63+
`$care` is an array of event names you want to care about. This differs slightly between the *Counting* and
64+
*Timing* observers. For the *Counting* observer, any event can be counted independently. For the *Timing*
7265
observer, it uses the difference in time between `saving` and `saved` to submit the metric, so only the after-operation
7366
events can be observed: `created`, `saved`, `updated`, `deleted`, `restored`. This is also why custom observable events
74-
are not supported for the ___Timing___ observer (yet ... working on it, we're happy to take PRs).
67+
are not supported for the *Timing* observer (yet ... working on it, we're happy to take PRs).
7568

76-
Per NewRelic's "best practice" suggestions, all metric names are prefaced with 'Custom/'. The ___Counting___ observer
77-
also adds 'Counts/' to the name, while the ___Timing___ observer adds 'Timing/' to the name. Both observers append
78-
the event name to the end of the metric name. Take as an example, using the ___Counting___ observer on the `User` model
69+
Per NewRelic's "best practice" suggestions, all metric names are prefaced with 'Custom/'. The *Counting* observer
70+
also adds 'Counts/' to the name, while the *Timing* observer adds 'Timing/' to the name. Both observers append
71+
the event name to the end of the metric name. Take as an example, using the *Counting* observer on the `User` model
7972
monitoring the `created` event - the name would be: `Custom/Counts/App/User/created` (where `App/User` is the namespaced
80-
class named of the observed model, or will be whatever you set in `$name` if supplied).
81-
82-
**NOTE:** To use the observers, the `Newrelic` Facade must be loaded in your application configuration, not just the
83-
Service Provider.
73+
class name of the observed model with slashes reversed for NewRelic metric paths, or will be whatever you set in `$name`
74+
if supplied).
8475

8576
It is safe to run these observers in integration tests or interactive test environments as long as
8677
`newrelic.throw_if_not_installed` is set to `false`. Then if the NewRelic PHP Agent is not installed in that
87-
environment, the custom metrics will simply not be recorded.
78+
environment, the custom metrics will simply not be recorded. If the NewRelic PHP Agent is installed in that
79+
environment, the metrics will be recorded.
8880

8981
The default events both observers care about are: `created`, `saved`, `updated`, `deleted`, `restored`.
9082

83+
**NOTE:** To use the observers, the `Newrelic` Facade must be loaded in your application configuration, not just the
84+
Service Provider.
85+
86+
**NOTE:** NewRelic restricts the total number of custom metrics you can have to 2000, and recommends less than 1000.
87+
88+
#### Example Custom Metrics Dashboard
89+
![dashboard](dashboard.png)
90+
9191
### Basic Use
9292

9393
This package includes a Facade to the [Intouch/Newrelic](http://github.com/In-Touch/newrelic) class.
@@ -99,6 +99,16 @@ Any of its methods may be accessed as any other Facade is accessed, for example:
9999

100100
... would set the NewRelic App Name to 'MyApp'
101101

102+
### Laravel 4.x Support
103+
104+
| Laravel Version | Package Tag | Supported |
105+
|-----------------|-------------|-----------|
106+
| 4.2.x | [1.1.5](https://github.com/In-Touch/laravel-newrelic/tree/1.1.5) | yes |
107+
| 4.1.x | [1.1.5](https://github.com/In-Touch/laravel-newrelic/tree/1.1.5) | no |
108+
| 4.0.x | [1.0.4](https://github.com/In-Touch/laravel-newrelic/tree/1.0.4) | no |
109+
*we will review PRs for unsupported versions, but we don't use those versions in production ourselves so we aren't
110+
testing / working on that*
111+
102112
### Issues
103113

104114
Before opening an issues for data not reporting in the format you have configured, please check your NewRelic PHP Agent

dashboard.png

32.5 KB
Loading

src/Intouch/LaravelNewrelic/Observers/NewrelicCountingObserver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public function __call( $event, array $args )
5858
}
5959

6060
$model = array_shift( $args );
61-
$name = 'Custom/Counts/' . ltrim( $this->name ?: get_class( $model ), '/' ) . '/' . $event;
61+
$metric = trim( str_replace( '\\', '/', $this->name ?: get_class( $model ) ), '/' );
62+
$name = 'Custom/Counts/' . $metric . '/' . $event;
6263

6364
/**
6465
* NewRelic assumes custom metrics to be in milliseconds, so 4 gets interpreted as

src/Intouch/LaravelNewrelic/Observers/NewrelicTimingObserver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function __construct( $name = null, array $care = [ ] )
6868

6969
protected function getMetricName( $model, $event )
7070
{
71-
return 'Custom/Timing/' . ltrim( $this->name ?: get_class( $model ), '/' ) . '/' . $event;
71+
return 'Custom/Timing/' . trim( str_replace( '\\', '/', $this->name ?: get_class( $model ) ), '/' ) . '/' . $event;
7272
}
7373

7474
/**

0 commit comments

Comments
 (0)