This repository was archived by the owner on Oct 3, 2023. It is now read-only.
File tree 2 files changed +16
-13
lines changed
2 files changed +16
-13
lines changed Original file line number Diff line number Diff line change @@ -9,12 +9,12 @@ beginning of our application. In `web/index.php`:
9
9
require_once __DIR__ . '/../vendor/autoload.php';
10
10
11
11
// Configure and start the OpenCensus Tracer
12
- $exporter = new OpenCensus\Trace\Exporter\StackdriverExporter ();
12
+ $exporter = new OpenCensus\Trace\Exporter\EchoExporter ();
13
13
OpenCensus\Trace\Tracer::start($exporter);
14
14
15
15
$app = new Silex\Application();
16
16
// ... rest of the application
17
17
```
18
18
19
- In this example, we configured ` StackdriverExporter ` , but you can configure
19
+ In this example, we configured ` EchoExporter ` , but you can configure
20
20
any exporter here. You can also enable any other integrations here.
Original file line number Diff line number Diff line change 4
4
5
5
// Configure and start the OpenCensus Tracer
6
6
use OpenCensus \Trace \Tracer ;
7
- $ exporter = new OpenCensus \Trace \Exporter \StackdriverExporter ();
7
+ $ exporter = new OpenCensus \Trace \Exporter \EchoExporter ();
8
8
Tracer::start ($ exporter );
9
9
10
10
function fib ($ n )
11
11
{
12
- if ($ n < 3 ) {
13
- return $ n ;
14
- }
15
- return fib ($ n - 1 ) + fib ($ n - 2 );
12
+ return Tracer::inSpan ([
13
+ 'name ' => 'fib ' ,
14
+ 'attributes ' => [
15
+ 'n ' => $ n
16
+ ]
17
+ ], function () use ($ n ) {
18
+ if ($ n < 3 ) {
19
+ return $ n ;
20
+ }
21
+ return fib ($ n - 1 ) + fib ($ n - 2 );
22
+ });
16
23
}
17
24
18
25
$ app = new Silex \Application ();
@@ -21,14 +28,10 @@ function fib($n)
21
28
return 'Hello World! ' ;
22
29
});
23
30
24
- $ app ->get ('/hello/{name} ' , function ($ name ) use ($ app ) {
25
- return 'Hello ' . $ app ->escape ($ name );
26
- });
27
-
28
31
$ app ->get ('/fib/{n} ' , function ($ n ) use ($ app ) {
29
32
$ n = (int ) $ n ;
30
- $ fib = Tracer:: inSpan ([ ' name ' => ' recursiveFib ' ], ' fib ' , [ $ n ] );
31
- return sprintf ('The %dth Fibonacci number is %d ' , $ n , $ fib );
33
+ $ fib = fib ( $ n );
34
+ return sprintf ('The %dth Fibonacci number is %d. ' , $ n , $ fib );
32
35
});
33
36
34
37
$ app ->run ();
You can’t perform that action at this time.
0 commit comments