Created
February 22, 2018 16:14
-
-
Save BransonGitomeh/f1ea4de9b18525262ee85c149f6d9e0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
listening on 3210 | |
calling hemera with { traceId: '0f616dd8a5077b9e' } | |
[2018-02-22T16:11:51.209Z] DEBUG (hemera-bran-pc-e09d40077e17487bbd2dd6905e6e95a8/11868 on bran-pc): sendClientSend | |
plugin: "hemera-zipkin" | |
traceData: { | |
"traceId": "0f616dd8a5077b9e", | |
"spanId": "98a8fb154eb44934b5a7bcbe461e8a63", | |
"sampled": true | |
} | |
meta: { | |
"service": "math-service", | |
"name": "a:1,b:2,cmd:add,topic:math", | |
"binaryAnnotations": { | |
"rpc.topic": "math", | |
"rpc.method": "a:1,b:2,cmd:add,topic:math", | |
"rpc.timeout": 2000, | |
"rpc.maxMessages": 0, | |
"rpc.pubsub": false | |
} | |
} | |
[2018-02-22T16:11:51.210Z] DEBUG (hemera-bran-pc-e09d40077e17487bbd2dd6905e6e95a8/11868 on bran-pc): | |
outbound: { | |
"id": "f218a767afc844dd954ad3c8f2e5c5dd", | |
"pattern": "a:1,b:2,cmd:add,topic:math" | |
} | |
[2018-02-22T16:11:51.217Z] DEBUG (hemera-bran-pc-e09d40077e17487bbd2dd6905e6e95a8/11868 on bran-pc): sendServerRecv | |
plugin: "hemera-zipkin" | |
traceData: { | |
"traceId": "0f616dd8a5077b9e", | |
"spanId": "98a8fb154eb44934b5a7bcbe461e8a63", | |
"timestamp": 32728774208279, | |
"sampled": true | |
} | |
meta: { | |
"service": "math-service", | |
"name": "a:1,b:2,cmd:add,topic:math", | |
"binaryAnnotations": { | |
"server.topic": "math", | |
"server.maxMessages": 0, | |
"server.pubsub": false | |
} | |
} | |
[2018-02-22T16:11:51.220Z] DEBUG (hemera-bran-pc-e09d40077e17487bbd2dd6905e6e95a8/11868 on bran-pc): sendServerSend | |
plugin: "hemera-zipkin" | |
traceData: { | |
"traceId": "0f616dd8a5077b9e", | |
"spanId": "98a8fb154eb44934b5a7bcbe461e8a63", | |
"timestamp": 32728774208279, | |
"sampled": true | |
} | |
meta: { | |
"service": "math-service", | |
"name": "a:1,b:2,cmd:add,topic:math", | |
"binaryAnnotations": { | |
"server.topic": "math", | |
"server.maxMessages": 0, | |
"server.pubsub": false | |
} | |
} | |
[2018-02-22T16:11:51.224Z] DEBUG (hemera-bran-pc-e09d40077e17487bbd2dd6905e6e95a8/11868 on bran-pc): | |
inbound: { | |
"id": "f218a767afc844dd954ad3c8f2e5c5dd", | |
"duration": "15.81ms", | |
"pattern": "a:1,b:2,cmd:add,topic:math" | |
} | |
[2018-02-22T16:11:51.225Z] DEBUG (hemera-bran-pc-e09d40077e17487bbd2dd6905e6e95a8/11868 on bran-pc): sendClientRecv | |
plugin: "hemera-zipkin" | |
traceData: { | |
"traceId": "0f616dd8a5077b9e", | |
"spanId": "98a8fb154eb44934b5a7bcbe461e8a63", | |
"sampled": true | |
} | |
meta: { | |
"service": "math-service", | |
"name": "a:1,b:2,cmd:add,topic:math", | |
"binaryAnnotations": {} | |
} | |
GET / 200 10 - 34.599 ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const morgan = require('morgan'); | |
const { | |
Tracer, | |
BatchRecorder, | |
jsonEncoder: { JSON_V2 }, | |
} = require('zipkin'); | |
const zipkinMiddleware = require('zipkin-instrumentation-express').expressMiddleware; | |
const CLSContext = require('zipkin-context-cls'); | |
const { HttpLogger } = require('zipkin-transport-http'); | |
const hemeraZipkin = require('hemera-zipkin'); | |
const localServiceName = 'gateway'; | |
const tracer = new Tracer({ | |
ctxImpl: new CLSContext('zipkin'), | |
recorder: new BatchRecorder({ | |
logger: new HttpLogger({ | |
endpoint: 'http://localhost:9411/api/v2/spans', | |
jsonEncoder: JSON_V2, | |
}), | |
}), | |
localServiceName, | |
}); | |
const app = express(); | |
app.use(morgan('tiny')); | |
const Hemera = require('nats-hemera'); | |
const nats = require('nats').connect(); | |
const hemera = new Hemera(nats, { | |
logLevel: 'trace', | |
childLogger: true, | |
tag: 'math-service', | |
}); | |
hemera.use(hemeraZipkin, { | |
debug: false, | |
host: 'localhost', | |
port: '9411', | |
path: '/api/v1/spans', | |
subscriptionBased: false, | |
sampling: 1, | |
}); | |
hemera.ready(async () => { | |
hemera.add({ topic: 'math', cmd: 'add' }, async resp => resp.a + resp.b); | |
// Add the Zipkin middleware | |
app.use(zipkinMiddleware({ tracer })); | |
app.get('/', async (req, res) => { | |
const { traceId } = tracer.id; | |
console.log('calling hemera with', { traceId }); | |
const math = await hemera.act({ | |
trace$: { | |
traceId, | |
}, | |
topic: 'math', | |
cmd: 'add', | |
a: 1, | |
b: 2, | |
}); | |
res.send({ math }); | |
}); | |
app.listen('3210', () => console.log('listening on 3210')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment