Skip to content

Commit

Permalink
Merge branch 'master' into 2.1-merge
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/guzzle/src/CoroutineHandler.php
#	src/guzzle/tests/Stub/CoroutineHandlerStub.php
  • Loading branch information
limingxinleo committed Nov 25, 2020
2 parents 4b88c3f + adbf877 commit fe39980
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 18 deletions.
12 changes: 8 additions & 4 deletions src/Aspect/HttpClientAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,15 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
);
$options['headers'] = array_replace($options['headers'] ?? [], $appendHeaders);
$proceedingJoinPoint->arguments['keys']['options'] = $options;
$result = $proceedingJoinPoint->process();
if ($result instanceof ResponseInterface) {
$span->setTag($this->spanTagManager->get('http_client', 'http.status_code'), $result->getStatusCode());

try {
$result = $proceedingJoinPoint->process();
if ($result instanceof ResponseInterface) {
$span->setTag($this->spanTagManager->get('http_client', 'http.status_code'), $result->getStatusCode());
}
} finally {
$span->finish();
}
$span->finish();
return $result;
}
}
15 changes: 9 additions & 6 deletions src/Aspect/JsonRpcAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,16 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
}

if ($proceedingJoinPoint->methodName === 'send') {
$result = $proceedingJoinPoint->process();
/** @var Span $span */
if ($span = CT::get('tracer.span.' . static::class)) {
if ($this->spanTagManager->has('rpc', 'status')) {
$span->setTag($this->spanTagManager->get('rpc', 'status'), isset($result['result']) ? 'OK' : 'Failed');
try {
$result = $proceedingJoinPoint->process();
} finally {
/** @var Span $span */
if ($span = CT::get('tracer.span.' . static::class)) {
if ($this->spanTagManager->has('rpc', 'status')) {
$span->setTag($this->spanTagManager->get('rpc', 'status'), isset($result['result']) ? 'OK' : 'Failed');
}
$span->finish();
}
$span->finish();
}

return $result;
Expand Down
7 changes: 5 additions & 2 deletions src/Aspect/MethodAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)

$key = $proceedingJoinPoint->className . '::' . $proceedingJoinPoint->methodName;
$span = $this->startSpan($key);
$result = $proceedingJoinPoint->process();
$span->finish();
try {
$result = $proceedingJoinPoint->process();
} finally {
$span->finish();
}
return $result;
}
}
9 changes: 6 additions & 3 deletions src/Aspect/RedisAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
$arguments = $proceedingJoinPoint->arguments['keys'];
$span = $this->startSpan('Redis' . '::' . $arguments['name']);
$span->setTag($this->spanTagManager->get('redis', 'arguments'), json_encode($arguments['arguments']));
$result = $proceedingJoinPoint->process();
$span->setTag($this->spanTagManager->get('redis', 'result'), json_encode($result));
$span->finish();
try {
$result = $proceedingJoinPoint->process();
$span->setTag($this->spanTagManager->get('redis', 'result'), json_encode($result));
} finally {
$span->finish();
}
return $result;
}
}
7 changes: 5 additions & 2 deletions src/Aspect/TraceAnnotationAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
}
$span = $this->startSpan($name);
$span->setTag($tag, $source);
$result = $proceedingJoinPoint->process();
$span->finish();
try {
$result = $proceedingJoinPoint->process();
} finally {
$span->finish();
}
return $result;
}
}
7 changes: 6 additions & 1 deletion src/SpanStarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ protected function startSpan(
/** @var ServerRequestInterface $request */
$request = Context::get(ServerRequestInterface::class);
if (! $request instanceof ServerRequestInterface) {
throw new \RuntimeException('ServerRequest object missing.');
// If the request object is absent, we are probably in a commandline context.
// Throwing an exception is unnecessary.
$root = $this->tracer->startSpan($name, $option);
$root->setTag(SPAN_KIND, $kind);
Context::set('tracer.root', $root);
return $root;
}
$carrier = array_map(function ($header) {
return $header[0];
Expand Down

0 comments on commit fe39980

Please sign in to comment.