/
main.js
50 lines (43 loc) · 1.42 KB
/
main.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
'use strict';
const beeline = require('honeycomb-beeline');
beeline({
// Get this via https://ui.honeycomb.io/account after signing up for Honeycomb
writeKey: process.env.HONEYCOMB_API_KEY,
// The name of your app is a good choice to start with
dataset: process.env.HONEYCOMB_DATASET,
serviceName: process.env.SERVICE_NAME || 'node-message-service',
apiHost: process.env.HONEYCOMB_API_ENDPOINT || 'https://api.honeycomb.io',
httpTraceParserHook: beeline.w3c.httpTraceParserHook,
httpTracePropagationHook: beeline.w3c.httpTracePropagationHook,
});
const express = require('express');
// Constants
const PORT = 9000;
const HOST = '0.0.0.0';
// App
const app = express();
app.get('/message', async (req, res) => {
beeline.addContext({ name: 'Message' });
const messageSpan = beeline.startSpan({ name: 'look up message' });
const message = await determineMessage(messages);
beeline.addTraceContext({ user_message: message });
beeline.finishSpan(messageSpan);
res.send(`${message}`);
});
const messages = [
'how are you?',
'how are you doing?',
"what's good?",
"what's up?",
'how do you do?',
'sup?',
'good day to you',
'how are things?',
'howzit?',
'woohoo',
];
function determineMessage() {
return messages[Math.floor(Math.random() * messages.length)];
}
app.listen(PORT, HOST);
console.log(`Running node message service on http://${HOST}:${PORT}`);