Skip to content

Commit

Permalink
updated elasticsearch logger to include basic elasticsearch metadata …
Browse files Browse the repository at this point in the history
…that matches apm metadata for quick log switching between indexes
  • Loading branch information
mdebarros committed Sep 6, 2019
1 parent 19977cc commit 0e5551b
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/observables/elastic-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,30 @@
--------------
******/

const addElasticsearchMetaData = (value) => {
if (value.metadata && value.metadata.event && value.metadata.trace) {
const elasticsearchMetaData = {
'processor': {
'name': 'transaction',
'event': 'transaction'
},
'trace': {
'id': value.metadata.trace.traceId
},
'@timestamp': value.metadata.event.createdAt,
'transaction': {
'result': (value.metadata.event.state.status === 'success') ? 'success' : 'error',
'name': value.metadata.trace.service,
'id': value.metadata.trace.spanId,
'sampled': !!value.metadata.trace.sampled
}
}
return {...value, ...elasticsearchMetaData}
} else {
return value
}
}

const Rx = require('rxjs')
const { ElasticSearchClient } = require('../lib/efk')
const Logger = require('@mojaloop/central-services-shared').Logger
Expand All @@ -40,7 +64,7 @@ const elasticsearchClientObservable = ({ message }) => {
const client = await ElasticSearchClient.getInstance()
await client.index({
index: ElasticSearchClient.getIndex(),
body: message.value
body: addElasticsearchMetaData(message.value)
})
observable.complete()
} catch (e) {
Expand Down

0 comments on commit 0e5551b

Please sign in to comment.