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

Commit e1dce19

Browse files
committed
Update example README.md
1 parent 5034618 commit e1dce19

1 file changed

Lines changed: 72 additions & 29 deletions

File tree

examples/README.md

Lines changed: 72 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,24 @@ Note: This code was tested on the following Node versions:
55
- v6.10.0 (for console exporter only)
66
- v9.8.0 (for Stackdriver and Zipkin exporters)
77

8+
At this momment the automatic instrumetation is only for apps using http and mongo-db.
9+
810
___
911

1012
## Setup
1113

12-
1. Clone the OpenCensus Node repository **TODO link to repository**
13-
<>
14+
1. Clone the OpenCensus Node repository https://github.com/census-instrumentation/opencensus-node.git
15+
```bash
16+
git clone https://github.com/census-instrumentation/opencensus-node.git
17+
cd opencensus-node
18+
```
1419

1520
2. Switch to branch `dev` with:
1621
```bash
1722
git checkout dev
1823
```
1924

20-
3. Navigate to the OpenCensus Node project folder and install the dependencies with:
25+
3. Install the dependencies with:
2126
```bash
2227
npm install
2328
```
@@ -27,38 +32,68 @@ npm install
2732
node_modules/.bin/tsc
2833
```
2934

30-
5. Clone the application we will instrument (EasyNotes Application)
31-
<https://github.com/callicoder/node-easy-notes-app>
35+
5. In a different folder, clone the example application to be instrumented (EasyNotes Application)
36+
```bash
37+
git clone https://github.com/callicoder/node-easy-notes-app
38+
```
3239

3340
6. Navigate to the application folder and install the dependencies with:
3441
```bash
42+
cd node-easy-notes-app
3543
npm install
3644
```
3745

38-
7. Navigate to the `node_modules` folder inside the EasyNotes application and create a link to OpenCensus Node project folder with:
46+
7. Check if the app is running. PS.: a mongodb installation is required
3947
```bash
48+
$ node server.js
49+
Server is listening on port 3000
50+
Successfully connected to the database
51+
```
52+
53+
## Add opencensus instrumentation
54+
55+
To add opencensus instrumetation, follow the step below:
56+
57+
1. Navigate to the `node_modules` folder inside the EasyNotes application and create a link to OpenCensus Node project folder with:
58+
```bash
59+
cd node_modules
4060
ln -s <your path>/opencensus-node/build/src opencensus-nodejs
61+
cd ..
4162
```
4263

64+
2. Edit server.js and add the following line, as the first line of the file:
65+
```javascript
66+
var tracing = require("opencensus-nodejs").start()
67+
...
68+
var express = require('express');
69+
```
4370

44-
## Instrument using Stackdriver
4571

46-
1. Make sure you enabled Stackdriver Tracing on Google Cloud Platform. More info at <https://cloud.google.com/trace/docs/quickstart>
72+
## Running the Instrumented Application
73+
74+
Save the file server.js and run the app with debugging option.
4775

48-
2. Enable Application Default Credentials for authentication with:
4976
```bash
50-
export GOOGLE_APPLICATION_CREDENTIALS=path/to/your/credential.json
77+
$ DEBUG=opencensus node server.js
78+
opencensus useAsyncHooks = true +0ms
79+
opencensus patching http@9.8.0 module +75ms
80+
opencensus patching http.Server.prototype.emit function +7ms
81+
....
82+
Server is listening on port 3000
83+
Successfully connected to the database
5184
```
52-
More information at <https://cloud.google.com/docs/authentication/getting-started>
85+
This options uses a default exporter to console.
5386

54-
3. Open the `server.js` file in the EasyNotes application and insert this code on top:
55-
```javascript
56-
var traceMng = require("opencensus-nodejs")
57-
.addStackdriver("your-project-id")
58-
.start();
87+
To test de api you can use the commands:
88+
```bash
89+
#To insert a note:
90+
curl -X POST http://localhost:3000/notes --data '{"title": "Note 1", "content": "this is the note content"}' -H "Content-Type: application/json"
91+
92+
#To get notes:
93+
curl http://localhost:3000/notes
5994
```
6095

61-
## Instrument using Zipkin
96+
## Exporting to Zipkins
6297

6398
1. Download Zipkin choosing one 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:
6499
```bash
@@ -73,7 +108,26 @@ var tracing = require("opencensus-nodejs")
73108
.start()
74109
```
75110

76-
## Instrumenting with multiple Exporters
111+
112+
## Exporting to Stackdriver
113+
114+
1. Make sure you enabled Stackdriver Tracing on Google Cloud Platform. More info at <https://cloud.google.com/trace/docs/quickstart>
115+
116+
2. Enable Application Default Credentials for authentication with:
117+
```bash
118+
export GOOGLE_APPLICATION_CREDENTIALS=path/to/your/credential.json
119+
```
120+
More information at <https://cloud.google.com/docs/authentication/getting-started>
121+
122+
3. Open the `server.js` file in the EasyNotes application and insert this code on top:
123+
```javascript
124+
var traceMng = require("opencensus-nodejs")
125+
.addStackdriver("your-project-id")
126+
.start();
127+
```
128+
129+
130+
## Exporting to multiple Exporters
77131

78132
It is possible to instrument with more than one code. To achieve this, simply add more than one Exporter in series.
79133

@@ -83,14 +137,3 @@ var tracing = require("opencensus-nodejs")
83137
.addStackdriver("your-project")
84138
.start()
85139
```
86-
87-
## Running the Instrumented Application
88-
89-
It is possible both to run with debugging information and without it. To run with debugging information use:
90-
```bash
91-
DEBUG=opencensus node server.js
92-
```
93-
To run without debugging information, simply use:
94-
```bash
95-
node server.js
96-
```

0 commit comments

Comments
 (0)