Skip to content

[log-analytics] az monitor log-analytics query fails in AzureChinaCloud with CloudEndpointNotSetException #10318

Description

@x-engineering-agent

Source: Azure/azure-cli#32631 (by MattCosturos)
Affected extension: log-analytics (src/log-analytics/)


<<UNTRUSTED:issue-32631>>

Issue #32631 (by MattCosturos)

Title

az monitor log-analytics query fails in AzureChinaCloud with CloudEndpointNotSetException

Body

Describe the bug

When running az monitor log-analytics query in Azure China (AzureChinaCloud), the command consistently fails with:

azure.cli.core.cloud.CloudEndpointNotSetException
The exception is thrown during client initialization, before any HTTP request is sent to the Log Analytics service.

This issue occurs across:

Different workspaces
Different KQL queries (e.g. Usage, AzureDiagnostics, StorageBlobLogs)

To Reproduce
Set Azure CLI cloud to Azure China:

az cloud set --name AzureChinaCloud
Login:

az login
Run any Log Analytics query:

az monitor log-analytics query \
--workspace \
--analytics-query "Usage"

Expected behavior
The command should successfully execute the Log Analytics query and return results, the same way it does in Azure Public Cloud.

Actual behavior
The command fails immediately with:

azure.cli.core.cloud.CloudEndpointNotSetException
No HTTP request is sent to the Log Analytics service.

Debug output
Relevant part of the stack trace:

File ".../azext_loganalytics/aaz/latest/monitor/log_analytics/_query.py", line 75
self.QueryExecute(ctx=self.ctx)()

File ".../azure/cli/core/aaz/_operation.py", line 37, in init
self.client = ctx.get_http_client(self.CLIENT_TYPE)

File ".../azure/cli/core/aaz/_client.py", line 75, in init
raise CloudEndpointNotSetException()

azure.cli.core.cloud.CloudEndpointNotSetException

Analysis / Root Cause
Based on the Azure CLI Core implementation in:

azure/cli/core/_profile.py
Azure CLI resolves service endpoints from the current cloud profile:

endpoint = cloud.endpoints.get(endpoint_name)
if not endpoint:
raise CloudEndpointNotSetException()
In AzureChinaCloud, the cloud profile does not appear to define the required endpoint for Log Analytics Query used by the log-analytics extension (AAZ-based).

As a result:

Client initialization fails
CloudEndpointNotSetException is raised
The query is never executed
This suggests a missing or incomplete Log Analytics endpoint definition for AzureChinaCloud, rather than a user configuration or query issue.

Environment
Azure CLI version:

az version

2.78.0

Extension:

log-analytics 1.0.0b1
OS:Windows 11

Cloud: AzureChinaCloud

Other Log Analytics access methods (e.g. REST API / PowerShell) work in Azure China
This appears to be a gap in Sovereign Cloud support for the new AAZ-based log-analytics extension
**Ask
Please confirm whether this is a known issue and advise:

Whether a missing endpoint definition for AzureChinaCloud needs to be added
Or if there is a recommended workaround until full support is available**

Related command

az monitor log-analytics query --workspace XXXXX --analytics-query 'kusto query' --debug

Errors

PS C:\Users<[~]USER>\AppData\Roaming\Code\User> az monitor log-analytics query --workspace <WORKSPACE_ID> --analytics-query <KQL_QUERY> --debug

cli.knack.cli: Command arguments:
['monitor', 'log-analytics', 'query',
'--workspace', '<WORKSPACE_ID>',
'--analytics-query', '<KQL_QUERY>',
'--debug']

cli.knack.cli: init debug log: Enable color in terminal.
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [...]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []

cli.azure.cli.core: Modules found from index for 'monitor':
['azure.cli.command_modules.monitor', 'azext_loganalytics']

cli.azure.cli.core: Loading command modules:
Name Load Time Groups Commands
monitor 1.729 23 70

cli.azure.cli.core: Loading extensions:
Name Load Time Groups Commands Directory
log-analytics 0.018 2 1 C:\Users<[~]USER>.azure\cliextensions\log-analytics

cli.azure.cli.core: Loaded 23 groups, 71 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command : monitor log-analytics query
cli.azure.cli.core: Command table: monitor log-analytics query

cli.azure.cli.core.azlogging:
metadata file logging enabled - writing logs to:
C:\Users<[~]USER>.azure\commands<TIMESTAMP>.monitor_log-analytics_query.log

az_command_data_logger:
command args: monitor log-analytics query --workspace {} --analytics-query {} --debug

az_command_data_logger:
extension name: log-analytics
extension version: 1.0.0b

Issue script & Debug output

PS C:\Users<[~]USER>\AppData\Roaming\Code\User> az monitor log-analytics query --workspace <WORKSPACE_ID> --analytics-query <KQL_QUERY> --debug

cli.knack.cli: Command arguments:
['monitor', 'log-analytics', 'query',
'--workspace', '<WORKSPACE_ID>',
'--analytics-query', '<KQL_QUERY>',
'--debug']

cli.knack.cli: init debug log: Enable color in terminal.
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [...]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []

cli.azure.cli.core: Modules found from index for 'monitor':
['azure.cli.command_modules.monitor', 'azext_loganalytics']

cli.azure.cli.core: Loading command modules:
Name Load Time Groups Commands
monitor 1.729 23 70

cli.azure.cli.core: Loading extensions:
Name Load Time Groups Commands Directory
log-analytics 0.018 2 1 C:\Users<[~]USER>.azure\cliextensions\log-analytics

cli.azure.cli.core: Loaded 23 groups, 71 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command : monitor log-analytics query
cli.azure.cli.core: Command table: monitor log-analytics query

cli.azure.cli.core.azlogging:
metadata file logging enabled - writing logs to:
C:\Users<[~]USER>.azure\commands<TIMESTAMP>.monitor_log-analytics_query.log

az_command_data_logger:
command args: monitor log-analytics query --workspace {} --analytics-query {} --debug

az_command_data_logger:
extension name: log-analytics
extension version: 1.0.0b

Expected behavior

The command should successfully execute the Log Analytics query and return results, the same way it does in Azure Public Cloud.

Environment Summary

Cloud:
AzureChinaCloud

OS:
Windows (PowerShell)

Azure CLI:
2.78.0

Extension:
log-analytics 1.0.0b1

Additional context

No response

Comments

Comment by Yong Zhang (@yonzhan)

Thank you for opening this issue, we will look into it.

Comment by MattCosturos

Running Az cli 2.83.0, log-analytics 1.0.0b1 and USGovCloud generates the same error
<<END:issue-32631>>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions