3535 */
3636class ZipkinExporter implements ExporterInterface
3737{
38- /**
39- * @var string
40- */
41- private $ name ;
42-
4338 /**
4439 * @var string
4540 */
@@ -55,20 +50,56 @@ class ZipkinExporter implements ExporterInterface
5550 */
5651 private $ url ;
5752
53+ /**
54+ * @var array
55+ */
56+ private $ localEndpoint ;
57+
5858 /**
5959 * Create a new ZipkinExporter
6060 *
6161 * @param string $name The name of this application
6262 * @param string $host The hostname of the Zipkin server
6363 * @param int $port The port of the Zipkin server
64- * @param string $endpoint (optional) The path for the span reporting endpoint. **Defaults to** `/api/v2/spans`
64+ * @param string $endpoint (optional) The path for the span reporting
65+ * endpoint. **Defaults to** `/api/v2/spans`
66+ * @param array $server (optoinal) The server array to search for the
67+ * SERVER_PORT. **Defaults to** $_SERVER
6568 */
66- public function __construct ($ name , $ host , $ port , $ endpoint = '/api/v2/spans ' )
69+ public function __construct ($ name , $ host , $ port , $ endpoint = '/api/v2/spans ' , $ server = null )
6770 {
68- $ this -> name = $ name ;
71+ $ server = $ server ?: $ _SERVER ;
6972 $ this ->host = $ host ;
7073 $ this ->port = $ port ;
7174 $ this ->url = "http:// $ {host}: $ {port}$ {endpoint}" ;
75+ $ this ->localEndpoint = [
76+ 'serviceName ' => $ name
77+ ];
78+ if (array_key_exists ('SERVER_PORT ' , $ server )) {
79+ $ this ->localEndpoint ['port ' ] = $ server ['SERVER_PORT ' ];
80+ }
81+ }
82+
83+ /**
84+ * Set the localEndpoint ipv4 value for all reported spans. Note that this
85+ * is optional because the reverse DNS lookup can be slow.
86+ *
87+ * @param string $ipv4 IPv4 address
88+ */
89+ public function setLocalIpv4 ($ ipv4 )
90+ {
91+ $ this ->localEndpoint ['ipv4 ' ] = $ ipv4 ;
92+ }
93+
94+ /**
95+ * Set the localEndpoint ipv6 value for all reported spans. Note that this
96+ * is optional because the reverse DNS lookup can be slow.
97+ *
98+ * @param string $ipv6 IPv6 address
99+ */
100+ public function setLocalIpv6 ($ ipv6 )
101+ {
102+ $ this ->localEndpoint ['ipv6 ' ] = $ ipv6 ;
72103 }
73104
74105 /**
@@ -124,12 +155,6 @@ public function convertSpans(TracerInterface $tracer, $headers = null)
124155 // True if we are contributing to a span started by another tracer (ex on a different host).
125156 $ isShared = !empty ($ spans ) && $ spans [0 ]->parentSpanId () != null ;
126157
127- $ localEndpoint = [
128- 'serviceName ' => $ this ->name ,
129- 'ipv4 ' => $ this ->host ,
130- 'port ' => $ this ->port
131- ];
132-
133158 $ zipkinSpans = [];
134159 foreach ($ spans as $ span ) {
135160 $ startTime = (int )((float ) $ span ->startTime ()->format ('U.u ' ) * 1000 * 1000 );
@@ -154,7 +179,7 @@ public function convertSpans(TracerInterface $tracer, $headers = null)
154179 'duration ' => $ endTime - $ startTime ,
155180 'debug ' => $ isDebug ,
156181 'shared ' => $ isShared ,
157- 'localEndpoint ' => $ localEndpoint ,
182+ 'localEndpoint ' => $ this -> localEndpoint ,
158183 'tags ' => $ attributes
159184 ];
160185
0 commit comments