This repository has been archived by the owner on Nov 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
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 #46 from philkra/development
Development
- Loading branch information
Showing
6 changed files
with
154 additions
and
19 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
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,52 @@ | ||
<?php | ||
|
||
namespace PhilKra\ElasticApmLaravel\Apm; | ||
|
||
|
||
use PhilKra\Helper\Timer; | ||
|
||
/* | ||
* Eventually this class could be a proxy for a Span provided by the | ||
* Elastic APM package. | ||
*/ | ||
class Span | ||
{ | ||
/** @var Timer */ | ||
private $timer; | ||
/** @var SpanCollection */ | ||
private $collection; | ||
|
||
private $name = 'Transaction Span'; | ||
private $type = 'app.span'; | ||
|
||
private $start; | ||
|
||
public function __construct(Timer $timer, SpanCollection $collection) | ||
{ | ||
$this->timer = $timer; | ||
$this->collection = $collection; | ||
|
||
$this->start = $timer->getElapsedInMilliseconds(); | ||
} | ||
|
||
public function setName(string $name) | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
public function setType(string $type) | ||
{ | ||
$this->type = $type; | ||
} | ||
|
||
public function end() | ||
{ | ||
$duration = round($this->timer->getElapsedInMilliseconds() - $this->start, 3); | ||
$this->collection->push([ | ||
'name' => $this->name, | ||
'type' => $this->type, | ||
'start' => $this->start, | ||
'duration' => $duration, | ||
]); | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
namespace PhilKra\ElasticApmLaravel\Apm; | ||
|
||
|
||
use Illuminate\Support\Collection; | ||
|
||
/* | ||
* Creating an extension of the Collection class let's us establish | ||
* a named dependency which can be more easily modified in the future. | ||
*/ | ||
class SpanCollection extends Collection | ||
{ | ||
|
||
} |
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,39 @@ | ||
<?php | ||
|
||
namespace PhilKra\ElasticApmLaravel\Apm; | ||
|
||
|
||
use PhilKra\Helper\Timer; | ||
|
||
/* | ||
* Eventually this class could be a proxy for a Transaction provided by the | ||
* Elastic APM package. | ||
*/ | ||
class Transaction | ||
{ | ||
/** @var SpanCollection */ | ||
private $collection; | ||
/** @var Timer */ | ||
private $timer; | ||
|
||
public function __construct(SpanCollection $collection, Timer $timer) | ||
{ | ||
$this->collection = $collection; | ||
$this->timer = $timer; | ||
} | ||
|
||
public function startNewSpan(string $name = null, string $type = null): Span | ||
{ | ||
$span = new Span($this->timer, $this->collection); | ||
|
||
if (null !== $name) { | ||
$span->setName($name); | ||
} | ||
|
||
if (null !== $type) { | ||
$span->setType($type); | ||
} | ||
|
||
return $span; | ||
} | ||
} |
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