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

Commit aeff987

Browse files
authored
Add Usage docs (#79)
* Build main page with hugo and hyde theme to match opencensus.io style * Add content for framework integration * Fix code fence blocks * Add pages for integrating Guzzle and Wordpress * Add a page for using the extension * Menu links
1 parent d9dc296 commit aeff987

37 files changed

Lines changed: 1617 additions & 3 deletions

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ php:
44

55
install:
66
- wget -O sami.phar http://get.sensiolabs.org/sami.phar
7+
- wget -O /tmp/hugo.deb https://github.com/gohugoio/hugo/releases/download/v0.30.2/hugo_0.30.2_Linux-64bit.deb
8+
- sudo dpkg -i /tmp/hugo.deb
79

810
script:
11+
- cd docs && hugo
912
- php sami.phar update config/sami.php
1013
- touch docs/.nojekyll
1114

@@ -15,7 +18,7 @@ branches:
1518

1619
deploy:
1720
provider: pages
18-
local_dir: docs
21+
local_dir: docs/public
1922
skip_cleanup: true
2023
email: chingor@google.com # To satisfy the CLA check, replace this with bot email.
2124
github_token: $GITHUB_TOKEN # Set in travis-ci.org dashboard

config/sami.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
$sami = new Sami($iterator, [
3838
// 'versions' => $versions,
39-
'build_dir' => __DIR__ . '/../docs',
39+
'build_dir' => __DIR__ . '/../docs/public/api',
4040
'title' => 'OpenCensus PHP API'
4141
]);
4242

docs/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_site
2+
.sass-cache
3+
public/

docs/config.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
baseURL = "/"
2+
languageCode = "en-us"
3+
title = "OpenCensus for PHP"
4+
theme = "hyde"
5+
6+
pygmentsCodeFences = true
7+
pygmentsOptions = "startinline=false"
8+
9+
[params]
10+
description = "A stats collection and distributed tracing framework"
11+
12+
[[menu.main]]
13+
name = "API Documentation"
14+
url = "/api"
15+
weight = -10

docs/content/index.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: "OpenCensus for PHP"
3+
date: "2017-11-30"
4+
type: index
5+
menu:
6+
main:
7+
weight: -100
8+
---
9+
10+
# OpenCensus for PHP
11+
12+
[API Documentation][api-docs]
13+
14+
## Installation
15+
16+
1. Install the `opencensus/opencensus` package using [composer][composer]:
17+
18+
```bash
19+
$ composer require opencensus/opencensus
20+
```
21+
22+
1. [Optional]: Install the `opencensus` extension from [PECL][pecl]. See more
23+
information on [using the extension](using-the-extension).
24+
25+
## Tracing
26+
27+
### Framework Integration
28+
29+
* [Laravel](integrating-laravel)
30+
* [Silex](integrating-silex)
31+
* [Symfony](integrating-symfony)
32+
* [Wordpress](integrating-wordpress)
33+
34+
### Other Integrations
35+
36+
* [Guzzle](integrating-guzzle)
37+
38+
## Stats
39+
40+
Coming Soon!
41+
42+
[api-docs]: api/
43+
[composer]: https://getcomposer.org/
44+
[pecl]: https://pecl.php.net/

docs/content/integrating-guzzle.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: "Integrating OpenCensus with Guzzle"
3+
date: "2017-11-30"
4+
type: page
5+
menu:
6+
main:
7+
parent: "Integrations"
8+
---
9+
10+
Integration with Guzzle using the following methods will:
11+
12+
1. Create spans for every outgoing HTTP request used by that Guzzle client.
13+
2. Propagate the span context to the remote endpoint for distributed tracing.
14+
15+
## Guzzle 6
16+
17+
To add OpenCensus support for Guzzle 6 HTTP clients, we add a middleware to our
18+
Guzzle client:
19+
20+
```php
21+
<?php
22+
use GuzzleHttp\Client;
23+
use GuzzleHttp\HandlerStack;
24+
use OpenCensus\Trace\Integrations\Guzzle\Middleware;
25+
26+
$stack = new HandlerStack();
27+
$stack->setHandler(\GuzzleHttp\choose_handler());
28+
$stack->push(new Middleware());
29+
$client = new Client(['handler' => $stack]);
30+
```
31+
32+
You will want to set this up wherever your Guzzle client is created.
33+
34+
## Guzzle 5
35+
36+
To add OpenCensus support for Guzzle 5 clients, we attach an EventSubscriber to
37+
our Guzzle client:
38+
39+
```php
40+
<?php
41+
use GuzzleHttp\Client;
42+
use OpenCensus\Trace\Integrations\Guzzle\EventSubscriber;
43+
44+
$client = new Client();
45+
$subscriber = new EventSubscriber();
46+
$client->getEmitter()->attach($subscriber);
47+
```
48+
49+
You will want to set this up wherever your Guzzle client is created.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: "Integrating OpenCensus with Laravel"
3+
date: "2017-11-30"
4+
type: page
5+
menu:
6+
main:
7+
parent: "Integrations"
8+
---
9+
10+
## Laravel 5.5
11+
12+
1. To add OpenCensus to our Laravel application, we will create a
13+
`ServiceProvider`. In `app/Providers/OpenCensusProvider.php`:
14+
15+
```php
16+
<?php
17+
namespace App\Providers;
18+
19+
use Illuminate\Support\ServiceProvider;
20+
use OpenCensus\Trace\Exporter\StackdriverExporter;
21+
use OpenCensus\Trace\Tracer;
22+
use OpenCensus\Trace\Integrations\Laravel;
23+
use OpenCensus\Trace\Integrations\Mysql;
24+
use OpenCensus\Trace\Integrations\PDO;
25+
26+
class OpenCensusProvider extends ServiceProvider
27+
{
28+
public function boot()
29+
{
30+
if (php_sapi_name() == 'cli') {
31+
return;
32+
}
33+
34+
// Enable OpenCensus extension integrations
35+
Laravel::load();
36+
Mysql::load();
37+
PDO::load();
38+
39+
// Start the request tracing for this request
40+
$exporter = new StackdriverExporter();
41+
Tracer::start($exporter);
42+
43+
// Create a span that starts from when Laravel first boots (public/index.php)
44+
Tracer::inSpan(['name' => 'bootstrap', 'startTime' => LARAVEL_START], function () {});
45+
}
46+
}
47+
```
48+
49+
In this example, we configured `StackdriverExporter`, but you can configure
50+
any exporter here. You can also enable any other integrations here.
51+
52+
1. Enable this `ServiceProvider`. In `config/app.php`:
53+
54+
```php
55+
<?php
56+
// in the `providers` section
57+
...
58+
'providers' => [
59+
...
60+
App\Providers\OpenCensusProvider::class,
61+
],
62+
...
63+
```

docs/content/integrating-silex.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: "Integrating OpenCensus with Silex"
3+
date: "2017-11-30"
4+
type: page
5+
menu:
6+
main:
7+
parent: "Integrations"
8+
---
9+
10+
## Silex 2.2
11+
12+
To add OpenCensus to our Silex application, we simply start the tracer at the
13+
beginning of our application. In `web/index.php`:
14+
15+
```php
16+
<?php
17+
require_once __DIR__ . '/../vendor/autoload.php';
18+
19+
// Configure and start the OpenCensus Tracer
20+
$exporter = new OpenCensus\Trace\Exporter\StackdriverExporter();
21+
OpenCensus\Trace\Tracer::start($exporter);
22+
23+
$app = new Silex\Application();
24+
// ... rest of the application
25+
```
26+
27+
In this example, we configured `StackdriverExporter`, but you can configure
28+
any exporter here. You can also enable any other integrations here.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
title: "Integrating OpenCensus with Symfony"
3+
date: "2017-11-30"
4+
type: page
5+
menu:
6+
main:
7+
parent: "Integrations"
8+
---
9+
10+
## Symfony 3.3
11+
12+
1. To add OpenCensus to our Symfony application, we will create a `Bundle`
13+
In `src/AppBundle/OpenCensusBundle.php`:
14+
15+
```php
16+
<?php
17+
namespace AppBundle;
18+
19+
use OpenCensus\Trace\Exporter\StackdriverExporter;
20+
use OpenCensus\Trace\Integrations\Mysql;
21+
use OpenCensus\Trace\Integrations\PDO;
22+
use OpenCensus\Trace\Integrations\Symfony;
23+
use OpenCensus\Trace\Tracer;
24+
use Symfony\Component\HttpKernel\Bundle\Bundle;
25+
26+
class AppBundle extends Bundle
27+
{
28+
public function boot()
29+
{
30+
$this->setupOpenCensus();
31+
}
32+
33+
private function setupOpenCensus()
34+
{
35+
if (php_sapi_name() == 'cli') {
36+
return;
37+
}
38+
39+
// Enable OpenCensus extension integrations
40+
Mysql::load();
41+
PDO::load();
42+
Symfony::load();
43+
44+
// Start the request tracing for this request
45+
$exporter = new StackdriverExporter();
46+
Tracer::start($exporter);
47+
}
48+
}
49+
```
50+
51+
In this example, we configured `StackdriverExporter`, but you can configure
52+
any exporter here. You can also enable any other integrations here.
53+
54+
1. Enable this `Bundle` by adding it to the list of bundles registered. In
55+
`app/AppKernel.php`:
56+
57+
```php
58+
<?php
59+
// in the `registerBundles()`
60+
...
61+
$bundles = [
62+
...
63+
new AppBundle\AppBundle(),
64+
new AppBundle\OpenCensusBundle(),
65+
];
66+
...
67+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: "Integrating OpenCensus with WordPress"
3+
date: "2017-11-30"
4+
type: page
5+
menu:
6+
main:
7+
parent: "Integrations"
8+
---
9+
10+
To add OpenCensus to your WordPress installation, ensure that you can use
11+
composer with your instance of WordPress.
12+
13+
In your `wp-config.php`:
14+
15+
```php
16+
<?php
17+
// load composer dependencies
18+
require_once('/path/to/vendor/autoload.php');
19+
20+
use OpenCensus\Trace\Exporter\StackdriverExporter;
21+
use OpenCensus\Trace\Tracer;
22+
23+
OpenCensus\Trace\Integrations\Wordpress::load();
24+
$exporter = new StackdriverExporter();
25+
Tracer::start($exporter);
26+
```
27+
28+
In this example, we configured `StackdriverExporter`, but you can configure any
29+
exporter here. You can also enable any other integrations here.

0 commit comments

Comments
 (0)