Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes the errors while running the project for Lumen to allow compatibility for Lumen as well #51

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Collectors/EventsCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ abstract class EventsCollector extends SegmentCollector
* @var \Illuminate\Foundation\Application
*/
protected $app;
viezel marked this conversation as resolved.
Show resolved Hide resolved

public function __construct(Application $app)
public function __construct()
{
$this->app = $app;
$this->app = app();

$this->registerEventListeners();
}
Expand Down
12 changes: 9 additions & 3 deletions src/Collectors/FrameworkCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ public function registerEventListeners(): void
$startTime = defined('LARAVEL_START') ? LARAVEL_START : microtime(true);
$this->addSegment('laravel boot', $startTime);

$this->app->booted(function () {
$this->endSegment('laravel boot');
});
if($this->app instanceof \Laravel\Lumen\Application){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot refer to this->app due to you just deleted the proptery

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes apologies for that. I have added it to the base class.(EventsCollector)

$this->endSegment('laravel boot');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you test this logic? It seems incorrect as you have two endsection and incorrect type.

else{
$this->app->booted(function () {
$this->endSegment('laravel boot');
});
}

}
}
11 changes: 8 additions & 3 deletions src/Collectors/RouteCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ class RouteCollector extends EventsCollector
{
public function registerEventListeners(): void
{
$this->app->booted(function () {
$this->addSegment('route matching');
});
if($this->app instanceof \Laravel\Lumen\Application){
$this->endSegment('laravel boot');
}
else{
$this->app->booted(function () {
$this->endSegment('laravel boot');
});
}

// Time between route resolution and request handled
$this->app['events']->listen(RouteMatched::class, function ($event) {
Expand Down
4 changes: 3 additions & 1 deletion src/Submission/APISegmentSubmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Napp\Xray\Submission;

use Aws\XRay\XRayClient;
use Carbon\Carbon;
use Pkerrigan\Xray\Segment;
use Pkerrigan\Xray\Submission\SegmentSubmitter;

Expand All @@ -17,8 +18,9 @@ class APISegmentSubmitter implements SegmentSubmitter

public function __construct()
{

$config = config('xray.aws');
$config['credentials']['expires'] = now()->addDay()->unix();
$config['credentials']['expires'] = Carbon::now()->addDay()->unix();
$this->client = new XRayClient($config);
}

Expand Down