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

Commit bc7d181

Browse files
eduardoemerykjin
authored andcommitted
doc: update readme.md files and add examples (#29)
* doc: update readme.md files and add examples * refactor(fix): changes to address review comments
1 parent b2fd95d commit bc7d181

File tree

12 files changed

+487
-81
lines changed

12 files changed

+487
-81
lines changed

README.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,47 @@
1-
# OpenCensus Core Node.js
1+
# OpenCensus Libraries for Node.js
22
[![Gitter chat][gitter-image]][gitter-url]
33

4-
OpenCensus for Node.js is an implementation of OpenCensus, a toolkit for collecting application performance and behavior monitoring data.
4+
OpenCensus Node.js is an implementation of OpenCensus, a toolkit for collecting application performance and behavior monitoring data. Right now OpenCensus for Node.js supports custom tracing and automatic tracing for HTTP and HTTPS. Please visit the [OpenCensus Node.js package](https://github.com/census-instrumentation/opencensus-node/tree/master/packages/opencensus-nodejs) for usage.
55

66
The library is in alpha stage and the API is subject to change.
77

88
Please join [gitter](https://gitter.im/census-instrumentation/Lobby) for help or feedback on this project.
99

10+
## Installation
11+
12+
Install OpenCensus with:
13+
14+
```bash
15+
npm install @opencensus/nodejs
16+
```
17+
18+
## Plugins
19+
20+
OpenCensus can collect tracing data automatically using plugins. Users can also create and use their own plugins. Currently, OpenCensus supports automatic tracing for:
21+
22+
- [HTTP](https://github.com/census-instrumentation/opencensus-node/blob/master/packages/opencensus-instrumentation-http/README.md)
23+
- [HTTPS](https://github.com/census-instrumentation/opencensus-node/blob/master/packages/opencensus-instrumentation-https/README.md)
24+
25+
## Propagation
26+
27+
OpenCensus collects distributed tracing. It is able to do so by propagating span data through services. Currently, OpenCensus supports:
28+
29+
- [B3 Propagation](https://github.com/census-instrumentation/opencensus-node/blob/master/packages/opencensus-propagation-b3/README.md)
30+
- [Stackdriver Propagation](https://github.com/census-instrumentation/opencensus-node/blob/master/packages/opencensus-propagation-stackdriver/README.md)
31+
32+
## Exporters
33+
34+
OpenCensus is vendor-agnostic and can upload data to any backend with various exporter implementations. Even though, OpenCensus provides support for many backends, users can also implement their own exporters for proprietary and unofficially supported backends. Currently, OpenCensus supports:
35+
36+
- [Stackdriver](https://github.com/census-instrumentation/opencensus-node/blob/master/packages/opencensus-exporter-stackdriver/README.md)
37+
- [Zipkin](https://github.com/census-instrumentation/opencensus-node/blob/master/packages/opencensus-exporter-zipkin/README.md)
38+
- [Z-Pages](https://github.com/census-instrumentation/opencensus-node/blob/master/packages/opencensus-exporter-zpages/README.md)
39+
- [Jaeger](https://github.com/census-instrumentation/opencensus-node/blob/master/packages/opencensus-exporter-jaeger/README.md)
40+
41+
If no exporter is registered in the tracing instance, as default, a console log exporter is used.
42+
1043
## Useful links
1144
- For more information on OpenCensus, visit: <https://opencensus.io/>
12-
- To checkout the OpenCensus for Node.js, visit: <https://github.com/census-instrumentation/opencensus-node>
1345
- For help or feedback on this project, join us on [gitter](https://gitter.im/census-instrumentation/Lobby)
1446

1547
[gitter-image]: https://badges.gitter.im/census-instrumentation/lobby.svg
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# OpenCensus Node.js Automatic Tracing
2+
3+
In this example we'll build a simple http server that returns `Hello World`. We're also going to instrument it using OpenCensus, to be able to collect traces and send them to different services.
4+
5+
## Installing OpenCensus
6+
7+
Install OpenCensus with:
8+
9+
```bash
10+
npm install @opencensus/nodejs
11+
```
12+
13+
## Instrumenting the Application
14+
15+
OpenCensus is able to automatically trace HTTP requests, therefore, you just need to require OpenCensus in your application with:
16+
17+
```javascript
18+
var tracing = require('@opencensus/nodejs');
19+
tracing.start();
20+
21+
var http = require('http');
22+
http.createServer(function (req, res) {
23+
res.writeHead(200, { 'Content-Type': 'text/html' });
24+
res.write('Hello World!');
25+
res.end();
26+
}).listen(8080);
27+
```
28+
29+
### Using Stackdriver Exporter
30+
31+
To use Stackdriver as your exporter, make sure you have enabled [Stackdriver Tracing](https://cloud.google.com/trace/docs/quickstart) on Google Cloud Platform. Enable your [Application Default Credentials](https://cloud.google.com/docs/authentication/getting-started) for authentication with:
32+
33+
```bash
34+
export GOOGLE_APPLICATION_CREDENTIALS=path/to/your/credential.json
35+
```
36+
37+
In your code, instanciate a Stackdriver Exporter and pass it to `tracing.start()`.
38+
39+
```javascript
40+
var stackdriver = require('@opencensus/exporter-stackdriver');
41+
42+
// Add your project id to the Stackdriver options
43+
exporter = new stackdriver.StackdriverTraceExporter({projectId: "your-project-id"});
44+
45+
tracing.start({'exporter': exporter});
46+
```
47+
48+
### Using Zipkin Exporter
49+
50+
To use Zipkin as your exporter, first, download from any of the three available options on [Quickstart](https://zipkin.io/pages/quickstart.html): through Docker, on Java or manually compiling the source code. Tests were executed running Zipkin with Java, through the following commands on terminal:
51+
52+
```bash
53+
wget -O zipkin.jar 'https://search.maven.org/remote_content?g=io.zipkin.java&a=zipkin-server&v=LATEST&c=exec'
54+
java -jar zipkin.jar
55+
```
56+
57+
In your code, instanciate a Zipkin Exporter and pass it to `tracing.start()`.
58+
59+
```javascript
60+
var zipkin = require('@opencensus/exporter-zipkin');
61+
62+
// Add your zipkin url and service name to the Zipkin options
63+
var options = {
64+
url: 'your-zipkin-url',
65+
serviceName: 'your-service-name'
66+
}
67+
var exporter = new zipkin.ZipkinTraceExporter(options);
68+
69+
tracing.start({'exporter': exporter});
70+
```
71+
72+
## Running the Instrumented Application
73+
74+
Run the application with:
75+
76+
```bash
77+
node server.js
78+
```
79+
80+
Go to `http://localhost:8080` to make a request or use a REST Application to do so.
81+
82+
Now, just go to the service used to send the traces and see the requests you just made.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright 2018, OpenCensus Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
var tracing = require('opencensus-nodejs');
18+
var stackdriver = require('@opencensus/opencensus-exporter-stackdriver');
19+
20+
// Add your project id to the Stackdriver options
21+
exporter = new stackdriver.StackdriverTraceExporter({projectId: "your-project-id"});
22+
23+
tracing.start({'exporter': exporter});
24+
25+
var http = require('http');
26+
http.createServer(function (req, res) {
27+
res.writeHead(200, { 'Content-Type': 'text/html' });
28+
res.write('Hello World!');
29+
res.end();
30+
}).listen(8080);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright 2018, OpenCensus Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
var tracing = require('opencensus-nodejs');
18+
var zipkin = require('@opencensus/opencensus-exporter-zipkin');
19+
20+
// Add your zipkin url and service name to the Zipkin options
21+
var options = {
22+
url: 'your-zipkin-url',
23+
serviceName: 'your-service-name'
24+
}
25+
var exporter = new zipkin.ZipkinTraceExporter(options);
26+
27+
tracing.start({'exporter': exporter});
28+
29+
var http = require('http');
30+
http.createServer(function (req, res) {
31+
res.writeHead(200, { 'Content-Type': 'text/html' });
32+
res.write('Hello World!');
33+
res.end();
34+
}).listen(8080);

packages/opencensus-exporter-stackdriver/README.md

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,59 @@
11
# OpenCensus Stackdriver Exporter for Node.js
22
[![Gitter chat][gitter-image]][gitter-url]
33

4-
OpenCensus Stackdriver Exporter allows the user to send collected traces with OpenCensus Node.js to Stackdriver.
4+
OpenCensus Stackdriver Exporter allows the user to send collected traces with [OpenCensus Node.js](https://github.com/census-instrumentation/opencensus-node) to Stackdriver.
55

66
This project is still at an early stage of development. It's subject to change.
77

8-
Note: This code was tested on the following Node versions:
9-
- v6.10.0 (for console exporter only)
10-
- v9.8.0 (for Stackdriver and Zipkin exporters)
8+
## Installation
119

10+
Install OpenCensus Stackdriver Exporter with:
11+
```bash
12+
npm install @opencensus/nodejs
13+
npm install @opencensus/exporter-stackdriver
14+
```
15+
16+
## Usage
17+
18+
To use Stackdriver as your exporter, make sure you have enabled [Stackdriver Tracing](https://cloud.google.com/trace/docs/quickstart) on Google Cloud Platform. Enable your [Application Default Credentials](https://cloud.google.com/docs/authentication/getting-started) for authentication with:
19+
20+
```bash
21+
export GOOGLE_APPLICATION_CREDENTIALS=path/to/your/credential.json
22+
```
23+
24+
Instance the exporter on your application and pass your Project ID. For javascript:
25+
26+
```javascript
27+
var tracing = require('@opencensus/nodejs');
28+
var stackdriver = require('@opencensus/exporter-stackdriver');
29+
30+
// Add your project id to the Stackdriver options
31+
var exporter = new stackdriver.StackdriverTraceExporter({projectId: "your-project-id"});
32+
33+
tracing.registerExporter(exporter).start();
34+
```
35+
36+
Similarly for Typescript:
37+
38+
```typescript
39+
import * as tracing from '@opencensus/nodejs';
40+
import { StackdriverTraceExporter } from '@opencensus/exporter-stackdriver';
41+
42+
// Add your project id to the Stackdriver options
43+
const exporter = new StackdriverTraceExporter({projectId: "your-project-id"});
44+
```
45+
46+
Now, register the exporter and start tracing.
47+
48+
```javascript
49+
tracing.start({'exporter': exporter});
50+
```
51+
52+
or
53+
54+
```javascript
55+
tracing.registerExporter(exporter).start();
56+
```
1257

1358
## Useful links
1459
- To know more about Stackdriver, visit: <https://cloud.google.com/docs/authentication/getting-started>

packages/opencensus-exporter-zipkin/README.md

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,66 @@
11
# OpenCensus Zipkin Exporter for Node.js
22
[![Gitter chat][gitter-image]][gitter-url]
33

4-
OpenCensus Zipkin Exporter allows the user to send collected traces with OpenCensus Node.js to Zipkin.
4+
OpenCensus Zipkin Exporter allows the user to send collected traces with [OpenCensus Node.js](https://github.com/census-instrumentation/opencensus-node) to Zipkin.
55

66
This project is still at an early stage of development. It's subject to change.
77

8-
Note: This code was tested on the following Node versions:
9-
- v6.10.0 (for console exporter only)
10-
- v9.8.0 (for Stackdriver and Zipkin exporters)
8+
## Installation
119

10+
Install OpenCensus Zipikin Exporter with:
11+
```bash
12+
npm install @opencensus/nodejs
13+
npm install @opencensus/exporter-zipkin
14+
```
15+
16+
## Usage
17+
18+
To use Zipkin as your exporter, first, download from any of the three available options on [Quickstart](https://zipkin.io/pages/quickstart.html): through Docker, on Java or manually compiling the source code. Tests were executed running Zipkin with Java, through the following commands on terminal:
19+
20+
```bash
21+
wget -O zipkin.jar 'https://search.maven.org/remote_content?g=io.zipkin.java&a=zipkin-server&v=LATEST&c=exec'
22+
java -jar zipkin.jar
23+
```
24+
25+
Instance the exporter on your application and pass the options. For javascript:
26+
27+
```javascript
28+
var tracing = require('@opencensus/nodejs');
29+
var zipkin = require('@opencensus/exporter-zipkin');
30+
31+
// Add your zipkin url and application name to the Zipkin options
32+
var options = {
33+
url: 'your-zipkin-url',
34+
serviceName: 'your-application-name'
35+
}
36+
var exporter = new zipkin.Zipkin(options);
37+
```
38+
39+
Similarly for Typescript:
40+
41+
```typescript
42+
import * as tracing from '@opencensus/nodejs';
43+
import { Zipkin } from '@opencensus/exporter-zipkin';
44+
45+
// Add your zipkin url and application name to the Zipkin options
46+
const options = {
47+
url: 'your-zipkin-url',
48+
serviceName: 'your-application-name'
49+
}
50+
const exporter = new Zipkin(options);
51+
```
52+
53+
Now, register the exporter and start tracing.
54+
55+
```javascript
56+
tracing.start({'exporter': exporter});
57+
```
58+
59+
or
60+
61+
```javascript
62+
tracing.registerExporter(exporter).start();
63+
```
1264

1365
## Useful links
1466
- For more information on OpenCensus, visit: <https://opencensus.io/>

0 commit comments

Comments
 (0)