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

Proof of Design Implementation of a first design proposal for opencensus-nodejs #1

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
7468f39
PoD(Proof Of Design) - v0
silva-fabio Mar 20, 2018
5fa79ac
Added basic structure of tests
djonathascardoso Mar 20, 2018
905cd8d
finished test-trace
djonathascardoso Mar 21, 2018
26844f1
added new tests in test-trace
djonathascardoso Mar 21, 2018
4e47d54
Add unit tests for span.ts
luanamartinssantos Mar 21, 2018
3d7e19b
Merge branch 'OP-30' of https://gitlab.cesar.org.br/opencensus/opence…
luanamartinssantos Mar 21, 2018
4ebfa0a
finished test-tracemanager
djonathascardoso Mar 21, 2018
002bf48
Merge branch 'OP-30' of https://gitlab.cesar.org.br/opencensus/opence…
luanamartinssantos Mar 21, 2018
2bd955a
Add initial Stackdriver exporter
eduardoemery Mar 22, 2018
edddb85
added test-tracemanager
djonathascardoso Mar 22, 2018
caedca1
finished interfaces creation
djonathascardoso Mar 22, 2018
a1a6311
added zipkin files
djonathascardoso Mar 22, 2018
9794455
Fix end trace
eduardoemery Mar 22, 2018
4fe6771
Add interfaces
eduardoemery Mar 22, 2018
d93d595
Add license on the unit tests
luanamartinssantos Mar 22, 2018
75e1f5a
Fix stackdriver auth and ignores tracing for Google API
eduardoemery Mar 22, 2018
415d618
Merge branch 'OP-30' into 'dev'
silva-fabio Mar 22, 2018
b56ae29
Merge branch 'OP-31' into dev
silva-fabio Mar 22, 2018
3f2beb2
Changing class name TraceManger to Tracer, creating class Tracing. Mo…
silva-fabio Mar 23, 2018
87fc0ee
Changing class name TraceManger to Tracer, creating class Tracing. Mo…
silva-fabio Mar 23, 2018
77c6e99
Refactoring test classes to the new clases names
silva-fabio Mar 23, 2018
b92fc46
Send real data to Stackdriver and create registerExporter method
eduardoemery Mar 23, 2018
1c3a5c6
traceId logic update
silva-fabio Mar 23, 2018
f732471
Fix root span dispatch
eduardoemery Mar 23, 2018
555d337
Fix code style.
eldreygalindo Mar 23, 2018
d6179ee
Merge branch 'OP-31.v2' of gitlab.cesar.org.br:opencensus/opencensus-…
eldreygalindo Mar 23, 2018
163a8e6
Make spans in a trace private
eduardoemery Mar 23, 2018
763a7d1
Add start methods for Stackdriver and Zipkin
eduardoemery Mar 23, 2018
2dba623
Merge branch 'OP-31.v2' into 'dev'
silva-fabio Mar 23, 2018
d2bfb6b
added basic struct
djonathascardoso Mar 23, 2018
3e80e1f
finished zipkin basic implementation
djonathascardoso Mar 23, 2018
23f31e1
Merge branch 'OP-34' into 'dev'
silva-fabio Mar 24, 2018
8aba0c7
Refactoring: rename class and file Trace to RootSpan, add TraceConfig…
silva-fabio Mar 25, 2018
4e1959b
More refactorings, add endspan event listener, correct bug in zipkin …
silva-fabio Mar 25, 2018
cc50e42
Fix zipkin export bug time and duration
silva-fabio Mar 27, 2018
00d6b27
Change startRootSpan to deal with context
silva-fabio Mar 29, 2018
249b90a
Change startRootSpan to deal with context
silva-fabio Mar 29, 2018
2dc8892
Merge branch 'dev' of gitlab.cesar.org.br:opencensus/opencensus-node …
silva-fabio Mar 29, 2018
a49a3c8
Add validation to root span creation
silva-fabio Mar 29, 2018
7ff552a
Add wrapEmitter to req and res, Improving debug mensages
silva-fabio Mar 29, 2018
a0dca87
Fixed zipkin url configuration
djonathas Mar 29, 2018
4f92ad1
Merge branch 'dev' of https://gitlab.cesar.org.br/opencensus/opencens…
djonathas Mar 29, 2018
3e8aff4
Add a README.md for the OpenCensus Node example
eduardoemery Mar 29, 2018
01be637
Merge branch 'hotfix-readme' into 'dev'
silva-fabio Mar 29, 2018
fe9257a
Adapted tests for dev
djonathas Mar 29, 2018
926d4d9
Update example README.md
silva-fabio Mar 29, 2018
6cd4561
Add design doc
silva-fabio Mar 29, 2018
973ccfc
Merge branch 'OP-30.v3' into 'dev'
silva-fabio Mar 30, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,16 @@ bin
# Vim
.swp

#VScode
.vscode/

# Other
TAGS

# nodejs
node_modules/
npm-debug.log
.nyc_output/
build/


Binary file not shown.
139 changes: 139 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# OpenCensus Node.js Example


Note: This code was tested on the following Node versions:
- v6.10.0 (for console exporter only)
- v9.8.0 (for Stackdriver and Zipkin exporters)

At this momment the automatic instrumetation is only for apps using http and mongo-db.

___

## Setup

1. Clone the OpenCensus Node repository https://github.com/census-instrumentation/opencensus-node.git
```bash
git clone https://github.com/census-instrumentation/opencensus-node.git
cd opencensus-node
```

2. Switch to branch `dev` with:
```bash
git checkout dev
```

3. Install the dependencies with:
```bash
npm install
```

4. Compile the TypeScript code into JavaScript with:
```
node_modules/.bin/tsc
```

5. In a different folder, clone the example application to be instrumented (EasyNotes Application)
```bash
git clone https://github.com/callicoder/node-easy-notes-app
```

6. Navigate to the application folder and install the dependencies with:
```bash
cd node-easy-notes-app
npm install
```

7. Check if the app is running. PS.: a mongodb installation is required
```bash
$ node server.js
Server is listening on port 3000
Successfully connected to the database
```

## Add opencensus instrumentation

To add opencensus instrumetation, follow the step below:

1. Navigate to the `node_modules` folder inside the EasyNotes application and create a link to OpenCensus Node project folder with:
```bash
cd node_modules
ln -s <your path>/opencensus-node/build/src opencensus-nodejs
cd ..
```

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


## Running the Instrumented Application

Save the file server.js and run the app with debugging option.

```bash
$ DEBUG=opencensus node server.js
opencensus useAsyncHooks = true +0ms
opencensus patching [email protected] module +75ms
opencensus patching http.Server.prototype.emit function +7ms
....
Server is listening on port 3000
Successfully connected to the database
```
This options uses a default exporter to console.

To test de api you can use the commands:
```bash
#To insert a note:
curl -X POST http://localhost:3000/notes --data '{"title": "Note 1", "content": "this is the note content"}' -H "Content-Type: application/json"

#To get notes:
curl http://localhost:3000/notes
```

## Exporting to Zipkins

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:
```bash
wget -O zipkin.jar 'https://search.maven.org/remote_content?g=io.zipkin.java&a=zipkin-server&v=LATEST&c=exec'
java -jar zipkin.jar
```

2. Open the `server.js` file in the EasyNotes application and insert this code on top:
```javascript
var tracing = require("opencensus-nodejs")
.addZipkin("http://localhost:9411/api/v2/spans", "easy-notes")
.start()
```


## Exporting to Stackdriver

1. Make sure you enabled Stackdriver Tracing on Google Cloud Platform. More info at <https://cloud.google.com/trace/docs/quickstart>

2. Enable Application Default Credentials for authentication with:
```bash
export GOOGLE_APPLICATION_CREDENTIALS=path/to/your/credential.json
```
More information at <https://cloud.google.com/docs/authentication/getting-started>

3. Open the `server.js` file in the EasyNotes application and insert this code on top:
```javascript
var traceMng = require("opencensus-nodejs")
.addStackdriver("your-project-id")
.start();
```


## Exporting to multiple Exporters

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

```javascript
var tracing = require("opencensus-nodejs")
.addZipkin(“http://localhost:9411/api/v2/spans“, "easy-notes")
.addStackdriver("your-project")
.start()
```
Loading