Skip to content

Commit b72d9d3

Browse files
author
Mads Møller
authored
Merge pull request Napp#4 from trybeapp/daemon-pr
Add daemon submitter
2 parents 47e3a8d + 179bf72 commit b72d9d3

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,24 @@ The above results in:
123123

124124
![XML-example](https://raw.githubusercontent.com/Napp/xray-laravel/master/docs/xray-xml-example.png)
125125

126+
## Daemon support
127+
128+
The X-Ray daemon is automatically run in a Lambda environment. Use this over the default `Napp\Xray\Submission\APISegmentSubmitter` to relay requests to Amazon X-Ray.
129+
130+
Firstly, publish the X-Ray config and then update the submitter in `config/xray.php` to `\Napp\Xray\Submission\DaemonSegmentSubmitter::class`
131+
132+
```console
133+
php artisan vendor:publish --tag=xray-config
134+
```
135+
136+
```php
137+
# config/xray.php
138+
...
139+
'submitter' => \Napp\Xray\Submission\DaemonSegmentSubmitter::class,
140+
...
141+
```
142+
143+
The daemon submitter will pick up the `_AWS_XRAY_DAEMON_ADDRESS` `_AWS_XRAY_DAEMON_PORT`. These environment variables are injected for you if using a service like [Laravel Vapor](https://vapor.laravel.com/)
126144

127145
## Disable Tracer
128146

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Napp\Xray\Submission;
6+
7+
use Pkerrigan\Xray\Segment;
8+
use Pkerrigan\Xray\Submission\DaemonSegmentSubmitter as SubmissionDaemonSegmentSubmitter;
9+
use Pkerrigan\Xray\Submission\SegmentSubmitter;
10+
11+
class DaemonSegmentSubmitter implements SegmentSubmitter
12+
{
13+
/**
14+
* @var SubmissionDaemonSegmentSubmitter
15+
*/
16+
private $submitter;
17+
18+
/**
19+
* @var string
20+
*/
21+
private $host;
22+
23+
/**
24+
* @var int
25+
*/
26+
private $port;
27+
28+
public function __construct()
29+
{
30+
$this->host = env('_AWS_XRAY_DAEMON_ADDRESS');
31+
$this->port = (int) env('_AWS_XRAY_DAEMON_PORT');
32+
}
33+
34+
/**
35+
* Get or create the Daemon submitter.
36+
*
37+
* @return SubmissionDaemonSegmentSubmitter
38+
*/
39+
protected function submitter(): SubmissionDaemonSegmentSubmitter
40+
{
41+
if (is_null($this->submitter)) {
42+
$this->submitter = new SubmissionDaemonSegmentSubmitter(
43+
$this->host,
44+
$this->port
45+
);
46+
}
47+
48+
return $this->submitter;
49+
}
50+
51+
/**
52+
* @param Segment $segment
53+
* @return void
54+
*/
55+
public function submitSegment(Segment $segment)
56+
{
57+
$this->submitter()->submitSegment($segment);
58+
}
59+
}

0 commit comments

Comments
 (0)