Skip to content

Commit

Permalink
feat: add Laravel runtime version reporting
Browse files Browse the repository at this point in the history
Uses new hook in Configuration class of bugsnag-php 3.17.0 to append the Laravel/Lumen application version
to device data to make it reportable.
  • Loading branch information
tomlongridge committed May 29, 2019
1 parent aeae4c7 commit 5aed502
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

## TBD

* Add Laravel/Lumen version string to report and session payloads (device.runtimeVersions)
[#352](https://github.com/bugsnag/bugsnag-laravel/pull/352)

## 2.15.2 (2019-01-23)

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"php": ">=5.5",
"illuminate/contracts": "^5.0",
"illuminate/support": "^5.0",
"bugsnag/bugsnag": "^3.15.0",
"bugsnag/bugsnag": "^3.17.0",
"bugsnag/bugsnag-psr-logger": "^1.4",
"monolog/monolog": "^1.12"
},
Expand Down
19 changes: 19 additions & 0 deletions src/BugsnagServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ public function register()

$client->setReleaseStage(isset($config['release_stage']) ? $config['release_stage'] : $app->environment());
$client->setHostname(isset($config['hostname']) ? $config['hostname'] : null);
$client->getConfig()->mergeDeviceData(['runtimeVersions' => $this->getRuntimeVersion()]);

$client->setFallbackType($app->runningInConsole() ? 'Console' : 'HTTP');
$client->setAppType(isset($config['app_type']) ? $config['app_type'] : null);
Expand Down Expand Up @@ -399,6 +400,24 @@ protected function setupSessionTracking(Client $client, $endpoint, $events)
$sessionTracker->setStorageFunction($genericStorage);
}

/**
* Returns the framework name and version to add to the device data.
*
* Attempts to parse a semantic framework version from $app or else return the full version string.
* e.g. Lumin: "Lumen (x.x.x) (Laravel Components y.y.*)" => "x.x.x"
*
* @return array
*/
protected function getRuntimeVersion() {

$version = $this->app->version();
if (preg_match('/(\d+\.\d+\.\d+)/', $version, $versionMatches)) {
$version = $versionMatches[0];
}
return [ ($this->app instanceof LumenApplication ? 'lumen' : 'laravel' ) => $version ];

}

/**
* Get the services provided by the provider.
*
Expand Down

0 comments on commit 5aed502

Please sign in to comment.