Skip to content

Commit

Permalink
Fix for issue: azure-ad-b2c#64
Browse files Browse the repository at this point in the history
Observations from testing:
- The application insights does not return the results in the same order as viewing in Azure Portal application insights when the times are identical
- A single application insights entity can span more than 2 write entries, sometime we need to combine 3 or 4 together
- Sometimes application insights entities can have the extact same time (and therefore shoud NOT be combined)

Fixes applied:
- Add the id to the sort of the api call, that way all entries that are to be combined will be next to each other in the array
- The logic for combining the step labels to be display did not take into account the order of the two entries to be combined
- Moved the text "The report shows......" to only be added after the last entry is combined (in cases where 3 or 4 application insights entries)
- To handle where there are 3 or 4 entries to combine, after we combine the first 2 we move back up the loop (i--) again and check if there are more entries that need to be combined for this entry
e.g. When 4 entries to combine, [A, B, C, D]
 [A + B, delete B, i--
 [AB + C, delete C, i--
 [ABC + D, delete D, i--
 [ABCD] no action
  • Loading branch information
Viper61x23 committed Mar 25, 2022
1 parent a4bb294 commit 543245f
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/ApplicationInsightsExplorerExplorerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default class ApplicationInsightsExplorerExplorerProvider implements vsco
+ '/events/traces?timespan=' + timespan + "PT" + config.duration + 'H'
+ "&$filter=startswith(customDimensions/EventName, 'Journey Recorder')"
+ '&$top=' + config.maxRows
+ '&$orderby=timestamp desc&$select=id,timestamp,cloud/roleInstance,trace/message,customDimensions'
+ '&$orderby=timestamp desc,id&$select=id,timestamp,cloud/roleInstance,trace/message,customDimensions'

// Prepare the Application insights call
var options = {
Expand Down Expand Up @@ -179,29 +179,42 @@ export default class ApplicationInsightsExplorerExplorerProvider implements vsco

// Set the first line as a continuation
this.AppInsightsItems[i].Continuation = true;
this.AppInsightsItems[i].Id += ", " + this.AppInsightsItems[i + 1].Id + " (The report shows a combination of two Application Insight entities)";
this.AppInsightsItems[i].Id += ", " + this.AppInsightsItems[i + 1].Id;

// Check if the first entity is the first one, or the continuation
if (this.AppInsightsItems[i].Data.startsWith("[")) {
this.AppInsightsItems[i].Data = this.AppInsightsItems[i].Data + this.AppInsightsItems[i + 1].Data;
// Set the orchestration steps
this.AppInsightsItems[i + 1].OrchestrationStep.replace("Step ", "").split(",").forEach(element => {
if (this.AppInsightsItems[i].OrchestrationStep.indexOf(element + ",") < 1) {
this.AppInsightsItems[i].OrchestrationStep += ", " + element
}
});
}
else {
this.AppInsightsItems[i].Data = this.AppInsightsItems[i + 1].Data + this.AppInsightsItems[i].Data
// Set the orchestration steps
this.AppInsightsItems[i].OrchestrationStep.replace("Step ", "").split(",").forEach(element => {
if (this.AppInsightsItems[i + 1].OrchestrationStep.indexOf(element + ",") < 1) {
this.AppInsightsItems[i + 1].OrchestrationStep += ", " + element
}
});
}

// Set the orchestration steps
this.AppInsightsItems[i + 1].OrchestrationStep.replace("Step ", "").split(",").forEach(element => {
if (this.AppInsightsItems[i].OrchestrationStep.indexOf(element + ",") < 1) {
this.AppInsightsItems[i].OrchestrationStep += ", " + element
}
});
// Only add combination text if combined the last entry together
if (this.AppInsightsItems[i].Data.endsWith("]")) {
this.AppInsightsItems[i].Id += " (The report shows a combination of two Application Insight entities)";
}

if (this.AppInsightsItems[i].OrchestrationStep.length > 0 &&
(!this.AppInsightsItems[i].OrchestrationStep.startsWith("Step")))
this.AppInsightsItems[i].OrchestrationStep = "Step " + this.AppInsightsItems[i].OrchestrationStep;

// Remove the second entity
this.AppInsightsItems.splice(i + 1, 1);

// More than 2 entities sometimes need to be combined, after joining two together we need to go back 1 step in the loop and check again
i--;
}
}

Expand Down

0 comments on commit 543245f

Please sign in to comment.