Describe the bug
Using ApplicationInsightsDataClient.query.execute fails due to not providing api-version query param
To Reproduce
Steps to reproduce the behavior:
Set APP_ID to your application insights app ID. (note, this is not the instrumentation ID. You can find it via the "API Access" pane in the App Insights instance in the Azure Portal
from os import environ
from azure.common.client_factory import get_client_from_cli_profile
from azure.applicationinsights import ApplicationInsightsDataClient
from azure.applicationinsights.models import QueryBody
client = get_client_from_cli_profile(ApplicationInsightsDataClient)
query = "traces | where * has '91f42869-0ea5-466c-8684-8f4b6bc31bf4' | order by timestamp desc"
client.query.execute(environ['APP_ID'], body=QueryBody(query=query, timespan="PT3H"))
Expected behavior
Exception isn't generated
Screenshots
$ python /tmp/test.py
Traceback (most recent call last):
File "/tmp/test.py", line 8, in <module>
client.query.execute(environ['APP_ID'], body=QueryBody(query=query, timespan="PT3H"))
File "/home/USER/PROJECT/.direnv/python-3.8.2/lib/python3.8/site-packages/azure/applicationinsights/operations/query_operations.py", line 87, in execute
raise models.ErrorResponseException(self._deserialize, response)
azure.applicationinsights.models.error_response_py3.ErrorResponseException: (MissingApiVersionParameter) The api-version query parameter (?api-version=) is required for all requests.
$
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @azmonapplicationinsights.
It's been upwards of a month without response. Is there any status for this?
Hi @bmc-msft
I wonder if this is an interaction with the get_client_from_cli_profile. Could you try with your own credential creating directly the client, or adding a kwarg base_url = 'https://api.applicationinsights.io/v1' ?
had the same problem https://stackoverflow.com/questions/64767335/missingapiversionparameter-when-querying-azure-application-insights-api-with-pyt and transformed solution from relating Log Analytics issue https://github.com/Azure/azure-sdk-for-python/issues/4544
Setting the base_url did not work for me.
However, the work-around from the issue linked by @KaiWalter worked for me.
For future people scouring for this issue, this is the updated sample that works:
from os import environ
from azure.applicationinsights import ApplicationInsightsDataClient
from azure.applicationinsights.models import QueryBody
from azure.common.client_factory import get_azure_cli_credentials
creds, _ = get_azure_cli_credentials(resource="https://api.applicationinsights.io")
client = ApplicationInsightsDataClient(creds)
query = "traces | where * has '91f42869-0ea5-466c-8684-8f4b6bc31bf4' | order by timestamp desc"
print(client.query.execute(environ['APP_ID'], body=QueryBody(query=query, timespan="PT3H")))
It would be extremely beneficial if the azure.applicationinsights library was updated to support azure.identity, such that a single base library for authentication across all of the Azure SDK can be used.
@bmc-msft would it be possible for you to test https://github.com/Azure/azure-sdk-for-python/pull/15220 ?
This package will eventually goes to azure-identity support, but I have no timeline yet, so if I can simplify your life by this tiny bugfix at least, let's try to do it :)
@lmazuel I can confirm that your PR works for my purposes.
Though, I wonder if it will work for other Azure Clouds, such as Azure Government which I believe has it's own endpoint.
@bmc-msft fair point, I read the CLI code to get some ideas, and updated the PR. Could you confirm again?
@lmazuel confirmed the new changes work for me.
fix will be in azure-common 1.1.26 I will release tomorrow
https://pypi.org/project/azure-common/1.1.26/ released
Thanks a lot @bmc-msft for your help testing, really appreciate! And thanks @KaiWalter for the reminder there was an older issue, I forgot about it :p
Most helpful comment
fix will be in azure-common 1.1.26 I will release tomorrow