Skip to content

Commit

Permalink
taking care of loose spans
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin committed Jan 24, 2020
1 parent 098d4d8 commit 41a4b6d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/event-stream-processor",
"version": "8.8.0-snapshot.1",
"version": "8.8.0-snapshot.2",
"description": "event stream processor to monitor kafka event topic and create traces and store logs to efk stack with APM",
"main": "app.js",
"scripts": {
Expand Down
16 changes: 16 additions & 0 deletions src/observables/apmTracerObservable.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,28 @@ const recreateTraceObservable = ({ traceId, tags }) => {
return Rx.Observable.create(async observable => {
try {
const cachedTrace = (await client.get(key)).item

const findLooseSpans = (parentSpan, currentSpan = null) => {
const looseSpans = []
for (const span of Object.values(cachedTrace.spans)) {
if (span.spanContext.parentSpanId === parentSpan.spanContext.spanId && (!currentSpan || (span.spanContext.spanId !== currentSpan.spanContext.spanId))) {
looseSpans.push(span)
delete cachedTrace.spans[span.spanContext.spanId]
}
}
return looseSpans
}

if (cachedTrace.lastSpan && cachedTrace.masterSpan) {
let currentSpan = cachedTrace.spans[cachedTrace.lastSpan.spanId]
const resultTrace = [currentSpan]
const looseSpansOfLastSpan = findLooseSpans(currentSpan)
looseSpansOfLastSpan.forEach(span => resultTrace.push(span))
for (let i = 0; i < Object.keys(cachedTrace.spans).length; i++) {
const parentSpan = cachedTrace.spans[currentSpan.spanContext.parentSpanId]
if (!parentSpan) break
const looseSpans = findLooseSpans(parentSpan, currentSpan)
looseSpans.forEach(span => resultTrace.unshift(span))
resultTrace.unshift(parentSpan)
currentSpan = parentSpan
}
Expand Down
1 change: 0 additions & 1 deletion src/observables/elastic-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const Logger = require('@mojaloop/central-services-logger')
const elasticsearchClientObservable = ({ message }) => {
return Rx.Observable.create(async observable => {
try {
Logger.info(`EFK request time:: ${new Date().toISOString()}`)
const client = await ElasticSearchClient.getInstance()
await client.index({
index: ElasticSearchClient.getIndex(),
Expand Down

0 comments on commit 41a4b6d

Please sign in to comment.