Skip to content

Commit cd80cb8

Browse files
committed
0.0.1
0 parents  commit cd80cb8

File tree

10 files changed

+770
-0
lines changed

10 files changed

+770
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea
2+
*.iml
3+
4+
composer.phar
5+
vendor/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Vasily Ostanin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Newrelic.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace bazilio\yii\newrelic;
4+
5+
require_once __DIR__ . '/vendor/autoload.php';
6+
7+
use bazilio\yii\newrelic\handlers\BaseHandler;
8+
use bazilio\yii\newrelic\handlers\ConsoleHandler;
9+
use bazilio\yii\newrelic\handlers\WebHandler;
10+
use NewRelic\NewRelic as Agent;
11+
use yii\base\BootstrapInterface;
12+
use yii\base\Component;
13+
14+
/**
15+
* Class Newrelic
16+
* @package bazilio\yii\newrelic
17+
*/
18+
class Newrelic extends Component implements BootstrapInterface
19+
{
20+
/**
21+
* @var \NewRelic\NewRelic
22+
*/
23+
public $agent;
24+
25+
/**
26+
* @var string App name
27+
*/
28+
public $name;
29+
30+
/**
31+
* @var string Licence key
32+
*/
33+
public $licence = 'newrelic.license';
34+
35+
/**
36+
* @var string handlers\Handler
37+
*/
38+
public $handler;
39+
40+
/**
41+
* @var bool Enable view instrumentation with newrelic scripts
42+
*/
43+
public $enableEndUser = true;
44+
45+
/**
46+
* @inheritdoc
47+
*/
48+
public function bootstrap($app)
49+
{
50+
if ($this->handler) {
51+
$handler = new $this->handler(['newrelic' => $this]);
52+
} elseif ($app instanceof \yii\web\Application) {
53+
$handler = new WebHandler(['newrelic' => $this]);
54+
} elseif ($app instanceof \yii\console\Application) {
55+
$handler = new ConsoleHandler(['newrelic' => $this]);
56+
} else {
57+
$handler = new BaseHandler(['newrelic' => $this]);
58+
}
59+
60+
$handler->bootstrap($app);
61+
}
62+
63+
public function init()
64+
{
65+
parent::init();
66+
67+
if (Agent::isLoaded()) {
68+
$this->name = $this->name ? $this->name : \Yii::$app->name;
69+
$this->agent = new Agent();
70+
$this->agent->setAppname($this->name, $this->licence);
71+
}
72+
}
73+
}

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Newrelic instrumentation for Yii 2
2+
==================================
3+
4+
This extension describes routes, action params and instruments views with newrelic end user monitoring scripts.
5+
Supports console and web applications.
6+
7+
For license information check the [LICENSE](LICENSE)-file.
8+
9+
Requirements
10+
------------
11+
12+
Works with newrelic agent with version >=3.0
13+
14+
Installation
15+
------------
16+
17+
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
18+
19+
Either run
20+
21+
```
22+
php composer.phar require --prefer-dist bazilio/yii2-newrelic
23+
```
24+
25+
or add
26+
27+
```json
28+
"bazilio/yii2-newrelic": "~0.0.1"
29+
```
30+
31+
to the require section of your composer.json.
32+
33+
34+
Configuration
35+
-------------
36+
37+
To use this extension, you have to configure your components & bootstrap section your application configuration:
38+
39+
```php
40+
return [
41+
'bootstrap' => ['newrelic'],
42+
'components' => [
43+
// ...
44+
'newrelic' => [
45+
'class' => 'bazilio\yii\newrelic\Newrelic',
46+
'name' => 'My App Frontend', // optional, uses Yii::$app->name by default
47+
'handler' => 'class/name', // optional, your custom handler
48+
'licence' => '...' // optional
49+
]
50+
],
51+
];
52+
```

composer.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "bazilio/yii2-newrelic",
3+
"description": "Newrelic integration for Yii2",
4+
"type": "yii2-extension",
5+
"license": "MIT",
6+
"keywords": ["yii2", "newrelic", "debug", "monitoring"],
7+
"authors": [
8+
{
9+
"name": "Vasily Ostanin",
10+
"email": "[email protected]"
11+
}
12+
],
13+
"require": {
14+
"sobanvuex/php-newrelic": "1.*",
15+
"php": ">=5.4.0",
16+
"yiisoft/yii2": "*"
17+
},
18+
"autoload": {
19+
"psr-4": {
20+
"bazilio\\yii\\newrelic\\": ""
21+
}
22+
}
23+
24+
}

0 commit comments

Comments
 (0)