Fetching Application Insights logs from Java code with kusto Query?

Choudhary, Roshankumar 6 Reputation points
2022-04-21T18:52:08.167+00:00

Hey Guys,

Need some help here. I am trying to fetch logs from Application Insights using Java ( will use Kusto query) within. Initially I thought I can do this by using Azure Log Analytics API (https://learn.microsoft.com/en-us/azure/azure-monitor/logs/api/overview) however it doesn't have any specific example or maybe I am not looking in the right direction. Also, I did find "Tenant Id" and Client Id "Application Id" but we don't have any client secret as we are using certificates.

Can somebody please help me or point me in the right direction.

I am expecting something like below:

LogsQueryClient logsQueryClient = new LogsQueryClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.buildClient();
LogsQueryResult queryResults = logsQueryClient.queryWorkspace("{workspace-id}", "kusto query string",
new QueryTimeInterval(Duration.ofDays(1)));

    for (LogsTableRow row : queryResults.getTable().getRows()) {  
        System.out.println(row.getColumnValue("TransactionId") + " " + row.getColumnValue("EventReason"));  
    }  
Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
2,833 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Monalla-MSFT 11,961 Reputation points
    2022-04-26T14:41:59.393+00:00

    Hello @Choudhary, Roshankumar - Welcome to Microsoft Q&A and thanks for reaching out.

    A client secret is a string value your app can use in place of a certificate to identity itself and sometimes called as application password.

    Client secrets are considered less secure than certificate credentials. Application developers sometimes use client secrets during local app development because of their ease of use. However, you should use certificate credentials for any of your applications that are running in production.

    • In the Azure portal, in App registrations, select your application.
    • Select Certificates & secrets > Client secrets > New client secret.
    • Add a description for your client secret.
    • Select an expiration for the secret or specify a custom lifetime.
    • Client secret lifetime is limited to two years (24 months) or less. You can't specify a custom lifetime longer than 24 months.
    • Microsoft recommends that you set an expiration value of less than 12 months.
    • Select Add.
    • Record the secret's value for use in your client application code. This secret value is never displayed again after you leave this page.

    For application security recommendations, see Microsoft identity platform best practices and recommendations.

    Also take a look at this doc for more reference: Add a client Secret

    Hope this helps. and please feel free to reach out if you have any further questions.

    ------------------------------------------------------------------

    If the above response was helpful, please feel free to "Accept as Answer" and "Upvote" the same so it can be beneficial to the community

    0 comments No comments

  2. Choudhary, Roshankumar 6 Reputation points
    2022-05-02T19:31:03.843+00:00

    I did get to know from Andriy Fedonyuk that app Insights API cannot be used with certificates and only option I have is "client_secret". I have to see if that something feasible in our environment.