microsoft / microsoft/AzureMonitorCommunity

Query to get CustomMetrics in an app returns empty result. Using APIKey for authentication.

Open
#106 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PowerShell
Stars
1.2k
Forks
493
PR merge metrics
No merged PRs in 30d

Description

I'm trying to access AppInsights data, for now trying through a console app, using APIKey for authentication.
Surprisingly, I get empty result as response. Same query returns expected result when run in Azure portal.
Please help me understand what I am missing here.

Code:

public async Task<IList<IDictionary<string, string>>> ReadAsync(string applicationId, string apiKey)
        {
            ApiKeyClientCredentials credentials = new ApiKeyClientCredentials(apiKey);
            using ApplicationInsightsDataClient client = new ApplicationInsightsDataClient(credentials);
            client.AppId = applicationId;
            string query = "customMetrics | take 1";
            HttpOperationResponse<QueryResults> queryWithHttpMessagesAsync = await client.QueryWithHttpMessagesAsync(query);
            QueryResults result = queryWithHttpMessagesAsync.Body;
            IList<IDictionary<string, string>> resultsDictionary = result.Results.ToList();

            return resultsDictionary;
        }

image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the ReadAsync method with the supplied customMetrics | take 1 query, application ID, and API key, then compare the response with the Azure portal result. Inspect the returned QueryResults and authentication context to identify why the console app receives no rows. Done means the cause of the empty result and the required correction are documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
api, cloud, observability-sre
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.