Which SDK or API should I use to fetch metrics data from Azure Application Insights?

Haruka Ichinose 25 Reputation points
2024-06-20T02:59:52.7+00:00

I have my Next.js 14 application that uses "@microsoft/applicationinsights-web" and "@microsoft/applicationinsights-react-js" to collect metrics and sends to Azure Application Insights instance. The setup is successful and it's collecting our app's page visit.

Now, I wanted to get the metrics back from Azure Application Insights to the Next.js app. I would like to show how many users visited the app monthly on the Next.js app. After doing research on the Azure docs and googling, I got confused about the following points and wanted to get experts advice.

It's my first time to post on Azure forum so please let me know if I miss any information. I appreciate if anyone give me what's the good practice and the right service I should use to achieve this feature. Thank you!

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,330 questions
0 comments No comments
{count} votes

Accepted answer
  1. AnuragSingh-MSFT 21,386 Reputation points
    2024-06-20T14:15:10.9433333+00:00

    @Haruka Ichinose, Thank you for posting this question on Microsoft Q&A and welcome.

    Please find below the answer your questions:

    1. Azure Monitor is the umbrella under which multiple solutions are placed. Each of these solutions are applicable to collect/analyze and respond to monitoring data. For more details, see Azure Monitor overview
      Application Insights is part of Azure Monitor for Application Performance Management (APM) for live web applications.
    2. For your use case, you need the ApplicationInsights API which you have mentioned in the question. The other API - Azure Monitor Metrics Get is to query the metrics telemetry stored in Azure Monitor. This is the metric that you see when you go to "Metrics" menu for any resource. The data collected by ApplicationInsights is stored as logs in a log Analytics workspace.
    3. The REST API for Application Insights Query - Get is an option to use query the result back, which is collected by ApplicationInsights.
      There is a JavaScript SDK library as well for it as available here - LogsQueryClient class. However, this queries the backend log analytics workspace and not the ApplicationInsights resource itself. Therefore, the table names will be different (even though they contain the same information) - Table schemas
      To summarize, when you try to query information from ApplicationInsights, the table name used will be slightly different from when you query the LA workspace.
    4. Regarding API Access, see Log Analytics API authentication. The configure API option is to help quickly explore the API without using Microsoft Entra Authentication (App Registration). If your registered App has the authorization to query ApplicationInsights data. You can add the Monitoring Reader role to the App Service principal and you should be able to use it for query instead of API key.

    Hope this helps.

    If the answer did not help, please add more context/follow-up question for it. Else, if the answer helped, please click Accept answer so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.