az monitor app-insights query got error ApplicationNotFoundError: The application could not be found #4591
Description
- If the issue is to do with Azure CLI 2.0 in-particular, create an issue here at Azure/azure-cli
Extension name (the extension in question)
In azure china cloud:
az monitor app-insights query azure-cli Version: 2.34.1 Extension Name: application-insights. Version: 0.1.15.
Description of issue (in as much detail as possible)
az monitor app-insights query -a appinsight1 -g appinsight1 --analytics-query 'requests | limit 5' --debug
cli.knack.cli: Command arguments: ['monitor', 'app-insights', 'query', '-a', 'appinsight1', '-g', 'appinsight1', '--analytics-query', 'requests | limit 5', '--debug']
cli.knack.cli: init debug log:
Enable color in terminal.
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x7f9d963aed08>, <function OutputProducer.on_global_arguments at 0x7f9d95ef2d90>, <function CLIQuery.on_global_arguments at 0x7f9d95c83378>]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
cli.azure.cli.core: Modules found from index for 'monitor': ['azure.cli.command_modules.monitor', 'azext_applicationinsights']
cli.azure.cli.core: Loading command modules:
cli.azure.cli.core: Name Load Time Groups Commands
cli.azure.cli.core: monitor 0.010 34 139
cli.azure.cli.core: Total (1) 0.010 34 139
cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next']
cli.azure.cli.core: Loading extensions:
cli.azure.cli.core: Name Load Time Groups Commands Directory
cli.azure.cli.core: application-insights 0.004 10 30 /root/.azure/cliextensions/application-insights
cli.azure.cli.core: Total (1) 0.004 10 30
cli.azure.cli.core: Loaded 43 groups, 169 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command : monitor app-insights query
cli.azure.cli.core: Command table: monitor app-insights query
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x7f9d94c390d0>]
cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to '/root/.azure/commands/2022-03-29.09-28-55.monitor_app-insights_query.23267.log'.
az_command_data_logger: command args: monitor app-insights query -a {} -g {} --analytics-query {} --debug
cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument..add_subscription_parameter at 0x7f9d947bad08>]
cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument..add_ids_arguments at 0x7f9d946a42f0>, <function register_cache_arguments..add_cache_arguments at 0x7f9d946a4400>]
cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x7f9d95ef2e18>, <function CLIQuery.handle_query_parameter at 0x7f9d95c83400>, <function register_ids_argument..parse_ids_arguments at 0x7f9d946a4378>]
az_command_data_logger: extension name: application-insights
az_command_data_logger: extension version: 0.1.15
cli.azure.cli.core.auth.persistence: build_persistence: location='/root/.azure/msal_token_cache.json', encrypt=False
cli.azure.cli.core.auth.identity: _load_msal_http_cache: /root/.azure/msal_http_cache.bin
cli.azure.cli.core.auth.identity: __load_msal_http_cache: /root/.azure/msal_http_cache.bin
urllib3.util.retry: Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None, status=None)
msal.authority: openid_config = {'token_endpoint': 'https://login.chinacloudapi.cn/b388b808-0ec9-4a09-a414-a7cbbd8b7e9b/oauth2/v2.0/token', 'token_endpoint_auth_methods_supported': ['client_secret_post', 'private_key_jwt', 'client_secret_basic'], 'jwks_uri': 'https://login.chinacloudapi.cn/b388b808-0ec9-4a09-a414-a7cbbd8b7e9b/discovery/v2.0/keys', 'response_modes_supported': ['query', 'fragment', 'form_post'], 'subject_types_supported': ['pairwise'], 'id_token_signing_alg_values_supported': ['RS256'], 'response_types_supported': ['code', 'id_token', 'code id_token', 'id_token token'], 'scopes_supported': ['openid', 'profile', 'email', 'offline_access'], 'issuer': 'https://login.partner.microsoftonline.cn/b388b808-0ec9-4a09-a414-a7cbbd8b7e9b/v2.0', 'request_uri_parameter_supported': False, 'userinfo_endpoint': 'https://microsoftgraph.chinacloudapi.cn/oidc/userinfo', 'authorization_endpoint': 'https://login.chinacloudapi.cn/b388b808-0ec9-4a09-a414-a7cbbd8b7e9b/oauth2/v2.0/authorize', 'device_authorization_endpoint': 'https://login.chinacloudapi.cn/b388b808-0ec9-4a09-a414-a7cbbd8b7e9b/oauth2/v2.0/devicecode', 'http_logout_supported': True, 'frontchannel_logout_supported': True, 'end_session_endpoint': 'https://login.chinacloudapi.cn/b388b808-0ec9-4a09-a414-a7cbbd8b7e9b/oauth2/v2.0/logout', 'claims_supported': ['sub', 'iss', 'cloud_instance_name', 'cloud_instance_host_name', 'cloud_graph_host_name', 'msgraph_host', 'aud', 'exp', 'iat', 'auth_time', 'acr', 'nonce', 'preferred_username', 'name', 'tid', 'ver', 'at_hash', 'c_hash', 'email'], 'kerberos_endpoint': 'https://login.chinacloudapi.cn/b388b808-0ec9-4a09-a414-a7cbbd8b7e9b/kerberos', 'tenant_region_scope': 'AS', 'cloud_instance_name': 'partner.microsoftonline.cn', 'cloud_graph_host_name': 'graph.chinacloudapi.cn', 'msgraph_host': 'microsoftgraph.chinacloudapi.cn', 'rbac_url': 'https://pas.chinacloudapi.cn'}
msrest.universal_http.requests: Configuring retry: max_retries=3, backoff_factor=0.8, max_backoff=90
cli.azure.cli.core.commands.client_factory: Getting management service client client_type=ApplicationInsightsManagementClient
urllib3.util.retry: Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None, status=None)
msal.authority: openid_config = {'token_endpoint': 'https://login.chinacloudapi.cn/b388b808-0ec9-4a09-a414-a7cbbd8b7e9b/oauth2/v2.0/token', 'token_endpoint_auth_methods_supported': ['client_secret_post', 'private_key_jwt', 'client_secret_basic'], 'jwks_uri': 'https://login.chinacloudapi.cn/b388b808-0ec9-4a09-a414-a7cbbd8b7e9b/discovery/v2.0/keys', 'response_modes_supported': ['query', 'fragment', 'form_post'], 'subject_types_supported': ['pairwise'], 'id_token_signing_alg_values_supported': ['RS256'], 'response_types_supported': ['code', 'id_token', 'code id_token', 'id_token token'], 'scopes_supported': ['openid', 'profile', 'email', 'offline_access'], 'issuer': 'https://login.partner.microsoftonline.cn/b388b808-0ec9-4a09-a414-a7cbbd8b7e9b/v2.0', 'request_uri_parameter_supported': False, 'userinfo_endpoint': 'https://microsoftgraph.chinacloudapi.cn/oidc/userinfo', 'authorization_endpoint': 'https://login.chinacloudapi.cn/b388b808-0ec9-4a09-a414-a7cbbd8b7e9b/oauth2/v2.0/authorize', 'device_authorization_endpoint': 'https://login.chinacloudapi.cn/b388b808-0ec9-4a09-a414-a7cbbd8b7e9b/oauth2/v2.0/devicecode', 'http_logout_supported': True, 'frontchannel_logout_supported': True, 'end_session_endpoint': 'https://login.chinacloudapi.cn/b388b808-0ec9-4a09-a414-a7cbbd8b7e9b/oauth2/v2.0/logout', 'claims_supported': ['sub', 'iss', 'cloud_instance_name', 'cloud_instance_host_name', 'cloud_graph_host_name', 'msgraph_host', 'aud', 'exp', 'iat', 'auth_time', 'acr', 'nonce', 'preferred_username', 'name', 'tid', 'ver', 'at_hash', 'c_hash', 'email'], 'kerberos_endpoint': 'https://login.chinacloudapi.cn/b388ec9-4a09-a414-a7cbbd8b7e9b/kerberos', 'tenant_region_scope': 'AS', 'cloud_instance_name': 'partner.microsoftonline.cn', 'cloud_graph_host_name': 'graph.chinacloudapi.cn', 'msgraph_host': 'microsoftgraph.chinacloudapi.cn', 'rbac_url': 'https://pas.chinacloudapi.cn'}
cli.azure.cli.core.auth.credential_adaptor: CredentialAdaptor.get_token: scopes=('https://management.core.chinacloudapi.cn//.default',), kwargs={}
cli.azure.cli.core.auth.msal_authentication: UserCredential.get_token: scopes=('https://management.core.chinacloudapi.cn//.default',), kwargs={}
msal.application: Cache hit an AT
msal.telemetry: Generate or reuse correlation_id: a90f2a02-dd74-4193-9e96-7b1690dfcd50
cli.azure.cli.core.sdk.policies: Request URL: 'https://management.chinacloudapi.cn/subscriptions/05a7ed23-e9a5-467b-b371-7a9d9f6a504b/resourceGroups/appinsight1/providers/Microsoft.Insights/components/appinsight1?api-version=2015-05-01'
cli.azure.cli.core.sdk.policies: Request method: 'GET'
cli.azure.cli.core.sdk.policies: Request headers:
cli.azure.cli.core.sdk.policies: 'Accept': 'application/json'
cli.azure.cli.core.sdk.policies: 'x-ms-client-request-id': 'a781900c-af42-11ec-a1c1-0017fa03794b'
cli.azure.cli.core.sdk.policies: 'CommandName': 'monitor app-insights query'
cli.azure.cli.core.sdk.policies: 'ParameterSetName': '-a -g --analytics-query --debug'
cli.azure.cli.core.sdk.policies: 'User-Agent': 'AZURECLI/2.34.1 (RPM) azsdk-python-azure-mgmt-applicationinsights/1.0.0 Python/3.6.8 (Linux-4.18.0-193.28.1.el8_2.x86_64-x86_64-with-centos-8.2.2004-Core)'
cli.azure.cli.core.sdk.policies: 'Authorization': '*****'
cli.azure.cli.core.sdk.policies: Request body:
cli.azure.cli.core.sdk.policies: This request has no body
urllib3.connectionpool: Starting new HTTPS connection (1): management.chinacloudapi.cn:443
urllib3.connectionpool: https://management.chinacloudapi.cn:443 "GET /subscriptions/05a67b-b371-7a9d9f6a504b/resourceGroups/appinsight1/providers/Microsoft.Insights/components/appinsight1?api-version=2015-05-01 HTTP/1.1" 200 None
cli.azure.cli.core.sdk.policies: Response status: 200
cli.azure.cli.core.sdk.policies: Response headers:
cli.azure.cli.core.sdk.policies: 'Cache-Control': 'no-cache'
cli.azure.cli.core.sdk.policies: 'Pragma': 'no-cache'
cli.azure.cli.core.sdk.policies: 'Transfer-Encoding': 'chunked'
cli.azure.cli.core.sdk.policies: 'Content-Type': 'application/json; charset=utf-8'
cli.azure.cli.core.sdk.policies: 'Content-Encoding': 'gzip'
cli.azure.cli.core.sdk.policies: 'Expires': '-1'
cli.azure.cli.core.sdk.policies: 'Vary': 'Accept-Encoding'
cli.azure.cli.core.sdk.policies: 'x-ms-request-id': 'a781900c-af42-11ec-a1c1-0017fa03794b'
cli.azure.cli.core.sdk.policies: 'X-Content-Type-Options': 'nosniff'
cli.azure.cli.core.sdk.policies: 'Request-Context': 'appId=cid-v1:db04ae52-3d0a-4ee2-9101-d38e3b34bb7f'
cli.azure.cli.core.sdk.policies: 'Access-Control-Expose-Headers': 'Request-Context'
cli.azure.cli.core.sdk.policies: 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
cli.azure.cli.core.sdk.policies: 'Server': 'Microsoft-IIS/10.0'
cli.azure.cli.core.sdk.policies: 'X-Powered-By': 'ASP.NET'
cli.azure.cli.core.sdk.policies: 'x-ms-ratelimit-remaining-subscription-reads': '14999'
cli.azure.cli.core.sdk.policies: 'x-ms-correlation-request-id': 'c5f4669-bd9e-946a999a72d1'
cli.azure.cli.core.sdk.policies: 'x-ms-routing-request-id': 'CHINANORTH2:20220329T092855Z:c5f46692-1998-489a-bd9e-946a999a72d1'
cli.azure.cli.core.sdk.policies: 'Date': 'Tue, 29 Mar 2022 09:28:55 GMT'
cli.azure.cli.core.sdk.policies: Response content:
cli.azure.cli.core.sdk.policies: {"id":"/subscriptions/0xxx-e9a5-467b-b371-7a9d9f6a504b/resourceGroups/appinsight1/providers/microsoft.insights/components/appinsight1","name":"appinsight1","type":"microsoft.insights/components","location":"chinaeast2","tags":{},"kind":"web","etag":""8b004607-0000-4200-0000-61825c830000"","properties":{"Ver":"v2","ApplicationId":"appinsight1","AppId":"40d791a5-b84b-4529-afe2-431645b87ff8","Application_Type":"web","Flow_Type":"Redfield","Request_Source":"IbizaAIExtension","InstrumentationKey":"ec900281-a9ff-c4b4-871d-49cd6c3b0df4","ConnectionString":"InstrumentationKey=ec900281-a9ff-c4b4-871d-49cd6c3b0df4;EndpointSuffix=applicationinsights.azure.cn;IngestionEndpoint=https://chinaeast2-0.in.applicationinsights.azure.cn/","Name":"appinsight1","CreationDate":"2021-02-02T05:49:00.2713937+00:00","TenantId":"05a7ed23-e9a5-467b-b371-7a9d9f6a504b","provisioningState":"Succeeded","SamplingPercentage":100.0,"CustomMetricsOptedInType":"NoDimensions","RetentionInDays":90,"WorkspaceResourceId":"/subscriptions/05a7ed23-e9a5-467b-b371-7a9d9f6a504b/resourcegroups/defaultresourcegroup-cne2/providers/microsoft.operationalinsights/workspaces/defaultworkspace-05a7ed23-eb371-7a9d9f6a504b-cne2","IngestionMode":"LogAnalytics","publicNetworkAccessForIngestion":"Enabled","publicNetworkAccessForQuery":"Enabled"}}
cli.azure.cli.core.auth.credential_adaptor: CredentialAdaptor.get_token
cli.azure.cli.core.auth.msal_authentication: UserCredential.get_token: scopes=('https://api.applicationinsights.azure.cn/.default',), kwargs={}
msal.application: Cache hit an AT
msal.telemetry: Generate or reuse correlation_id: a3c12794-8c90-426d-981a-52b40b5eff46
msrest.universal_http: Configuring redirects: allow=True, max=30
msrest.universal_http: Configuring request: timeout=100, verify=True, cert=None
msrest.universal_http: Configuring proxies: ''
msrest.universal_http: Evaluate proxies against ENV settings: True
urllib3.connectionpool: Starting new HTTPS connection (1): api.applicationinsights.io:443
urllib3.connectionpool: https://api.applicationinsights.io:443 "POST /v1/apps/40d791a5-b84b-4529-afe2-431645b87ff8/query HTTP/1.1" 404 147
msrest.exceptions: (ApplicationNotFoundError) The application could not be found
cli.azure.cli.core.util: azure.cli.core.util.handle_exception is called with an exception:
cli.azure.cli.core.util: Traceback (most recent call last):
File "/usr/lib64/az/lib/python3.6/site-packages/knack/cli.py", line 231, in invoke
cmd_result = self.invocation.execute(args)
File "/usr/lib64/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 658, in execute
raise ex
File "/usr/lib64/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 721, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
File "/usr/lib64/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 692, in _run_job
result = cmd_copy(params)
File "/usr/lib64/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 328, in call
return self.handler(*args, **kwargs)
File "/usr/lib64/az/lib/python3.6/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
return op(**command_args)
File "/root/.azure/cliextensions/application-insights/azext_applicationinsights/custom.py", line 36, in execute_query
raise ex
File "/root/.azure/cliextensions/application-insights/azext_applicationinsights/custom.py", line 32, in execute_query
return client.query.execute(targets[0], QueryBody(query=analytics_query, timespan=get_timespan(cmd.cli_ctx, start_time, end_time, offset), applications=targets[1:]))
File "/root/.azure/cliextensions/application-insights/azext_applicationinsights/vendored_sdks/applicationinsights/operations/query_operations.py", line 87, in execute
raise models.ErrorResponseException(self._deserialize, response)
azext_applicationinsights.vendored_sdks.applicationinsights.models.error_response_py3.ErrorResponseException: (ApplicationNotFoundError) The application could not be found
cli.azure.cli.core.azclierror: ApplicationNotFoundError: The application could not be found
az_command_data_logger: ApplicationNotFoundError: The application could not be found
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x7f9d94c392f0>]
az_command_data_logger: exit code: 3
cli.main: Command ran in 1.108 seconds (init: 0.167, invoke: 0.941)
telemetry.save: Save telemetry record of length 3227 in cache
telemetry.check: Negative: The /root/.azure/telemetry.txt was modified at 2022-03-29 09:26:07.336263, which in less than 600.000000 s
cli.azure.cli.core.auth.identity: _dumtelemetry.check: Negative: The /root/.azure/telemetry.txt was modified at 2022-03-29 09:26:07.336263, which in less than 600.000000 s
cli.azure.cli.core.auth.identity: _dump_msal_http_cache: /root/.azure/msal_http_cache.binp_msal_http_cache: /root/.azure/msal_http_cache.bin
i think it cause by connect to https://api.applicationinsights.io:443 error:
https://docs.microsoft.com/en-us/azure/azure-monitor/app/profiler-troubleshooting
App Setting China Cloud
ApplicationInsightsProfilerEndpoint https://profiler.monitor.azure.cn
ApplicationInsightsEndpoint https://dc.applicationinsights.azure.cn
Activity