| 1 | <?php |
| 2 | namespace Wikimedia\Telemetry; |
| 3 | |
| 4 | use Wikimedia\Assert\PreconditionException; |
| 5 | |
| 6 | /** |
| 7 | * Base interface for an OpenTelemetry tracer responsible for creating spans. |
| 8 | * @since 1.43 |
| 9 | */ |
| 10 | interface TracerInterface { |
| 11 | /** |
| 12 | * Create a span with the given name and the currently active span as the implicit parent. |
| 13 | * This requires a span to be already active and will throw an error otherwise. |
| 14 | * |
| 15 | * @param string $spanName The descriptive name of this span. |
| 16 | * Refer to the <a href="https://opentelemetry.io/docs/specs/otel/trace/api/#span">OTEL Tracing API |
| 17 | * spec</a> for recommended naming conventions. |
| 18 | * @return SpanInterface |
| 19 | * @throws PreconditionException If no span was active |
| 20 | */ |
| 21 | public function createSpan( string $spanName ): SpanInterface; |
| 22 | |
| 23 | /** |
| 24 | * Create a new root span, i.e. a span with no parent that forms the basis for a new trace. |
| 25 | * |
| 26 | * @param string $spanName The descriptive name of this span. |
| 27 | * Refer to the <a href="https://opentelemetry.io/docs/specs/otel/trace/api/#span">OTEL Tracing API |
| 28 | * spec</a> for recommended naming conventions. |
| 29 | * @return SpanInterface |
| 30 | */ |
| 31 | public function createRootSpan( string $spanName ): SpanInterface; |
| 32 | |
| 33 | /** |
| 34 | * Create a span with the given name and parent. |
| 35 | * |
| 36 | * @param string $spanName The descriptive name of this span. |
| 37 | * Refer to the <a href="https://opentelemetry.io/docs/specs/otel/trace/api/#span">OTEL Tracing API |
| 38 | * spec</a> for recommended naming conventions. |
| 39 | * @param SpanContext $parentSpanContext Context of the parent span this span should be associated with. |
| 40 | * @return SpanInterface |
| 41 | */ |
| 42 | public function createSpanWithParent( string $spanName, SpanContext $parentSpanContext ): SpanInterface; |
| 43 | |
| 44 | /** |
| 45 | * Shut down this tracer and export collected trace data. |
| 46 | * @return void |
| 47 | */ |
| 48 | public function shutdown(): void; |
| 49 | } |