88use Jaeger \Tag \OutOfScopeTag ;
99use Jaeger \Thrift \Log ;
1010use Jaeger \Thrift \Tag ;
11- use Jaeger \Tracer \TracerInterface ;
11+ use Jaeger \Tracer \FinishableInterface ;
1212
1313class Span extends \Jaeger \Thrift \Span implements SpanInterface
1414{
@@ -17,7 +17,7 @@ class Span extends \Jaeger\Thrift\Span implements SpanInterface
1717 private $ context ;
1818
1919 public function __construct (
20- TracerInterface $ tracer ,
20+ FinishableInterface $ tracer ,
2121 SpanContext $ context ,
2222 string $ operationName ,
2323 int $ startTime ,
@@ -33,7 +33,6 @@ public function __construct(
3333 $ this ->flags = $ context ->getFlags ();
3434 $ this ->operationName = $ operationName ;
3535 $ this ->startTime = $ startTime ;
36-
3736 $ this ->tags = $ tags ;
3837 $ this ->logs = $ logs ;
3938 parent ::__construct ();
@@ -42,14 +41,11 @@ public function __construct(
4241 public function __destruct ()
4342 {
4443 if (null !== $ this ->duration ) {
45- return $ this ;
44+ return ;
4645 }
4746 $ this ->tags [] = new ErrorTag ();
4847 $ this ->tags [] = new OutOfScopeTag ();
49-
5048 $ this ->tracer ->finish ($ this );
51-
52- return $ this ;
5349 }
5450
5551 public function getContext (): ?SpanContext
@@ -59,7 +55,7 @@ public function getContext(): ?SpanContext
5955
6056 public function isSampled (): bool
6157 {
62- return ( bool )( $ this ->flags & 1 );
58+ return $ this ->context -> isSampled ( );
6359 }
6460
6561 public function start (int $ startTimeUsec ): SpanInterface
@@ -71,10 +67,8 @@ public function start(int $startTimeUsec): SpanInterface
7167
7268 public function finish (int $ durationUsec = 0 ): SpanInterface
7369 {
74- if (0 === $ durationUsec ) {
75- $ durationUsec = (int )(microtime (true ) * 1000000 ) - $ this ->startTime ;
76- }
77- $ this ->duration = $ durationUsec ;
70+ $ this ->duration = $ durationUsec ?: (microtime (true ) * 1000000 ) - $ this ->startTime ;
71+ $ this ->tracer ->finish ($ this , -1 );
7872
7973 return $ this ;
8074 }
0 commit comments