carno-php /
tracing
| 1 | <?php |
||||||
| 2 | /** |
||||||
| 3 | * Context generator for carrier |
||||||
| 4 | * User: moyo |
||||||
| 5 | * Date: 23/11/2017 |
||||||
| 6 | * Time: 4:47 PM |
||||||
| 7 | */ |
||||||
| 8 | |||||||
| 9 | namespace Carno\Tracing\Chips; |
||||||
| 10 | |||||||
| 11 | use Carno\Tracing\Contracts\Vars\CTX; |
||||||
| 12 | use Carno\Tracing\Standard\Context; |
||||||
| 13 | use OpenTracing\Exceptions\SpanContextNotFound; |
||||||
| 14 | use OpenTracing\SpanContext; |
||||||
| 15 | |||||||
| 16 | trait ContextOperator |
||||||
| 17 | { |
||||||
| 18 | use IDGenerator; |
||||||
| 19 | |||||||
| 20 | /** |
||||||
| 21 | * @param SpanContext|null $in |
||||||
| 22 | * @return SpanContext |
||||||
| 23 | */ |
||||||
| 24 | public function fusedContext(SpanContext $in = null) : SpanContext |
||||||
| 25 | { |
||||||
| 26 | return $in ? $this->initFromContext($in) : $this->toNewContext(); |
||||||
| 27 | } |
||||||
| 28 | |||||||
| 29 | /** |
||||||
| 30 | * @return SpanContext |
||||||
| 31 | */ |
||||||
| 32 | protected function toNewContext() : SpanContext |
||||||
| 33 | { |
||||||
| 34 | if (empty($traceID = $this->getTraceID())) { |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 35 | throw SpanContextNotFound::create(); |
||||||
| 36 | } |
||||||
| 37 | |||||||
| 38 | $overrides = [ |
||||||
| 39 | CTX::TRACE_ID => $traceID, |
||||||
| 40 | CTX::SPAN_ID => $this->newSpanID(), |
||||||
| 41 | CTX::PARENT_SPAN_ID => $this->getSpanID(), |
||||||
|
0 ignored issues
–
show
It seems like
getSpanID() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 42 | CTX::TRACE_SAMPLED => $this->checkIsSampled(), |
||||||
|
0 ignored issues
–
show
It seems like
checkIsSampled() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 43 | ]; |
||||||
| 44 | |||||||
| 45 | return new Context(array_merge($this->getBaggageItems(), $overrides)); |
||||||
|
0 ignored issues
–
show
It seems like
getBaggageItems() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 46 | } |
||||||
| 47 | |||||||
| 48 | /** |
||||||
| 49 | * @param SpanContext $ctx |
||||||
| 50 | * @return SpanContext |
||||||
| 51 | */ |
||||||
| 52 | protected function initFromContext(SpanContext $ctx) : SpanContext |
||||||
| 53 | { |
||||||
| 54 | $this->setTraceID($ctx[CTX::TRACE_ID] ?? ''); |
||||||
|
0 ignored issues
–
show
It seems like
setTraceID() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 55 | $this->setSpanID($ctx[CTX::SPAN_ID] ?? ''); |
||||||
|
0 ignored issues
–
show
It seems like
setSpanID() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 56 | |||||||
| 57 | if ($ctx[CTX::PARENT_SPAN_ID] ?? '') { |
||||||
| 58 | $this->setParentSpanID($ctx[CTX::PARENT_SPAN_ID]); |
||||||
|
0 ignored issues
–
show
It seems like
setParentSpanID() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 59 | } |
||||||
| 60 | |||||||
| 61 | $this->markIsSampled($ctx[CTX::TRACE_SAMPLED] ?? false); |
||||||
|
0 ignored issues
–
show
It seems like
markIsSampled() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 62 | |||||||
| 63 | $items = []; |
||||||
| 64 | |||||||
| 65 | foreach ($ctx->getIterator() as $k => $v) { |
||||||
| 66 | if (in_array($k, [CTX::TRACE_ID, CTX::SPAN_ID, CTX::PARENT_SPAN_ID, CTX::TRACE_SAMPLED])) { |
||||||
| 67 | continue; |
||||||
| 68 | } else { |
||||||
| 69 | $items[$k] = $v; |
||||||
| 70 | } |
||||||
| 71 | } |
||||||
| 72 | |||||||
| 73 | $items && $this->setBaggageItems($items); |
||||||
|
0 ignored issues
–
show
It seems like
setBaggageItems() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 74 | |||||||
| 75 | return $ctx; |
||||||
| 76 | } |
||||||
| 77 | } |
||||||
| 78 |