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

added tags to spans in route handlers #200

Merged
merged 1 commit into from
Sep 19, 2019
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
64 changes: 34 additions & 30 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"@mojaloop/central-services-health": "8.1.0",
"@mojaloop/central-services-logger": "8.1.1",
"@mojaloop/central-services-metrics": "5.2.0",
"@mojaloop/central-services-shared": "8.1.0",
"@mojaloop/central-services-shared": "8.1.1",
"@mojaloop/central-services-stream": "8.1.0",
"@mojaloop/event-sdk": "8.1.0",
"@mojaloop/forensic-logging-client": "5.2.0",
Expand All @@ -90,7 +90,7 @@
"docdash": "1.1.1",
"glob": "7.1.4",
"hapi-auth-bearer-token": "6.2.1",
"hapi-swagger": "10.1.1",
"hapi-swagger": "10.1.2",
"joi-currency-code": "2.0.2",
"jsdoc": "3.6.3",
"rc": "1.2.8"
Expand All @@ -113,7 +113,7 @@
"proxyquire": "2.1.3",
"rewire": "4.0.1",
"sinon": "7.4.2",
"standard": "14.3.0",
"standard": "14.3.1",
"supertest": "4.0.2",
"tap-xunit": "2.4.1",
"tape": "4.11.0",
Expand Down
24 changes: 24 additions & 0 deletions src/api/transfers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ const Validator = require('../../lib/validator')
const Logger = require('@mojaloop/central-services-logger')
const Metrics = require('@mojaloop/central-services-metrics')
const ErrorHandler = require('@mojaloop/central-services-error-handling')
const Enum = require('@mojaloop/central-services-shared').Enum

const getSpanTags = ({ payload, headers }, transactionType, transactionAction) => {
const tags = {
transactionType,
transactionAction,
transactionId: payload.transferId,
source: headers[Enum.Http.Headers.FSPIOP.SOURCE],
destination: headers[Enum.Http.Headers.FSPIOP.DESTINATION]
}
if (payload.payerFsp && payload.payeeFsp) {
return {
...tags,
payerFsp: payload.payerFsp,
payeeFsp: payload.payeeFsp
}
} else {
return tags
}
}

/**
* @module src/api/transfers/handler
Expand All @@ -56,6 +76,7 @@ const create = async function (request, h) {

const span = request.span
try {
span.setTags(getSpanTags(request, Enum.Events.Event.Type.TRANSFER, Enum.Events.Event.Action.PREPARE))
Logger.debug('create::payload(%s)', JSON.stringify(request.payload))
Logger.debug('create::headers(%s)', JSON.stringify(request.headers))
await span.audit({
Expand Down Expand Up @@ -96,6 +117,7 @@ const fulfilTransfer = async function (request, h) {

const span = request.span
try {
span.setTags(getSpanTags(request, Enum.Events.Event.Type.TRANSFER, Enum.Events.Event.Action.COMMIT))
Validator.fulfilTransfer(request)
Logger.debug('fulfilTransfer::payload(%s)', JSON.stringify(request.payload))
Logger.debug('fulfilTransfer::headers(%s)', JSON.stringify(request.headers))
Expand Down Expand Up @@ -138,6 +160,7 @@ const getTransferById = async function (request, h) {

const span = request.span
try {
span.setTags(getSpanTags(request, Enum.Events.Event.Type.TRANSFER, Enum.Events.Event.Action.PROCESSING))
Logger.info('getById::id(%s)', request.params.id)
await span.audit({
headers: request.headers,
Expand Down Expand Up @@ -174,6 +197,7 @@ const fulfilTransferError = async function (request, h) {

const span = request.span
try {
span.setTags(getSpanTags(request, Enum.Events.Event.Type.TRANSFER, Enum.Events.Event.Action.ABORT))
Logger.debug('fulfilTransferError::payload(%s)', JSON.stringify(request.payload))
Logger.debug('fulfilTransferError::headers(%s)', JSON.stringify(request.headers))
Logger.debug('fulfilTransfer::id(%s)', request.params.id)
Expand Down
Loading