Skip to content

Commit

Permalink
Merge pull request #8 from uniondrug/2.x
Browse files Browse the repository at this point in the history
add ua to log
  • Loading branch information
xueron authored Apr 26, 2018
2 parents 66de767 + ac3d8fe commit 7442633
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/Middlewares/TraceMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@

class TraceMiddleware extends Middleware
{
const TRACE_ID = 'X_TRACE_ID';
const SPAN_ID = 'UDS_SPAN_ID';
const PARENT_SPAN_ID = 'UDS_PARENT_SPAN_ID';

/**
* @param \Phalcon\Http\RequestInterface $request
* @param \Uniondrug\Middleware\DelegateInterface $next
Expand All @@ -35,6 +31,7 @@ public function handle(RequestInterface $request, DelegateInterface $next)
$rTime = microtime(1);
$rip = $request->getClientAddress(true);
$req = $request->getHeader('REQUEST_URI');
$rua = $request->getUserAgent();
$query = $request->getHeader('QUERY_STRING');
if (!empty($query)) {
$req = $req . '?' . $query;
Expand Down Expand Up @@ -76,8 +73,8 @@ public function handle(RequestInterface $request, DelegateInterface $next)
$tTime = $sTime - $rTime;

// 5. 记录信息
$this->di->getLogger('trace')->debug(sprintf("[TraceMiddleware] traceId=%s, spanId=%s, pSpanId=%s, ss=%s, sr=%s, t=%s, req=%s, error=%s",
$traceId, $spanId, $parentSpanId, $sTime, $rTime, $tTime, $req, $error
$this->di->getLogger('trace')->debug(sprintf("[TraceMiddleware] traceId=%s, spanId=%s, pSpanId=%s, ss=%s, sr=%s, t=%s, req=%s, ua=%s, error=%s",
$traceId, $spanId, $parentSpanId, $sTime, $rTime, $tTime, $req, $rua, $error
));

// 6. 发送到中心
Expand All @@ -93,6 +90,7 @@ public function handle(RequestInterface $request, DelegateInterface $next)
'service' => $this->config->path('app.appName', 'UniondrugService'), // 当前服务的名称,在app.conf里面配置
'sr' => $rTime, // ServerReceive, 收到请求的时间
'ss' => $sTime, // ServerSend,完成后发送的时间
'ua' => $rua, // UserAgent
'req' => $req, // 请求的路径
'error' => $error,
]);
Expand Down

0 comments on commit 7442633

Please sign in to comment.