Source:
<code>public void onNewHead(FlowNode flowNode) { DatadogClient client = ClientFactory.getClient(); if (client == null){ return; } client.sendPipelineTrace(runFor(flowNode.getExecution()), flowNode); if (!isMonitored(flowNode)) { return; } StepEndNode endNode = (StepEndNode) flowNode; StepStartNode startNode = endNode.getStartNode(); int stageDepth = 0; String directParentName = null; for (BlockStartNode node : startNode.iterateEnclosingBlocks()) { if (DatadogUtilities.isStageNode(node)) { if(directParentName == null){ directParentName = getStageName(node); } stageDepth++; } } if(directParentName == null){ directParentName = "root"; } WorkflowRun run = getRun(flowNode); if(run == null){ return; } try { String result = DatadogUtilities.getResultTag(endNode); BuildData buildData = new BuildData(run, flowNode.getExecution().getOwner().getListener()); String hostname = buildData.getHostname(""); Map<String, Set<String>> tags = buildData.getTags(); TagsUtil.addTagToTags(tags, "stage_name", getStageName(startNode)); TagsUtil.addTagToTags(tags, "parent_stage_name", directParentName); TagsUtil.addTagToTags(tags, "stage_depth", String.valueOf(stageDepth)); TagsUtil.addTagToTags(tags, "result", result); client.gauge("jenkins.job.stage_duration", getTime(startNode, endNode), hostname, tags); <START> client.gauge("jenkins.job.stage_completed", 1, hostname, tags); <END> } catch (IOException | InterruptedException e) { DatadogUtilities.severe(logger, e, "Unable to submit the stage duration metric for " + getStageName(startNode)); } }</code><technical_language>suggestion client.incrementCounter("jenkins.job.stage_completed", hostname, tags);</technical_language>

Target:
public void onNewHead(FlowNode flowNode) { DatadogClient client = ClientFactory.getClient(); if (client == null){ return; } client.sendPipelineTrace(runFor(flowNode.getExecution()), flowNode); if (!isMonitored(flowNode)) { return; } StepEndNode endNode = (StepEndNode) flowNode; StepStartNode startNode = endNode.getStartNode(); int stageDepth = 0; String directParentName = null; for (BlockStartNode node : startNode.iterateEnclosingBlocks()) { if (DatadogUtilities.isStageNode(node)) { if(directParentName == null){ directParentName = getStageName(node); } stageDepth++; } } if(directParentName == null){ directParentName = "root"; } WorkflowRun run = getRun(flowNode); if(run == null){ return; } try { String result = DatadogUtilities.getResultTag(endNode); BuildData buildData = new BuildData(run, flowNode.getExecution().getOwner().getListener()); String hostname = buildData.getHostname(""); Map<String, Set<String>> tags = buildData.getTags(); TagsUtil.addTagToTags(tags, "stage_name", getStageName(startNode)); TagsUtil.addTagToTags(tags, "parent_stage_name", directParentName); TagsUtil.addTagToTags(tags, "stage_depth", String.valueOf(stageDepth)); TagsUtil.addTagToTags(tags, "result", result); client.gauge("jenkins.job.stage_duration", getTime(startNode, endNode), hostname, tags); client.incrementCounter("jenkins.job.stage_completed", hostname, tags); } catch (IOException | InterruptedException e) { DatadogUtilities.severe(logger, e, "Unable to submit the stage duration metric for " + getStageName(startNode)); } }