-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
89 lines (68 loc) · 1.91 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// This is where the application starts
// Initialize the express framework so we can use it to handle routes
const opentracing = require('opentracing');
const app = require('express')();
const initTracer = require('jaeger-client').initTracer;
const PrometheusMetricsFactory = require('jaeger-client').PrometheusMetricsFactory;
const promClient = require('prom-client');
const metrics = new PrometheusMetricsFactory(promClient, 'test');
const config = {
serviceName: 'JSAPI',
sampler: {
type: 'const',
param: 1
},
reporter:{
logSpans: true
// agentHost: 'localhost',
// agentPort: 5775
}
};
const options = {
logger: {
info(msg) {
console.log("INFO", msg)
},
error(msg) {
console.log("ERROR", msg)
}
},
tags: {
'JSAPI.version': '0.0.1',
},
metrics: metrics,
};
let tracer = initTracer(config, options);
console.log(tracer);
// Body Parser allows us to get stuff out of Post requests
const bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/', (req, res) => {
res.status(200).send('reguler')
});
//const context = tracer.extract(opentracing.FORMAT_HTTP_HEADERS, headers);
// Basic get Route
app.get('/hello', (req, res) => {
// req is the request and res is the response.
let span = tracer.startSpan('JSAPI');
span.finish();
console.log('What');
// End the route with a response
tracer.close();
res.status(200).send('Hello');
});
// Basic Post Route
app.post('/addNewItem', (req, res) => {
// req is the request and res is the response.
console.log('Post Request received');
// Get the name of the item from the request body
let itemToBeAdded = req.body.itemName;
console.log('Item to be added:', itemToBeAdded);
// End the route with a response
res.status(200).send('Good Post Request');
});
// Starts the app listening on port 3000
app.listen(3000, () => {
console.log('Listening on port 3000');
});