Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 842bbc5

Browse files
authored
Simplify quickstart (#142)
* Simplify silex example for use as quickstart * Update silex README with updates
1 parent b94682d commit 842bbc5

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

examples/silex/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ beginning of our application. In `web/index.php`:
99
require_once __DIR__ . '/../vendor/autoload.php';
1010

1111
// Configure and start the OpenCensus Tracer
12-
$exporter = new OpenCensus\Trace\Exporter\StackdriverExporter();
12+
$exporter = new OpenCensus\Trace\Exporter\EchoExporter();
1313
OpenCensus\Trace\Tracer::start($exporter);
1414

1515
$app = new Silex\Application();
1616
// ... rest of the application
1717
```
1818

19-
In this example, we configured `StackdriverExporter`, but you can configure
19+
In this example, we configured `EchoExporter`, but you can configure
2020
any exporter here. You can also enable any other integrations here.

examples/silex/web/index.php

+14-11
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@
44

55
// Configure and start the OpenCensus Tracer
66
use OpenCensus\Trace\Tracer;
7-
$exporter = new OpenCensus\Trace\Exporter\StackdriverExporter();
7+
$exporter = new OpenCensus\Trace\Exporter\EchoExporter();
88
Tracer::start($exporter);
99

1010
function fib($n)
1111
{
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+
});
1623
}
1724

1825
$app = new Silex\Application();
@@ -21,14 +28,10 @@ function fib($n)
2128
return 'Hello World!';
2229
});
2330

24-
$app->get('/hello/{name}', function ($name) use ($app) {
25-
return 'Hello ' . $app->escape($name);
26-
});
27-
2831
$app->get('/fib/{n}', function ($n) use ($app) {
2932
$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);
3235
});
3336

3437
$app->run();

0 commit comments

Comments
 (0)