azure-cli-extensions icon indicating copy to clipboard operation
azure-cli-extensions copied to clipboard

az monitor app-insights query with start and end time

Open marabesi opened this issue 1 year ago • 1 comments

Related command

az monitor app-insights query --app myapp -g mygroup --analytics-query 'traces | where message contains "bla"' --start-time date "2022-07-21" time "09:18:00.0000Z" timezone "+02:00" -o table

Extension name (the extension in question)

app-insights

Description of issue (in as much detail as possible)

The documentation around the app-insights query is not that completed when referring to the field "--start-time", the command below is an attempt to make a query and filter by the start date, but when the command is executed I see the error:

Unable to parse: 'date 2022-07-21 time 09:18:00.0000Z timezone +02:00'. Expected format: Start-time of time range for which to retrieve data. Format: date (yyyy-mm-dd) time (hh:mm:ss.xxxxx) timezone (+/-hh:mm)

Which indicates that the format I am giving is not that clear, but the docs says nothing about the format. After diving into the code (and checking this file from cli core), I saw that the format should be something like:

az monitor app-insights query --app myapp -g mygroup --analytics-query 'traces | where message contains "bla"' --start-time 2022-07-10T09:10:00.000Z -o table

When I run this command, I see no errors, but it shows nothing in the console (if I execute the same in the azure portal, I can see the logs properly). The question that I have is: is the date format correct? If so, can I mitigate why I can't see the logs?

marabesi avatar Jul 26 '22 19:07 marabesi

monitor

yonzhan avatar Jul 27 '22 00:07 yonzhan

Hi Marabesi, date format like '2022-07-21 09:18:00 +02:00', '2022-07-21 09:18:00', '2022-07-21' should work for start-time and end-time query.

The reason nothing returned in console might need to be debugged. You can add --debug in your command (like below) to see what's returning in your console and see what's going on in the backend.

az monitor app-insights query --app myapp -g mygroup --analytics-query 'traces | where message contains "bla"' --start-time '2022-07-10 09:10:00' -o table --debug

AllyW avatar Aug 23 '22 10:08 AllyW