-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from scoutapp/instrumentation-for-artisan-com…
…mands Added instrumentation for artisan console commands
- Loading branch information
Showing
17 changed files
with
458 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,9 +129,7 @@ jobs: | |
uses: octokit/[email protected] | ||
id: get_latest_ext_release | ||
with: | ||
route: GET /repos/{owner}/{repo}/releases/latest | ||
owner: scoutapp | ||
repo: scout-apm-php-ext | ||
route: GET /repos/scoutapp/scout-apm-php-ext/releases/latest | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: "Install scoutapm extension" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Scoutapm\Laravel\Console; | ||
|
||
use Exception; | ||
use Illuminate\Console\Events\CommandFinished; | ||
use Illuminate\Console\Events\CommandStarting; | ||
use Scoutapm\Events\Span\SpanReference; | ||
use Scoutapm\Events\Tag\Tag; | ||
use Scoutapm\ScoutApmAgent; | ||
|
||
use function implode; | ||
use function sprintf; | ||
|
||
final class ConsoleListener | ||
{ | ||
/** @var ScoutApmAgent */ | ||
private $agent; | ||
/** @var list<string> */ | ||
private $argv; | ||
|
||
/** @param list<string> $argv */ | ||
public function __construct(ScoutApmAgent $agent, array $argv) | ||
{ | ||
$this->agent = $agent; | ||
$this->argv = $argv; | ||
} | ||
|
||
/** @throws Exception */ | ||
public function startSpanForCommand(CommandStarting $commandStartingEvent): void | ||
{ | ||
if ($commandStartingEvent->command === null) { | ||
return; | ||
} | ||
|
||
$this->agent->startNewRequest(); | ||
|
||
$this->agent->addContext(Tag::TAG_ARGUMENTS, implode(' ', $this->argv)); | ||
|
||
/** @noinspection UnusedFunctionResultInspection */ | ||
$this->agent->startSpan(sprintf( | ||
'%s/artisan/%s', | ||
SpanReference::INSTRUMENT_JOB, | ||
$commandStartingEvent->command | ||
)); | ||
} | ||
|
||
/** @throws Exception */ | ||
public function stopSpanForCommand(CommandFinished $commandFinishedEvent): void | ||
{ | ||
if ($commandFinishedEvent->command === null) { | ||
return; | ||
} | ||
|
||
$this->agent->stopSpan(); | ||
$this->agent->connect(); | ||
$this->agent->send(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.