How Active Spans and Scope Manager work
masterFor most use cases, it is recommended to use Tracer::startActiveSpan.
Key Concepts:
- Scope Manager: An underlying abstraction that tracks the currently active span.
- Automatic Parenting: Starting an active span automatically uses the currently active span as its parent. If no parent is active, the new span becomes the root span.
- Automatic Finishing: When using
startActiveSpan, the span is automatically finished when you call$scope->close(). - Asynchronous Note: Unless you are using asynchronous code that tracks multiple spans simultaneously (like cURL Multi Exec), use
startActiveSpaneverywhere.
To prevent a span from automatically finishing when the scope is closed, pass 'finish_span_on_close' => false in the options array.
// At dispatcher level
$scope = $tracer->startActiveSpan('request');
...
$scope->close();
// At controller level
$scope = $tracer->startActiveSpan('controller');
...
$scope->close();
// At RPC calls level
$scope = $tracer->startActiveSpan('http');
file_get_contents('http://php.net');
$scope->close();