Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improvement on log and trace usage. #68

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 7 additions & 10 deletions OTEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,14 @@ const exporter = new JaegerExporter({

7. Deploy the example to OpenShift local

* Uncomment the `require('./tracing.js');` on `frontend/app.js`
* Uncomment the `require('./tracing.js');` on `worker/app.js`

```
$ oc create -f service.amqp.yaml
$ cd frontend
$ npm install
$ npm run openshift
$ cd ../worker
$ npm install
$ npm run openshift
oc create -f service.amqp.yaml
cd frontend
npm install
npm run openshift:enable:trace
cd ../worker
npm install
npm run openshift:enable:trace
```

8. When you login on Jaeger UI you can see the result like this:
Expand Down
14 changes: 7 additions & 7 deletions frontend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
*/

// require('./tracing.js');
const logger = require('./logger.js');

const path = require('path');
const crypto = require('crypto');
Expand All @@ -34,7 +34,7 @@ let amqpConnectionBindings;
try {
amqpConnectionBindings = serviceBindings.getBinding('AMQP', 'rhea');
} catch (err) {
console.log(err);
logger.error(err);
amqpConnectionBindings = {
host: process.env.MESSAGING_SERVICE_HOST || 'localhost',
port: process.env.MESSAGING_SERVICE_PORT || 5672,
Expand Down Expand Up @@ -68,12 +68,12 @@ function sendRequests () {

requestSender.send(message);

console.log(`${id}: Sent request ${JSON.stringify(message)}`);
logger.info(`${id}: Sent request ${JSON.stringify(message)}`);
}
}

container.on('connection_open', event => {
console.log(
logger.info(
`${id}: Connected to AMQP messaging service at ${amqpConnectionBindings.host}:${amqpConnectionBindings.port}`
);
requestSender = event.connection.open_sender('requests');
Expand Down Expand Up @@ -102,7 +102,7 @@ container.on('message', event => {
if (event.receiver === responseReceiver) {
const response = event.message;

console.log(`${id}: Received response ${response}`);
logger.info(`${id}: Received response ${response}`);

responses[response.correlation_id] = {
requestId: response.correlation_id,
Expand All @@ -113,10 +113,10 @@ container.on('message', event => {
});

container.on('error', err => {
console.log(err);
logger.info(err);
});

console.log(
logger.info(
`${id}: Attempting to connect to AMQP messaging service at ${amqpConnectionBindings.host}:${amqpConnectionBindings.port}`
);
container.connect(amqpConnectionBindings);
Expand Down
13 changes: 3 additions & 10 deletions frontend/bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,7 @@
/**
* Module dependencies.
*/
const pinoDebug = require('pino-debug');
const pino = require('pino');
const logger = pino({
transport: {
target: 'pino-pretty'
}
});
pinoDebug(logger);
const logger = require('../logger.js');

const app = require('../app');
const http = require('http');
Expand Down Expand Up @@ -92,10 +85,10 @@ function onError (error) {
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
logger.error(bind + ' requires elevated privileges');
process.exit(1);
case 'EADDRINUSE':
console.error(bind + ' is already in use');
logger.error(bind + ' is already in use');
process.exit(1);
default:
throw error;
Expand Down
3 changes: 3 additions & 0 deletions frontend/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const pino = require('pino');

module.exports = pino({});
Loading