Repository: Azure/azure-cli-extensions

Issue:
tried and failed, escaping quot. marks
Installed application-insights               0.1.1

tried to run basic queries e.g. 
C:\Windows\System32&gt;az monitor app-insights query --app tooling  --analytics-query 'exceptions'

but getting an error that does not provide much direction

PathNotFoundError - The requested path does not exist

the actual query I wanted to run was something like 

"exceptions
| where problemId == "Newtonsoft.Json.JsonReaderException at Newtonsoft.Json.JsonTextReader.ReadStringValue" 
| order by timestamp desc
| take 1"

how do you escape quot. marks? I tried few ways but nothing would seem to work - perhaps because the extension itself is unhealthy

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: 0bce0dc5-da82-717a-70cf-e392c05904a3
* Version Independent ID: a5cb6492-d731-0c98-7691-64d1d7a14a5c
* Content: [az monitor app-insights](https://docs.microsoft.com/en-us/cli/azure/ext/application-insights/monitor/app-insights?view=azure-cli-latest#feedback)
* Content Source: [latest/docs-ref-autogen/ext/application-insights/monitor/app-insights.yml](https://github.com/MicrosoftDocs/azure-docs-cli/blob/live/latest/docs-ref-autogen/ext/application-insights/monitor/app-insights.yml)
* GitHub Login: @rloutlaw
* Microsoft Alias: **routlaw**


Discussion:
add to S165.
@MyronFanQiu , please help take a look.
@VaclavK Hello. Which terminal are you using? Could you try this one? It should work in Powershell.
```
--analytics-query 'exceptions | where problemId == \"Newtonsoft.Json.JsonReaderException at Newtonsoft.Json.JsonTextReader.ReadStringValue\" | order by timestamp desc | take 1'
```
@MyronFanQiu thanks for this.. I tried powershell initially but due to the runtime failure would not see the result so could not verify

eentually ran it with --debug (why did I not do that in the first place..) and decyphered the message.. I was passing pure name of the AI instance - not fully qualified - so the message (PathNotFoundError - The requested path does not exist) turned out to be from the API call

passing guid fixes that so happy to report this now returns the result

so perhaps my suggestion would be to translate the raw error from the API call to something more descriptive

Resolving patch:
diff --git a/src/application-insights/azext_applicationinsights/_help.py b/src/application-insights/azext_applicationinsights/_help.py
--- a/src/application-insights/azext_applicationinsights/_help.py
+++ b/src/application-insights/azext_applicationinsights/_help.py
@@ -187,9 +187,9 @@
           the start time will be calculated by subtracting the offset. If --start-time and --end-time are
           provided, then --offset will be ignored.
     examples:
-      - name: Execute a simple query over past 3.5 days.
+      - name: Execute a simple query over past 1 hour and 30 minutes.
         text: |
-          az monitor app-insights query --app e292531c-eb03-4079-9bb0-fe6b56b99f8b --analytics-query 'requests | summarize count() by bin(timestamp, 1h)' --offset P3DT12H
+          az monitor app-insights query --app e292531c-eb03-4079-9bb0-fe6b56b99f8b --analytics-query 'requests | summarize count() by bin(timestamp, 1h)' --offset 1h30m
 """
 
 helps['monitor app-insights metrics show'] = """
diff --git a/src/application-insights/azext_applicationinsights/custom.py b/src/application-insights/azext_applicationinsights/custom.py
--- a/src/application-insights/azext_applicationinsights/custom.py
+++ b/src/application-insights/azext_applicationinsights/custom.py
@@ -7,6 +7,7 @@
 
 from knack.util import CLIError
 from knack.log import get_logger
+from azext_applicationinsights.vendored_sdks.applicationinsights.models import ErrorResponseException
 from .util import get_id_from_azure_resource, get_query_targets, get_timespan, get_linked_properties
 
 logger = get_logger(__name__)
@@ -16,7 +17,12 @@ def execute_query(cmd, client, application, analytics_query, start_time=None, en
     """Executes a query against the provided Application Insights application."""
     from .vendored_sdks.applicationinsights.models import QueryBody
     targets = get_query_targets(cmd.cli_ctx, application, resource_group_name)
-    return client.query.execute(targets[0], QueryBody(query=analytics_query, timespan=get_timespan(cmd.cli_ctx, start_time, end_time, offset), applications=targets[1:]))
+    try:
+        return client.query.execute(targets[0], QueryBody(query=analytics_query, timespan=get_timespan(cmd.cli_ctx, start_time, end_time, offset), applications=targets[1:]))
+    except ErrorResponseException as ex:
+        if "PathNotFoundError" in ex.message:
+            raise ValueError("The Application Insight is not found. Please check the app id again.")
+        raise ex
 
 
 def get_events(cmd, client, application, event_type, event=None, start_time=None, end_time=None, offset='1h', resource_group_name=None):
diff --git a/src/application-insights/setup.py b/src/application-insights/setup.py
--- a/src/application-insights/setup.py
+++ b/src/application-insights/setup.py
@@ -8,7 +8,7 @@
 from codecs import open
 from setuptools import setup, find_packages
 
-VERSION = "0.1.4"
+VERSION = "0.1.5"
 
 CLASSIFIERS = [
     'Development Status :: 4 - Beta',


Test patch: