Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
6 / 12
57.14% covered (warning)
57.14%
4 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
NoopTracer
50.00% covered (danger)
50.00%
6 / 12
57.14% covered (warning)
57.14%
4 / 7
16.00
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 createSpan
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createRootSpan
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createSpanWithParent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 shutdown
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 createRootSpanFromCarrier
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getRequestHeaders
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2namespace Wikimedia\Telemetry;
3
4/**
5 * A no-op tracer that creates no-op spans and persists no data.
6 * Useful for scenarios where tracing is disabled.
7 * Can still propagate some (not-Span-specific) context, like X-Request-Id.
8 *
9 * @since 1.43
10 * @internal
11 */
12class NoopTracer implements TracerInterface {
13
14    private SpanContext $noopSpanContext;
15    private TracerState $tracerState;
16    private ?ContextPropagatorInterface $contextPropagator;
17
18    public function __construct( ?ContextPropagatorInterface $contextPropagator = null ) {
19        $this->noopSpanContext = new SpanContext( '', '', null, '', false );
20        $this->tracerState = new TracerState();
21        $this->contextPropagator = $contextPropagator;
22    }
23
24    /** @inheritDoc */
25    public function createSpan( string $spanName, $parentSpan = null ): SpanInterface {
26        return new NoopSpan( $this->tracerState, $this->noopSpanContext );
27    }
28
29    /** @inheritDoc */
30    public function createRootSpan( string $spanName ): SpanInterface {
31        return new NoopSpan( $this->tracerState, $this->noopSpanContext );
32    }
33
34    /** @inheritDoc */
35    public function createSpanWithParent( string $spanName, SpanContext $parentSpanContext ): SpanInterface {
36        return new NoopSpan( $this->tracerState, $this->noopSpanContext );
37    }
38
39    /** @inheritDoc */
40    public function shutdown(): void {
41        // no-op
42    }
43
44    /** @inheritDoc */
45    public function createRootSpanFromCarrier( string $spanName, array $carrier ): SpanInterface {
46        return new NoopSpan( $this->tracerState, $this->noopSpanContext );
47    }
48
49    /** @inheritDoc */
50    public function getRequestHeaders(): array {
51        $rv = [];
52        if ( $this->contextPropagator ) {
53            $rv = $this->contextPropagator->inject( $this->noopSpanContext, $rv );
54        }
55        return $rv;
56    }
57}