Skip to content

Commit bf9a6fc

Browse files
author
Patrick Leckey
committed
updated readme with observers
1 parent e622c98 commit bf9a6fc

File tree

1 file changed

+53
-9
lines changed

1 file changed

+53
-9
lines changed

README.md

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
#Laravel NewRelic package
22

3-
## Laravel 5
4-
5-
Please see the following issue, open with NewRelic:
6-
7-
[https://discuss.newrelic.com/t/php-agent-4-19-0-disabled-3rd-party-service-provider-incorrectly/1666](https://discuss.newrelic.com/t/php-agent-4-19-0-disabled-3rd-party-service-provider-incorrectly/16667)
8-
93
### Note
104

115
**`master` is currently undergoing updates to support Laravel 5**
@@ -35,7 +29,7 @@ the following line to the end:
3529

3630
Optionally, locate the `aliases` key and add the following line:
3731

38-
'Newrelic' => 'Intouch\LaravelNewrelic\Facades\Newrelic',
32+
'Newrelic' => 'Intouch\LaravelNewrelic\Facades\Newrelic',
3933

4034
Finally, publish the default configuration (it will end up in `config/newrelic.php`):
4135

@@ -46,13 +40,63 @@ Finally, publish the default configuration (it will end up in `config/newrelic.p
4640
Once the configuration from the package if published, see `config/newrelic.php` for configuration options and
4741
descriptions.
4842

43+
### Eloquent Model Observers
44+
45+
There are two observer classes for monitoring your Eloquent models, the `NewrelicCountingObserver` and the
46+
`NewrelicTimingObserver`. As their names suggest, one counts the number of times observable model events happen and the
47+
other gathers their timings (in milliseconds). These recorded metrics will show up in your NewRelic Custom Metrics.
48+
49+
The `NewrelicCountingObserver` can be used for any observable model events, including your custom events. The
50+
`NewrelicTimingObserver` currently only supports the built-in Eloquent observable events (see
51+
[Model Events](http://laravel.com/docs/5.0/eloquent#model-events) in the Laravel documentation).
52+
53+
Using the observers is simple - wherever you choose to register your model observers, simply add:
54+
55+
User::observe(new \Intouch\LaravelNewrelic\Observers\NewrelicTimingObserver() );
56+
User::observe(new \Intouch\LaravelNewrelic\Observers\NewrelicCountingObserver() );
57+
58+
... assuming you want to observe the `User` model.
59+
60+
Both observers take two optional parameters to their constructors: `$name` and `$care`. `$name` is the name you want
61+
to give to your custom metric, and if unset will default to the class name of the model object it is observing. If you
62+
want to change the `$care` array without changing the naming, simply pass `null` as the first constructor argument.
63+
64+
`$care` is an array of event names you want to care about. This differs slightly between the ___Counting___ and
65+
___Timing___ observers. For the ___Counting___ observer, any event can be counted independently. For the ___Timing___
66+
observer, it uses the difference in time between `saving` and `saved` to submit the metric, so only the after-operation
67+
events can be observed: `created`, `saved`, `updated`, `deleted`, `restored`. This is also why custom observable events
68+
are not supported for the ___Timing___ observer (yet ... working on it, we're happy to take PRs).
69+
70+
Per NewRelic's "best practice" suggestions, all metric names are prefaced with 'Custom/'. The ___Counting___ observer
71+
also adds 'Counts/' to the name, while the ___Timing___ observer adds 'Timing/' to the name. Both observers append
72+
the event name to the end of the metric name. Take as an example, using the ___Counting___ observer on the `User` model
73+
monitoring the `created` event - the name would be: `Custom/Counts/App/User/created` (where `App/User` is the namespaced
74+
class named of the observed model, or will be whatever you set in `$name` if supplied).
75+
76+
**NOTE:** To use the observers, the `Newrelic` Facade must be loaded in your application configuration, not just the
77+
Service Provider.
78+
79+
It is safe to run these observers in integration tests or interactive test environments as long as
80+
`newrelic.throw_if_not_installed` is set to `false`. Then if the NewRelic PHP Agent is not installed in that
81+
environment, the custom metrics will simply not be recorded.
82+
83+
The default events both observers care about are: `created`, `saved`, `updated`, `deleted`, `restored`.
84+
4985
### Basic Use
5086

51-
The registered Service Provider includes a Facade to the [Intouch/Newrelic](http://github.com/In-Touch/newrelic) class.
87+
This package includes a Facade to the [Intouch/Newrelic](http://github.com/In-Touch/newrelic) class.
5288
Any of its methods may be accessed as any other Facade is accessed, for example:
5389

54-
App::before( function() {
90+
App::after( function() {
5591
Newrelic::setAppName( 'MyApp' );
5692
} );
5793

5894
... would set the NewRelic App Name to 'MyApp'
95+
96+
### Issues
97+
98+
Before opening an issues for data not reporting in the format you have configured, please check your NewRelic PHP Agent
99+
logs and please see:
100+
[https://discuss.newrelic.com/t/php-agent-4-19-0-disabled-3rd-party-service-provider-incorrectly/1666](https://discuss.newrelic.com/t/php-agent-4-19-0-disabled-3rd-party-service-provider-incorrectly/16667)
101+
102+
If that hasn't cleared things up, please open an issue here or send us a PR.

0 commit comments

Comments
 (0)