|
1 | | -# OpenCensus Libraries for Node.js |
| 1 | +# OpenCensus Core Node.js |
2 | 2 | [![Gitter chat][gitter-image]][gitter-url] |
3 | 3 |
|
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 mongodb. |
| 4 | +OpenCensus for Node.js is an implementation of OpenCensus, a toolkit for collecting application performance and behavior monitoring data. |
5 | 5 |
|
6 | 6 | The library is in alpha stage and the API is subject to change. |
7 | 7 |
|
8 | 8 | Please join [gitter](https://gitter.im/census-instrumentation/Lobby) for help or feedback on this project. |
9 | 9 |
|
10 | | -Note: This code was tested on the following Node versions: |
11 | | -- v6.10.0 (for console exporter only) |
12 | | -- v9.8.0 (for Stackdriver and Zipkin exporters) |
13 | | - |
14 | | -___ |
15 | | - |
16 | | -## OpenCensus Setup |
17 | | - |
18 | | -1. Clone the OpenCensus Node repository < https://github.com/census-instrumentation/opencensus-node.git> |
19 | | -```bash |
20 | | -git clone https://github.com/census-instrumentation/opencensus-node.git |
21 | | -``` |
22 | | - |
23 | | -**TODO Ver com Fábio se o usuário terá que compilar** |
24 | | - |
25 | | -2. Switch to branch `dev` with: |
26 | | -```bash |
27 | | -git checkout dev |
28 | | -``` |
29 | | - |
30 | | -3. Navigate to the OpenCensus Node project folder and install the dependencies with: |
31 | | -```bash |
32 | | -cd opencensus-node |
33 | | -npm install |
34 | | -``` |
35 | | - |
36 | | -4. Compile the TypeScript code into JavaScript with: |
37 | | -``` |
38 | | -node_modules/.bin/tsc |
39 | | -``` |
40 | | - |
41 | | -___ |
42 | | - |
43 | | -## Instrumenting an Application |
44 | | - |
45 | | -Navigate to your application folder. Inside it's `node_modules` folder, create a directory named `@opencensus`: |
46 | | -``` |
47 | | -cd node_modules |
48 | | -mkdir @opencensus |
49 | | -``` |
50 | | - |
51 | | -Navigate to your new `@opencensus` folder and create a symlink to OpenCensus Node package with: |
52 | | -```bash |
53 | | -cd @opencensus |
54 | | -ln -s <path-to-opencensus-dir>/packages/opencensus-nodejs/ opencensus-nodejs |
55 | | -``` |
56 | | - |
57 | | -### Using Stackdriver Exporter |
58 | | - |
59 | | -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: |
60 | | -```bash |
61 | | -export GOOGLE_APPLICATION_CREDENTIALS=path/to/your/credential.json |
62 | | -``` |
63 | | - |
64 | | -Add the OpenCensus Stackdriver Exporter package to your project's `node_modules/@opencensus` folder with: |
65 | | -``` |
66 | | -cd node_modules/@opencensus |
67 | | -ln -s <path-to-opencensus-dir>/packages/opencensus-exporter-stackdriver/ opencensus-exporter-stackdriver |
68 | | -``` |
69 | | - |
70 | | -Finally, on top of your application, add the following lines of code: |
71 | | -```javascript |
72 | | -var tracing = require('@opencensus/opencensus-nodejs'); |
73 | | -var stackdriver = require('@opencensus/opencensus-exporter-stackdriver'); |
74 | | - |
75 | | -// Add your project id to the Stackdriver options |
76 | | -var options = new stackdriver.StackdriverOptions('your-project-id'); |
77 | | -var exporter = new stackdriver.Stackdriver(options); |
78 | | - |
79 | | -tracing.registerExporter(exporter).start(); |
80 | | -``` |
81 | | - |
82 | | -### Using Zipkin Exporter |
83 | | - |
84 | | -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: |
85 | | -```bash |
86 | | -wget -O zipkin.jar 'https://search.maven.org/remote_content?g=io.zipkin.java&a=zipkin-server&v=LATEST&c=exec' |
87 | | -java -jar zipkin.jar |
88 | | -``` |
89 | | - |
90 | | -Add the OpenCensus Zipkin Exporter package to your project's `node_modules/@opencensus` folder with: |
91 | | -``` |
92 | | -cd node_modules/@opencensus |
93 | | -ln -s <path-to-opencensus-dir>/packages/opencensus-exporter-zipkin/ opencensus-exporter-zipkin |
94 | | -``` |
95 | | - |
96 | | -Finally, on top of your application, add the following lines of code: |
97 | | -```javascript |
98 | | -var tracing = require('@opencensus/opencensus-nodejs'); |
99 | | -var zipkin = require('@opencensus/opencensus-exporter-zipkin'); |
100 | | - |
101 | | -// Add your zipkin url and application name to the Zipkin options |
102 | | -var options = new zipkin.ZipkinOptions("your-zipkin-url", "your-application-name") |
103 | | -var exporter = new zipkin.Zipkin(options); |
104 | | - |
105 | | -tracing.registerExporter(exporter).start(); |
106 | | -``` |
| 10 | +## Useful links |
| 11 | +- 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> |
| 13 | +- For help or feedback on this project, join us on [gitter](https://gitter.im/census-instrumentation/Lobby) |
107 | 14 |
|
108 | 15 | [gitter-image]: https://badges.gitter.im/census-instrumentation/lobby.svg |
109 | 16 | [gitter-url]: https://gitter.im/census-instrumentation/lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge |
|
0 commit comments