@@ -27,7 +27,7 @@ composer require opentracing/opentracing
2727
2828When consuming this library one really only need to worry about a couple of key
2929abstractions: the ` Tracer::startActiveSpan ` and ` Tracer::startSpan ` method,
30- the ` Span ` interface, and binding a ` Tracer ` at bootstrap time. Here are code snippets
30+ the ` Span ` interface, the ` Scope ` interface and binding a ` Tracer ` at bootstrap time. Here are code snippets
3131demonstrating some important use cases:
3232
3333### Singleton initialization
@@ -58,7 +58,7 @@ $spanContext = GlobalTracer::get()->extract(
5858function doSomething() {
5959 ...
6060
61- $span = GlobalTracer::get()->startActiveSpan ('my_span', ['child_of' => $spanContext]);
61+ $span = GlobalTracer::get()->startSpan ('my_span', ['child_of' => $spanContext]);
6262
6363 ...
6464
@@ -77,7 +77,7 @@ function doSomething() {
7777It's always possible to create a "root" ` Span ` with no parent or other causal reference.
7878
7979``` php
80- $span = $tracer->startActiveSpan ('my_first_span');
80+ $span = $tracer->startSpan ('my_first_span');
8181...
8282$span->finish();
8383```
@@ -95,27 +95,34 @@ Unless you are using asynchronous code that tracks multiple spans at the same
9595time, such as when using cURL Multi Exec or MySQLi Polling you are better
9696of just using ` Tracer::startActiveSpan ` everywhere in your application.
9797
98- The currently active span gets automatically closed and deactivated from the scope
99- when you call ` $span->finish() ` as you can see in the previous example.
98+ The currently active span gets automatically finished when you call ` $ scope->close() `
99+ as you can see in the previous example.
100100
101101If you don't want a span to automatically close when ` Span::finish() ` is called
102- then you must pass the option ` 'close_span_on_finish '=> false, ` to the ` $options `
102+ then you must pass the option ` 'finish_span_on_close '=> false, ` to the ` $options `
103103argument of ` startActiveSpan ` .
104104
105105An example of a linear, two level deep span tree using active spans looks like
106106this in PHP code:
107107
108108``` php
109- $root = $tracer->startActiveSpan('php');
110-
111- $controller = $tracer->startActiveSpan('controller');
112-
113- $http = $tracer->startActiveSpan('http');
114- file_get_contents('http://php.net');
115- $http->finish();
109+ // At dispatcher level
110+ $scope = $tracer->startActiveSpan('request');
111+ ...
112+ $scope->close();
113+ ```
114+ ``` php
115+ // At controller level
116+ $scope = $tracer->startActiveSpan('controller');
117+ ...
118+ $scope->close();
119+ ```
116120
117- $controller->finish();
118- $root->finish();
121+ ``` php
122+ // At RPC calls level
123+ $scope = $tracer->startActiveSpan('http');
124+ file_get_contents('http://php.net');
125+ $scope->close();
119126```
120127
121128#### Creating a child span assigning parent manually
@@ -153,11 +160,11 @@ $child = GlobalTracer::get()->startActiveSpan('my_second_span');
153160
154161...
155162
156- $child->finish ();
163+ $child->close ();
157164
158165...
159166
160- $parent->finish ();
167+ $parent->close ();
161168```
162169
163170### Serializing to the wire
@@ -237,7 +244,7 @@ register_shutdown_function(function() {
237244This is optional, tracers can decide to immediately send finished spans to a
238245backend. The flush call can be implemented as a NO-OP for these tracers.
239246
240- ### Using Span Options
247+ ### Using ` StartSpanOptions `
241248
242249Passing options to the pass can be done using either an array or the
243250SpanOptions wrapper object. The following keys are valid:
@@ -246,6 +253,8 @@ SpanOptions wrapper object. The following keys are valid:
246253- ` child_of ` is an object of type ` OpenTracing\SpanContext ` or ` OpenTracing\Span ` .
247254- ` references ` is an array of ` OpenTracing\Reference ` .
248255- ` tags ` is an array with string keys and scalar values that represent OpenTracing tags.
256+ - ` finish_span_on_close ` is a boolean that determines whether a span should be finished or not when the
257+ scope is closed.
249258
250259``` php
251260$span = $tracer->startActiveSpan('my_span', [
0 commit comments