nu123
nu123

Reputation: 139

Azure Monitor / Log Analytics metric alert query and need to redirect End-to-end transaction details window

I created a email notification to get when every time exception triggered email send some details to receiver. like this

enter image description here

and also following details

enter image description here

We need to attended the "End-to-end transaction" option to each email so when the receiver click the link i redirect the End-to-end transaction windows.How can add this..

enter image description here

Upvotes: 0

Views: 248

Answers (2)

joschi27
joschi27

Reputation: 1

It's possible if you don't mind using this hacky function I made for this purpose:

let encode_operationid_hardlink_to_transaction_srch = (ResourceId: string, StartTime: datetime, EndTime: datetime, OperationId: string) { 
let UrlEncodedResource = url_encode(url_encode(ResourceId));
let UrlEncodedStartTime = url_encode(tostring(StartTime));
let UrlEncodedEndTime = url_encode(tostring(EndTime));
let TimeDiff = datetime_diff('millisecond', EndTime, StartTime);
let Url = ```
https://portal.azure.com/#blade/AppInsightsExtension/BladeRedirect/BladeName/searchV1/ResourceId/
%UrlEncodedResource%
/BladeInputs/%7B%22tables%22%3A%5B%22availabilityResults%22%2C%22requests%22%2C%22exceptions%22%2C%22pageViews%22%2C%22traces%22%2C%22customEvents%22%2C%22dependencies%22%5D%2C%22timeContextWhereClause%22%3A%22%7C%20where%20timestamp%20%3E%20datetime(%5C%22
%UrlEncodedStartTime%
%5C%22)%20and%20timestamp%20%3C%20datetime(%5C%22
%UrlEncodedEndTime%
%5C%22)%22%2C%22filterWhereClause%22%3A%22%7C%20where%20*%20has%20%5C%22
%OperationId%
%5C%22%7C%20order%20by%20timestamp%20desc%22%2C%22originalParams%22%3A%7B%22eventTypes%22%3A%5B%7B%22value%22%3A%22availabilityResult%22%2C%22tableName%22%3A%22availabilityResults%22%2C%22label%22%3A%22Availability%22%7D%2C%7B%22value%22%3A%22request%22%2C%22tableName%22%3A%22requests%22%2C%22label%22%3A%22Request%22%7D%2C%7B%22value%22%3A%22exception%22%2C%22tableName%22%3A%22exceptions%22%2C%22label%22%3A%22Exception%22%7D%2C%7B%22value%22%3A%22pageView%22%2C%22tableName%22%3A%22pageViews%22%2C%22label%22%3A%22Page%20View%22%7D%2C%7B%22value%22%3A%22trace%22%2C%22tableName%22%3A%22traces%22%2C%22label%22%3A%22Trace%22%7D%2C%7B%22value%22%3A%22customEvent%22%2C%22tableName%22%3A%22customEvents%22%2C%22label%22%3A%22Custom%20Event%22%7D%2C%7B%22value%22%3A%22dependency%22%2C%22tableName%22%3A%22dependencies%22%2C%22label%22%3A%22Dependency%22%7D%5D%2C%22timeContext%22%3A%7B%22durationMs%22%3A
%TimeDiff%
%2C%22endTime%22%3A%22
%UrlEncodedEndTime%
%22%7D%2C%22filter%22%3A%5B%5D%2C%22searchPhrase%22%3A%7B%22originalPhrase%22%3A%22
%OperationId%
%22%2C%22_tokens%22%3A%5B%7B%22conjunction%22%3A%22and%22%2C%22value%22%3A%22
%OperationId%
%22%2C%22isNot%22%3Afalse%2C%22kql%22%3A%22%20*%20has%20%5C%22
%OperationId%
%5C%22%22%7D%5D%7D%2C%22sort%22%3A%22desc%22%7D%7D
```;

The resource id can be grabbed from the _ResourceId in the standard columns (but i think only if the insights is workspace-based)

The above function can be used like this: transaction_search_link=encode_operationid_hardlink_to_transaction_srch(_ResourceId, now() -5m, now() +2h, operation_Id)

The link will put you directly to the transaction search blade of the corresponding App Insights with the dates perfectly filled out so you see the transaction.

Now, to add this information to the alert email body, I used another hack:

In the log alert you can define dimensions. These are normally used to group results, but you can also use them to get additional information into the email. Make sure to add the transaction_search_link field to the dimensions and do not select any values. Dimensions in Alert Query (If you can't find any dimensions to choose just recreate your alert rule so it's updated to the newest version)

The email you will receive will look something like this: Alert Email excerpt

Please keep in mind that this is quite hacky, if microsoft decides to change anything about the search blade url or with the email alerts it will break. I don't want to create an entirely separate service just to parse alert emails so this seemed like a good solution.

Upvotes: 0

Ivan Glasenberg
Ivan Glasenberg

Reputation: 29940

This is not possible now. The receiver should manually nav to azure portal -> "End-to-end transaction", or you manually click "Copy link" from "End-to-end transaction" and send the link directly to customer.

By the way, you can suggest this as a feature on the Azure Monitor-Application Insights site, like this suggestion.

Hope it helps.

Upvotes: 1

Related Questions