Skip to content

Commit 0cf3b8e

Browse files
author
anahan
committed
ProcessIpTag now works for CLI
1 parent 5d7a4b1 commit 0cf3b8e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/Process/ProcessIpTag.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
<?php
2-
declare(strict_types=1);
2+
3+
declare(strict_types = 1);
34

45
namespace Jaeger\Process;
56

67
use Jaeger\Tag\StringTag;
78

89
class ProcessIpTag extends StringTag
910
{
11+
private function getIp(): string
12+
{
13+
if (\array_key_exists('SERVER_ADDR', $_SERVER) && '' !== ($ip = (string)$_SERVER['SERVER_ADDR'])) {
14+
return $ip;
15+
}
16+
17+
if (false === $hostName = \gethostname()) {
18+
return '127.0.0.1';
19+
}
20+
21+
return \gethostbyname($hostName);
22+
}
23+
1024
public function __construct()
1125
{
12-
parent::__construct('ip', $_SERVER['SERVER_ADDR']);
26+
parent::__construct('ip', $this->getIp());
1327
}
1428
}

0 commit comments

Comments
 (0)