Telemetry with Power Automate – how to get the report directly on your mailbox

AppSource is a great tool because it allows people (end users but also consultants) to install your software without even contacting you. But how do you know that someone installed it? Or (even more important) that someone had an issue during installation? 

Read the story that happened to me a few days ago to find out how to get notifications by email with errors.

What happened?

I got an email with the title: “Someone just installed your app!” … but after 5 minutes I got the same message from the same customer.

That is strange but also tells that something went wrong – either someone just clicks 2 times on AppSource or cancel the first installation (you cannot control that) or he had some issues during the installation and try one more time.

I decided to find out…

Telemetry

But how to do so? You can contact the person directly – almost all info you can get from the AppSource (except one of the most important – tenant id).

But what would you say? “Hello. Why did you install our app twice? Can you explain the problem?”.

Instead of that, you can run a simple query in the Application Insights to see if there have been any issues during the installation.

The example below will get for you all the signals for Install or Publish the app that failed:

traces 

| where message contains “failed” and customDimensions.eventId in (‘LC0011′,’LC0015’)

If you would get any lines then you can find the reason for the failure in the CustomDimensions field failureReason.

Here I got a surprise (that turns out in my case a tip to solve the issue). The message is not in English but in the language that someone has chosen during the installation -in this case, Swedish.

After solving the issue I was able to mail the person the solution instead of ping pong with a new customer about the reasons why he tried two or more times. Success!

Let’s automate

I could finish the task here but thought why every time do I need to look at the logs manually? What about upgrades when we do not get any information from AppSource? I thought to automate getting the issues by the mail.

I can then easily send it to more people who can react when I am not in the office and second, I can react to any problems much quicker. Also, I can include any issues with publishing, install or upgrade.

I decided to use Power Automate for that since the setup will not take me more than 15 minutes.

Using Power Automate with Azure Application Insights

The great thing with Power Automate is that it has templates for a lot of cases. Also, in the one that I am describing. To create a flow just go to templates and find Application Insights. Note that the connector to Application Insights is a Premium one.

You can use one of the existing or you can check one that I prepared.

In my flow, the first step is to run the flow every 1 hour. Then I am running the Application Insights query. If you do it for the first time you will need to set the connection for the Application Insights.

To generate API Key, go to Azure Portal and open section API Access for Application Insights. Create a new key and copy values to Power Automate.

The query checks if there are any failures for install, publish, update, unpublish and uninstall. It also excludes some not real tenant ids (for example docker containers).

traces

| where message contains “failed” and customDimensions.eventId in (‘LC0011′,’LC0015’, ‘RT0010′,’LC0019′,’LC0017′,’LC0023’) and customDimensions.AadTenantId !in (‘default’, ‘common’)

In the next steps, I am checking if there are any results. And if yes I continue the flow if there are no issues then I terminate the flow.

When there are any issues, I would like to send the mail that contains the table with the issues. For that I use another action from Application Insights that returns the HTML Table – Visualize Analytics query.

The query that I am using is very similar to the previous one but has the project part that shows time, tenant id, and failure reason.

traces

| where message contains “failed” and customDimensions.eventId in (‘LC0011′,’LC0015’, ‘RT0010′,’LC0019′,’LC0017’) and customDimensions.AadTenantId !in (‘default’, ‘common’)

|project timestamp, AadTenantId = customDimensions.AadTenantId, failureReason = customDimensions.failureReason

Note: I know that I could optimize it to have only one query here instead of using two, but I do not expect a lot of rows every hour – I hope to never see the result on my mailbox.

The last step is to compose the query result (body) – to be able to use it in the email body, and send email using the standard Send an email action. In the email body, I add the Output of the Compose action.

The result of the flow you can find below

What about successful updates and installs?

Small bonus at the end. If you would like to get the mail with the successful install and updates you can use below queries in the same flow (or copy of existing one):

Query in Run Analytics query step:

traces 

| where customDimensions.eventId in (‘LC0010′,’LC0022’) and customDimensions.aadTenantId !in (“default”,”common”)

Query in Visualize Analytics query:

traces

| where customDimensions.eventId in (‘LC0010′,’LC0022’) and customDimensions.aadTenantId !in (“default”,”common”)

| project [‘Operation Time’] = timestamp, [‘Tenant Id’] = customDimensions.AadTenantId, [‘Extension Name’] = customDimensions.[‘Extension name’], [‘Extension Version’] = customDimensions.[‘Extension version’], [‘Operation Message’] = message

One Comment

Add a Comment

Your email address will not be published.