@builtioflow/uhm-nodejs-agent
Advanced tools
Comparing version 10.16.4 to 10.17.0
@@ -15,2 +15,6 @@ "use strict"; | ||
const ignoreActions = ["start", "stop"]; | ||
const PROVIDER_CONDITION = "condition"; | ||
const PROVIDER_TYPE_GROUP = "group"; | ||
const PROVIDER_TYPE_GLOBAL_ERR_HANDLER = "global-error-handler"; | ||
const PROVIDER_STOP = "stop"; | ||
@@ -95,2 +99,3 @@ // don't use this context manager since engines are running worflows concurrently | ||
let actionList = uhmResource.actionDataList; | ||
const flowMap = actionList; | ||
if (span) { | ||
@@ -102,15 +107,12 @@ try { | ||
// -- Iterate over connector actions and prepare local span(s) | ||
const localSpans = []; | ||
let processedActions = []; | ||
actionList.forEach((action) => { | ||
const actionId = _.get(action, "actionId", ""); | ||
if (actionId && !ignoreActions.includes(action.actionId)) { | ||
if (actionId && !ignoreActions.includes(action.actionId) && !processedActions.includes(actionId) && action.name !== PROVIDER_CONDITION) { | ||
let localSpan = prepareLocalspan(action, uhmResource); | ||
localSpans.push(localSpan); | ||
processedActions.push(actionId); | ||
addChildSpans(flowMap, actionList, actionId, uhmResource, processedActions, localSpan); | ||
uhmResource._contextManager.finishSpan(localSpan); | ||
} | ||
}); | ||
if (localSpans && localSpans.length > 0) { | ||
localSpans.forEach((eachLocal) => { | ||
uhmResource._contextManager.finishSpan(eachLocal); | ||
}); | ||
} | ||
logger.debug("Connector tracing for workflow %s is finished with bill_id %s", resource.jobData.name, resource.jobData.bill_uid); | ||
@@ -187,2 +189,112 @@ } | ||
// Prepare child nodes | ||
function addChildSpans(flowMap, actionList, actionId, uhmResource, processedActions, localSpan) { | ||
let actionMap = flowMap.find((data) => data.actionId === actionId); | ||
if (actionMap.type && actionMap.type === PROVIDER_TYPE_GROUP || actionMap.type === PROVIDER_TYPE_GLOBAL_ERR_HANDLER) { | ||
handleLoop(actionList, actionId, uhmResource, flowMap, processedActions); | ||
} | ||
let nextActions = actionMap.next ? (actionMap.next).split(",") : []; | ||
let nextMatchedAction = findNextActions(nextActions, flowMap); | ||
// Recursive block for child nodes | ||
nextMatchedAction.forEach((action) => { | ||
if (action && action.actionId && action.actionId !== PROVIDER_STOP) { | ||
let actionData = actionList.find((data) => data.actionId == action.actionId); | ||
const actionId = _.get(actionData, "actionId", ""); | ||
let childSpan = prepareLocalspan(actionData, uhmResource); | ||
addChildSpans(flowMap, actionList, actionId, uhmResource, processedActions, childSpan); | ||
} else { | ||
let prevActions = actionMap.prev ? (actionMap.prev).split(",") : []; | ||
if (action && !processedActions.includes(actionId) || prevActions.length > 1) { | ||
processedActions.push(actionId); | ||
uhmResource._contextManager.finishSpan(localSpan); | ||
} | ||
} | ||
// Complete parent loop | ||
finishCurrentRootAction(localSpan, processedActions, nextMatchedAction, uhmResource); | ||
}); | ||
} | ||
// Prepare SPAN(s) for group connectors | ||
function handleLoop(actionList, groupId, uhmResource, flowMap, processedActions) { | ||
const groupActions = actionList.filter((item) => (item.group && item.group.indexOf(groupId) !== -1 && item.name !== PROVIDER_CONDITION)); | ||
let groupProcessedActions = []; | ||
if (groupActions && groupActions.length > 0) { | ||
for (let i = 0; i < groupActions.length; i++) { | ||
let action = groupActions[0]; | ||
let localSpan = prepareLocalspan(action, uhmResource); | ||
const actionId = _.get(action, "actionId", ""); | ||
groupProcessedActions.push(actionId); | ||
processedActions.push(actionId); | ||
removeIndex(actionId, groupActions); | ||
processLoopActions(localSpan, groupId, flowMap, actionList, uhmResource, actionId, groupProcessedActions, groupActions, processedActions); | ||
uhmResource._contextManager.finishSpan(localSpan); | ||
groupProcessedActions = []; | ||
i = 0; | ||
} | ||
} | ||
} | ||
// Prepare child nodes in loop | ||
function processLoopActions(localSpan, groupId, flowMap, actionList, uhmResource, actionId, groupProcessedActions, groupActions, processedActions) { | ||
let actionMap = flowMap.find((data) => data.actionId === actionId); | ||
if (actionMap.type && actionMap.type === PROVIDER_TYPE_GLOBAL_ERR_HANDLER) { | ||
handleLoop(actionList, actionId, uhmResource, flowMap, processedActions); | ||
} | ||
let nextActions = actionMap.next ? (actionMap.next).split(",") : []; | ||
let nextMatchedAction = findNextActions(nextActions, flowMap); | ||
nextMatchedAction.forEach((action) => { | ||
if (action && action.actionId && action.actionId != groupId) { | ||
let actionData = actionList.find((data) => data.actionId === action.actionId); | ||
let childSpan = prepareLocalspan(actionData, uhmResource); | ||
const actionId = _.get(actionData, "actionId", ""); | ||
removeIndex(actionId, groupActions); | ||
processLoopActions(childSpan, groupId, flowMap, actionList, uhmResource, actionId, groupProcessedActions, groupActions, processedActions); | ||
} else { | ||
let prevActions = actionMap.prev ? (actionMap.prev).split(",") : []; | ||
if (action && !groupProcessedActions.includes(action.actionId) || prevActions.length > 1) { | ||
groupProcessedActions.push(actionId); | ||
processedActions.push(actionId); | ||
uhmResource._contextManager.finishSpan(localSpan); | ||
} | ||
} | ||
// Complete parent loop | ||
finishCurrentRootAction(localSpan, groupProcessedActions, nextMatchedAction, uhmResource, processedActions); | ||
}); | ||
} | ||
function removeIndex(actionId, groupActions) { | ||
const index = groupActions.map((item) => item.actionId).indexOf(actionId); | ||
if (index !== -1) { | ||
groupActions.splice(index, 1); | ||
} | ||
} | ||
function findNextActions(nextActions, flowMap) { | ||
let nextMatchedAction = []; | ||
if (nextActions && nextActions.length > 0) { | ||
nextActions.forEach((action) => { | ||
let nextAction = flowMap.find((data) => data.actionId === action); | ||
nextAction = nextAction ? nextAction.next : ""; | ||
nextMatchedAction.push(flowMap.find((d) => d.actionId == nextAction)); | ||
}); | ||
} | ||
return nextMatchedAction; | ||
} | ||
function finishCurrentRootAction(localSpan, processedActions, nextMatchedAction, uhmResource, groupProcessedActions) { | ||
const spanActionId = localSpan._tags.find((d) => d.key === "actionId").value; | ||
if (!processedActions.includes(spanActionId) && isChildTaskFinished(nextMatchedAction, processedActions)) { | ||
processedActions.push(spanActionId); | ||
if (spanActionId.charAt(0) === "g") { | ||
groupProcessedActions.push(spanActionId); | ||
} | ||
uhmResource._contextManager.finishSpan(localSpan); | ||
} | ||
} | ||
// Check if all sub actions are processed, if yes then return true otherwise false | ||
function isChildTaskFinished(nextMatchedAction, processedActions) { | ||
return nextMatchedAction.every((action) => action !== undefined ? processedActions.includes(action.actionId) : true); | ||
} | ||
// Prepare SPAN | ||
function prepareLocalspan(action, uhmResource) { | ||
@@ -193,2 +305,4 @@ let localSpan = uhmResource._contextManager.createLocalSpan(action.name); | ||
const localSpanStatus = actionResult ? "1" : "3"; | ||
let accountName = _.get(action, "auth", ""); | ||
accountName = accountName === "" ? _.get(action, "connection", "") : accountName; | ||
Tags.TRANSACTION_STATUS.tag(localSpan, localSpanStatus); | ||
@@ -203,2 +317,4 @@ Tags.ERROR_MSG.tag(localSpan, _.get(action, "error", "")); | ||
Tags.END_TIME.tag(localSpan, convertToEpoch(_.get(action, "actionEndTime", ""))); | ||
Tags.ACTION_ID.tag(localSpan, _.get(action, "actionId", "")); | ||
Tags.ACCOUNT_NAME.tag(localSpan, accountName); | ||
return localSpan; | ||
@@ -205,0 +321,0 @@ } |
@@ -44,2 +44,4 @@ /* | ||
this.PROVIDER_VERSION = new Tag("pversion"); | ||
this.ACTION_ID = new Tag("actionId"); | ||
this.ACCOUNT_NAME = new Tag("accountName"); | ||
}; | ||
@@ -46,0 +48,0 @@ |
{ | ||
"name": "@builtioflow/uhm-nodejs-agent", | ||
"version": "10.16.4", | ||
"version": "10.17.0", | ||
"description": "A nodejs agent for skyapm agents", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 9 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
597490
15983
59