Skip to content

Commit 523d4cb

Browse files
committed
feat: allows the user to pass a custom zipkin URL.
1 parent 2b01737 commit 523d4cb

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,19 @@ curl http://localhost:8081
4949
1. This starts a trace in the frontend (http://localhost:8081/)
5050
2. Continues the trace and calls the backend (http://localhost:9000)
5151
3. Next, you can view traces that went through the backend via http://localhost:9411/?serviceName=frontend.
52+
53+
54+
## Running example with a non-docker zipkin:
55+
56+
If you need to pass the zipkin endpoint, just pass the reporter
57+
url as `HTTP_REPORTER_URL` env variable.
58+
59+
```bash
60+
61+
# In terminal 1:
62+
HTTP_REPORTER_URL=http://myzipkin:9411/api/v2/span composer run-frontend
63+
64+
# In terminal 2
65+
HTTP_REPORTER_URL=http://myzipkin:9411/api/v2/span composer run-backend
66+
67+
```

backend.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
use Zipkin\Timestamp;
43
use Zipkin\Propagation\Map;
54

65
require_once __DIR__ . '/vendor/autoload.php';

functions.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<?php
22

3-
use GuzzleHttp\Client;
43
use Zipkin\Endpoint;
54
use Zipkin\Samplers\BinarySampler;
65
use Zipkin\TracingBuilder;
76

87
function create_tracing($endpointName, $ipv4)
98
{
9+
$httpReporterURL = getenv('HTTP_REPORTER_URL');
10+
if ($httpReporterURL === false) {
11+
$httpReporterURL = 'http://localhost:9411/api/v2/spans';
12+
}
13+
1014
$endpoint = Endpoint::create($endpointName, $ipv4, null, 2555);
1115

1216
/* Do not copy this logger into production.
@@ -15,7 +19,10 @@ function create_tracing($endpointName, $ipv4)
1519
$logger = new \Monolog\Logger('log');
1620
$logger->pushHandler(new \Monolog\Handler\ErrorLogHandler());
1721

18-
$reporter = new Zipkin\Reporters\Http(\Zipkin\Reporters\Http\CurlFactory::create());
22+
$reporter = new Zipkin\Reporters\Http(
23+
\Zipkin\Reporters\Http\CurlFactory::create(),
24+
['endpoint_url' => $httpReporterURL]
25+
);
1926
$sampler = BinarySampler::createAsAlwaysSample();
2027
$tracing = TracingBuilder::create()
2128
->havingLocalEndpoint($endpoint)

0 commit comments

Comments
 (0)