We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
app-insights az cli extension seems not working properly in AzureChinaCloud (China East 2)
- If the issue is to do with Azure CLI 2.0 in-particular, create an issue here at [Azure/azure-cli](https://github.com/Azure/azure-cli/issues)

### Extension name (the extension in question)
application-insights

### Description of issue (in as much detail as possible)
I have properly logged in with a certain subscription in AzureChinaCloud (China East2)
```
az account show
{
  "environmentName": "AzureChinaCloud",
  "id": "5b5d5f37-8aca-49f8-8682-7ed6d2f00424",
  "isDefault": true,
  "name": "Project Vienna PROD - ChinaEast2",
  "state": "Enabled",
  "tenantId": "a55a4d5b-9241-49b1-b4ff-befa8db00269",
  "user": {
    "name": "oe-wanglongjiang@cme.gbl",
    "type": "user"
  }
}
```
However run any az monitor app-insights command always failed with error "The subscription '5b5d5f37-8aca-49f8-8682-7ed6d2f00424' could not be found" 

for example, api-key show
```
az monitor app-insights api-key show --app model-monitoring-chinaeast2 --resource-group model-mgmt-chinaeast2 --api-key MMSModelMonitoringApiKey
The subscription '5b5d5f37-8aca-49f8-8682-7ed6d2f00424' could not be found.
```

I doubted application-insights is not working in AzureChinaCloud, any insight of it? Appreciate

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/application-insights/setup.py`
Content:
```
1 #!/usr/bin/env python
2 
3 # --------------------------------------------------------------------------------------------
4 # Copyright (c) Microsoft Corporation. All rights reserved.
5 # Licensed under the MIT License. See License.txt in the project root for license information.
6 # --------------------------------------------------------------------------------------------
7 
8 from codecs import open
9 from setuptools import setup, find_packages
10 
11 VERSION = "0.1.1"
12 
13 CLASSIFIERS = [
14     'Development Status :: 4 - Beta',
15     'Intended Audience :: Developers',
16     'Intended Audience :: System Administrators',
17     'Programming Language :: Python',
18     'Programming Language :: Python :: 2',
19     'Programming Language :: Python :: 2.7',
20     'Programming Language :: Python :: 3',
21     'Programming Language :: Python :: 3.4',
22     'Programming Language :: Python :: 3.5',
23     'Programming Language :: Python :: 3.6',
24     'License :: OSI Approved :: MIT License',
25 ]
26 
27 DEPENDENCIES = []
28 
29 with open('README.rst', 'r', encoding='utf-8') as f:
30     README = f.read()
31 with open('HISTORY.rst', 'r', encoding='utf-8') as f:
32     HISTORY = f.read()
33 
34 setup(
35     name='application-insights',
36     version=VERSION,
37     description='Support for managing Application Insights components and querying metrics, events, and logs from such components.',
38     long_description=README + '\n\n' + HISTORY,
39     license='MIT',
40     author='Ace Eldeib',
41     author_email='aleldeib@microsoft.com',
42     url='https://github.com/Azure/azure-cli-extensions/tree/master/src/application-insights',
43     classifiers=CLASSIFIERS,
44     packages=find_packages(exclude=["tests"]),
45     package_data={'azext_applicationinsights': ['azext_metadata.json']},
46     install_requires=DEPENDENCIES
47 )
48
```

Path: `src/application-insights/azext_applicationinsights/_client_factory.py`
Content:
```
1 # --------------------------------------------------------------------------------------------
2 # Copyright (c) Microsoft Corporation. All rights reserved.
3 # Licensed under the MIT License. See License.txt in the project root for license information.
4 # --------------------------------------------------------------------------------------------
5 
6 
7 def applicationinsights_data_plane_client(cli_ctx, _, subscription=None):
8     """Initialize Log Analytics data client for use with CLI."""
9     from .vendored_sdks.applicationinsights import ApplicationInsightsDataClient
10     from azure.cli.core._profile import Profile
11     profile = Profile(cli_ctx=cli_ctx)
12     cred, _, _ = profile.get_login_credentials(
13         resource="https://api.applicationinsights.io",
14         subscription_id=subscription
15     )
16     return ApplicationInsightsDataClient(cred)
17 
18 
19 def applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=None):
20     """Initialize Log Analytics mgmt client for use with CLI."""
21     from .vendored_sdks.mgmt_applicationinsights import ApplicationInsightsManagementClient
22     from azure.cli.core._profile import Profile
23     profile = Profile(cli_ctx=cli_ctx)
24     # Use subscription from resource_id where possible, otherwise use login.
25     if subscription:
26         cred, _, _ = profile.get_login_credentials(subscription_id=subscription)
27         return ApplicationInsightsManagementClient(
28             cred,
29             subscription
30         )
31     cred, sub_id, _ = profile.get_login_credentials()
32     return ApplicationInsightsManagementClient(
33         cred,
34         sub_id
35     )
36 
37 
38 def cf_query(cli_ctx, _, subscription=None):
39     return applicationinsights_data_plane_client(cli_ctx, _, subscription=subscription).query
40 
41 
42 def cf_metrics(cli_ctx, _, subscription=None):
43     return applicationinsights_data_plane_client(cli_ctx, _, subscription=subscription).metrics
44 
45 
46 def cf_events(cli_ctx, _, subscription=None):
47     return applicationinsights_data_plane_client(cli_ctx, _, subscription=subscription).events
48 
49 
50 def cf_components(cli_ctx, _, subscription=None):
51     return applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=subscription).components
52 
53 
54 def cf_api_key(cli_ctx, _, subscription=None):
55     return applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=subscription).api_keys
56
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/application-insights/azext_applicationinsights/_client_factory.py b/src/application-insights/azext_applicationinsights/_client_factory.py
--- a/src/application-insights/azext_applicationinsights/_client_factory.py
+++ b/src/application-insights/azext_applicationinsights/_client_factory.py
@@ -10,7 +10,7 @@
     from azure.cli.core._profile import Profile
     profile = Profile(cli_ctx=cli_ctx)
     cred, _, _ = profile.get_login_credentials(
-        resource="https://api.applicationinsights.io",
+        resource=cli_ctx.cloud.endpoints.app_insights_resource_id,
         subscription_id=subscription
     )
     return ApplicationInsightsDataClient(cred)
@@ -19,20 +19,8 @@
 def applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=None):
     """Initialize Log Analytics mgmt client for use with CLI."""
     from .vendored_sdks.mgmt_applicationinsights import ApplicationInsightsManagementClient
-    from azure.cli.core._profile import Profile
-    profile = Profile(cli_ctx=cli_ctx)
-    # Use subscription from resource_id where possible, otherwise use login.
-    if subscription:
-        cred, _, _ = profile.get_login_credentials(subscription_id=subscription)
-        return ApplicationInsightsManagementClient(
-            cred,
-            subscription
-        )
-    cred, sub_id, _ = profile.get_login_credentials()
-    return ApplicationInsightsManagementClient(
-        cred,
-        sub_id
-    )
+    from azure.cli.core.commands.client_factory import get_mgmt_service_client
+    return get_mgmt_service_client(cli_ctx, ApplicationInsightsManagementClient, subscription_id=subscription)
 
 
 def cf_query(cli_ctx, _, subscription=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.1"
+VERSION = "0.1.2"
 
 CLASSIFIERS = [
     'Development Status :: 4 - Beta',

{"golden_diff": "diff --git a/src/application-insights/azext_applicationinsights/_client_factory.py b/src/application-insights/azext_applicationinsights/_client_factory.py\n--- a/src/application-insights/azext_applicationinsights/_client_factory.py\n+++ b/src/application-insights/azext_applicationinsights/_client_factory.py\n@@ -10,7 +10,7 @@\n     from azure.cli.core._profile import Profile\n     profile = Profile(cli_ctx=cli_ctx)\n     cred, _, _ = profile.get_login_credentials(\n-        resource=\"https://api.applicationinsights.io\",\n+        resource=cli_ctx.cloud.endpoints.app_insights_resource_id,\n         subscription_id=subscription\n     )\n     return ApplicationInsightsDataClient(cred)\n@@ -19,20 +19,8 @@\n def applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=None):\n     \"\"\"Initialize Log Analytics mgmt client for use with CLI.\"\"\"\n     from .vendored_sdks.mgmt_applicationinsights import ApplicationInsightsManagementClient\n-    from azure.cli.core._profile import Profile\n-    profile = Profile(cli_ctx=cli_ctx)\n-    # Use subscription from resource_id where possible, otherwise use login.\n-    if subscription:\n-        cred, _, _ = profile.get_login_credentials(subscription_id=subscription)\n-        return ApplicationInsightsManagementClient(\n-            cred,\n-            subscription\n-        )\n-    cred, sub_id, _ = profile.get_login_credentials()\n-    return ApplicationInsightsManagementClient(\n-        cred,\n-        sub_id\n-    )\n+    from azure.cli.core.commands.client_factory import get_mgmt_service_client\n+    return get_mgmt_service_client(cli_ctx, ApplicationInsightsManagementClient, subscription_id=subscription)\n \n \n def cf_query(cli_ctx, _, subscription=None):\ndiff --git a/src/application-insights/setup.py b/src/application-insights/setup.py\n--- a/src/application-insights/setup.py\n+++ b/src/application-insights/setup.py\n@@ -8,7 +8,7 @@\n from codecs import open\n from setuptools import setup, find_packages\n \n-VERSION = \"0.1.1\"\n+VERSION = \"0.1.2\"\n \n CLASSIFIERS = [\n     'Development Status :: 4 - Beta',\n", "issue": "app-insights az cli extension seems not working properly in AzureChinaCloud (China East 2)\n- If the issue is to do with Azure CLI 2.0 in-particular, create an issue here at [Azure/azure-cli](https://github.com/Azure/azure-cli/issues)\r\n\r\n### Extension name (the extension in question)\r\napplication-insights\r\n\r\n### Description of issue (in as much detail as possible)\r\nI have properly logged in with a certain subscription in AzureChinaCloud (China East2)\r\n```\r\naz account show\r\n{\r\n  \"environmentName\": \"AzureChinaCloud\",\r\n  \"id\": \"5b5d5f37-8aca-49f8-8682-7ed6d2f00424\",\r\n  \"isDefault\": true,\r\n  \"name\": \"Project Vienna PROD - ChinaEast2\",\r\n  \"state\": \"Enabled\",\r\n  \"tenantId\": \"a55a4d5b-9241-49b1-b4ff-befa8db00269\",\r\n  \"user\": {\r\n    \"name\": \"oe-wanglongjiang@cme.gbl\",\r\n    \"type\": \"user\"\r\n  }\r\n}\r\n```\r\nHowever run any az monitor app-insights command always failed with error \"The subscription '5b5d5f37-8aca-49f8-8682-7ed6d2f00424' could not be found\" \r\n\r\nfor example, api-key show\r\n```\r\naz monitor app-insights api-key show --app model-monitoring-chinaeast2 --resource-group model-mgmt-chinaeast2 --api-key MMSModelMonitoringApiKey\r\nThe subscription '5b5d5f37-8aca-49f8-8682-7ed6d2f00424' could not be found.\r\n```\r\n\r\nI doubted application-insights is not working in AzureChinaCloud, any insight of it? Appreciate\n", "before_files": [{"content": "#!/usr/bin/env python\n\n# --------------------------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for license information.\n# --------------------------------------------------------------------------------------------\n\nfrom codecs import open\nfrom setuptools import setup, find_packages\n\nVERSION = \"0.1.1\"\n\nCLASSIFIERS = [\n    'Development Status :: 4 - Beta',\n    'Intended Audience :: Developers',\n    'Intended Audience :: System Administrators',\n    'Programming Language :: Python',\n    'Programming Language :: Python :: 2',\n    'Programming Language :: Python :: 2.7',\n    'Programming Language :: Python :: 3',\n    'Programming Language :: Python :: 3.4',\n    'Programming Language :: Python :: 3.5',\n    'Programming Language :: Python :: 3.6',\n    'License :: OSI Approved :: MIT License',\n]\n\nDEPENDENCIES = []\n\nwith open('README.rst', 'r', encoding='utf-8') as f:\n    README = f.read()\nwith open('HISTORY.rst', 'r', encoding='utf-8') as f:\n    HISTORY = f.read()\n\nsetup(\n    name='application-insights',\n    version=VERSION,\n    description='Support for managing Application Insights components and querying metrics, events, and logs from such components.',\n    long_description=README + '\\n\\n' + HISTORY,\n    license='MIT',\n    author='Ace Eldeib',\n    author_email='aleldeib@microsoft.com',\n    url='https://github.com/Azure/azure-cli-extensions/tree/master/src/application-insights',\n    classifiers=CLASSIFIERS,\n    packages=find_packages(exclude=[\"tests\"]),\n    package_data={'azext_applicationinsights': ['azext_metadata.json']},\n    install_requires=DEPENDENCIES\n)\n", "path": "src/application-insights/setup.py"}, {"content": "# --------------------------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for license information.\n# --------------------------------------------------------------------------------------------\n\n\ndef applicationinsights_data_plane_client(cli_ctx, _, subscription=None):\n    \"\"\"Initialize Log Analytics data client for use with CLI.\"\"\"\n    from .vendored_sdks.applicationinsights import ApplicationInsightsDataClient\n    from azure.cli.core._profile import Profile\n    profile = Profile(cli_ctx=cli_ctx)\n    cred, _, _ = profile.get_login_credentials(\n        resource=\"https://api.applicationinsights.io\",\n        subscription_id=subscription\n    )\n    return ApplicationInsightsDataClient(cred)\n\n\ndef applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=None):\n    \"\"\"Initialize Log Analytics mgmt client for use with CLI.\"\"\"\n    from .vendored_sdks.mgmt_applicationinsights import ApplicationInsightsManagementClient\n    from azure.cli.core._profile import Profile\n    profile = Profile(cli_ctx=cli_ctx)\n    # Use subscription from resource_id where possible, otherwise use login.\n    if subscription:\n        cred, _, _ = profile.get_login_credentials(subscription_id=subscription)\n        return ApplicationInsightsManagementClient(\n            cred,\n            subscription\n        )\n    cred, sub_id, _ = profile.get_login_credentials()\n    return ApplicationInsightsManagementClient(\n        cred,\n        sub_id\n    )\n\n\ndef cf_query(cli_ctx, _, subscription=None):\n    return applicationinsights_data_plane_client(cli_ctx, _, subscription=subscription).query\n\n\ndef cf_metrics(cli_ctx, _, subscription=None):\n    return applicationinsights_data_plane_client(cli_ctx, _, subscription=subscription).metrics\n\n\ndef cf_events(cli_ctx, _, subscription=None):\n    return applicationinsights_data_plane_client(cli_ctx, _, subscription=subscription).events\n\n\ndef cf_components(cli_ctx, _, subscription=None):\n    return applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=subscription).components\n\n\ndef cf_api_key(cli_ctx, _, subscription=None):\n    return applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=subscription).api_keys\n", "path": "src/application-insights/azext_applicationinsights/_client_factory.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\n# --------------------------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for license information.\n# --------------------------------------------------------------------------------------------\n\nfrom codecs import open\nfrom setuptools import setup, find_packages\n\nVERSION = \"0.1.2\"\n\nCLASSIFIERS = [\n    'Development Status :: 4 - Beta',\n    'Intended Audience :: Developers',\n    'Intended Audience :: System Administrators',\n    'Programming Language :: Python',\n    'Programming Language :: Python :: 2',\n    'Programming Language :: Python :: 2.7',\n    'Programming Language :: Python :: 3',\n    'Programming Language :: Python :: 3.4',\n    'Programming Language :: Python :: 3.5',\n    'Programming Language :: Python :: 3.6',\n    'License :: OSI Approved :: MIT License',\n]\n\nDEPENDENCIES = []\n\nwith open('README.rst', 'r', encoding='utf-8') as f:\n    README = f.read()\nwith open('HISTORY.rst', 'r', encoding='utf-8') as f:\n    HISTORY = f.read()\n\nsetup(\n    name='application-insights',\n    version=VERSION,\n    description='Support for managing Application Insights components and querying metrics, events, and logs from such components.',\n    long_description=README + '\\n\\n' + HISTORY,\n    license='MIT',\n    author='Ace Eldeib',\n    author_email='aleldeib@microsoft.com',\n    url='https://github.com/Azure/azure-cli-extensions/tree/master/src/application-insights',\n    classifiers=CLASSIFIERS,\n    packages=find_packages(exclude=[\"tests\"]),\n    package_data={'azext_applicationinsights': ['azext_metadata.json']},\n    install_requires=DEPENDENCIES\n)\n", "path": "src/application-insights/setup.py"}, {"content": "# --------------------------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for license information.\n# --------------------------------------------------------------------------------------------\n\n\ndef applicationinsights_data_plane_client(cli_ctx, _, subscription=None):\n    \"\"\"Initialize Log Analytics data client for use with CLI.\"\"\"\n    from .vendored_sdks.applicationinsights import ApplicationInsightsDataClient\n    from azure.cli.core._profile import Profile\n    profile = Profile(cli_ctx=cli_ctx)\n    cred, _, _ = profile.get_login_credentials(\n        resource=cli_ctx.cloud.endpoints.app_insights_resource_id,\n        subscription_id=subscription\n    )\n    return ApplicationInsightsDataClient(cred)\n\n\ndef applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=None):\n    \"\"\"Initialize Log Analytics mgmt client for use with CLI.\"\"\"\n    from .vendored_sdks.mgmt_applicationinsights import ApplicationInsightsManagementClient\n    from azure.cli.core.commands.client_factory import get_mgmt_service_client\n    return get_mgmt_service_client(cli_ctx, ApplicationInsightsManagementClient, subscription_id=subscription)\n\n\ndef cf_query(cli_ctx, _, subscription=None):\n    return applicationinsights_data_plane_client(cli_ctx, _, subscription=subscription).query\n\n\ndef cf_metrics(cli_ctx, _, subscription=None):\n    return applicationinsights_data_plane_client(cli_ctx, _, subscription=subscription).metrics\n\n\ndef cf_events(cli_ctx, _, subscription=None):\n    return applicationinsights_data_plane_client(cli_ctx, _, subscription=subscription).events\n\n\ndef cf_components(cli_ctx, _, subscription=None):\n    return applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=subscription).components\n\n\ndef cf_api_key(cli_ctx, _, subscription=None):\n    return applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=subscription).api_keys\n", "path": "src/application-insights/azext_applicationinsights/_client_factory.py"}]}