简体   繁体   中英

How to post application insights data to REST API instead of Azure from ASP.NET Core application?

I have an ASP.NET Core 5.0 MVC web application and app insights enabled. I am trying to post application insights data to REST API, which I developed using nodejs.

My appsettings.json details are below. Here, API got trigger, but I'm not getting any body content (Insight's data).

Please guide me. Thanks in advance.

{
  "Logging": {
    "ApplicationInsights": {
      "LogLevel": {
        "Default": "Information",
        "Microsoft": "Warning",
        "Microsoft.Hosting.Lifetime": "Information"
      }
    },
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "ApplicationInsights": {
    "InstrumentationKey": "123",
    "TelemetryChannel": {
      "EndpointAddress": "http://localhost:3000/v2/track"
    }
  }
}

在此处输入图像描述

  • You won't be able to get the data directly through the application as it will not send the application insights directly to you, but it will save it in the storage account in form of blob storage.

  • What you can do is either get the data directly through the storage account or you can get data from the application insights.

  • If you want to take data from the storage account, you will have to use @azure/storage-blob npm package with node js .

     const container = blobServiceClient.getContainerClient(containerName); const blockBlob = container.getBlockBlobClient(blobName); const download = await blockBlob.download(0);
  • you can get containername from the portal under containers section of the storage account.

  • Another way would be to run a query in the application insights. This can be achieved by making http requests and the request has to be authenticated by either azure ad token or the access key which is in the portal.

     HTTP GET https://api.applicationinsights.io/v1/apps/{appId}/query?query={query}

Reference: Export telemetry from Application Insights by Anton Fritz

Export data using Query

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM