Azure / Azure/azure-cli

az monitor log-analytics query fails in AzureChinaCloud with CloudEndpointNotSetException

Open
#32,631 6 comments 0 reactions 1 assignee Assigned to @NoriZC View on GitHub
Account act-identity-squad act-observability-squad Auto-Assign Azure CLI Team customer-reported Monitor question
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

### 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\\AppData\Roaming\Code\User> az monitor log-analytics query --workspace --analytics-query --debug

cli.knack.cli: Command arguments:
['monitor', 'log-analytics', 'query',
'--workspace', '',
'--analytics-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\\.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\\.azure\commands\.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\\AppData\Roaming\Code\User> az monitor log-analytics query --workspace --analytics-query --debug

cli.knack.cli: Command arguments:
['monitor', 'log-analytics', 'query',
'--workspace', '',
'--analytics-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\\.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\\.azure\commands\.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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.