From 8b23f72f48532ca800b42fa6529daf0838e3920f Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Fri, 4 Aug 2023 10:25:40 -0700 Subject: [PATCH 01/26] init commit for app service resource detector --- .../LICENSE | 201 ++++++++++++++++++ .../MANITEST.rst | 9 + .../README.rst | 46 ++++ .../pyproject.toml | 51 +++++ .../src/__init__.py | 67 ++++++ .../tests/__init__.py | 0 .../test_app_service_resource_detector.py | 114 ++++++++++ 7 files changed, 488 insertions(+) create mode 100644 resource/opentelemetry-resource-detector-azure-app-service/LICENSE create mode 100644 resource/opentelemetry-resource-detector-azure-app-service/MANITEST.rst create mode 100644 resource/opentelemetry-resource-detector-azure-app-service/README.rst create mode 100644 resource/opentelemetry-resource-detector-azure-app-service/pyproject.toml create mode 100644 resource/opentelemetry-resource-detector-azure-app-service/src/__init__.py create mode 100644 resource/opentelemetry-resource-detector-azure-app-service/tests/__init__.py create mode 100644 resource/opentelemetry-resource-detector-azure-app-service/tests/test_app_service_resource_detector.py diff --git a/resource/opentelemetry-resource-detector-azure-app-service/LICENSE b/resource/opentelemetry-resource-detector-azure-app-service/LICENSE new file mode 100644 index 0000000000..1ef7dad2c5 --- /dev/null +++ b/resource/opentelemetry-resource-detector-azure-app-service/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright The OpenTelemetry Authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/resource/opentelemetry-resource-detector-azure-app-service/MANITEST.rst b/resource/opentelemetry-resource-detector-azure-app-service/MANITEST.rst new file mode 100644 index 0000000000..2906eeef0f --- /dev/null +++ b/resource/opentelemetry-resource-detector-azure-app-service/MANITEST.rst @@ -0,0 +1,9 @@ +graft src +graft tests +global-exclude *.pyc +global-exclude *.pyo +global-exclude __pycache__/* +include CHANGELOG.md +include MANIFEST.in +include README.rst +include LICENSE \ No newline at end of file diff --git a/resource/opentelemetry-resource-detector-azure-app-service/README.rst b/resource/opentelemetry-resource-detector-azure-app-service/README.rst new file mode 100644 index 0000000000..b6b149254f --- /dev/null +++ b/resource/opentelemetry-resource-detector-azure-app-service/README.rst @@ -0,0 +1,46 @@ +OpenTelemetry Resource detectors for Azure App Services +========================================================== + +|pypi| + +.. |pypi| image:: TODO + :target: TODO + + +This library provides custom resource detector for container platforms + +Installation +------------ + +:: + + pip install opentelemetry-resource-detector-azure-app-service + +--------------------------- + +Usage example for `opentelemetry-resource-detector-container` + +.. code-block:: python + + from opentelemetry import trace + from opentelemetry.sdk.trace import TracerProvider + from opentelemetry.resource.detector.container import ( + ContainerResourceDetector, + ) + from opentelemetry.sdk.resources import get_aggregated_resources + + + trace.set_tracer_provider( + TracerProvider( + resource=get_aggregated_resources( + [ + ContainerResourceDetector(), + ] + ), + ) + ) + +References +---------- + +* `OpenTelemetry Project `_ diff --git a/resource/opentelemetry-resource-detector-azure-app-service/pyproject.toml b/resource/opentelemetry-resource-detector-azure-app-service/pyproject.toml new file mode 100644 index 0000000000..9503d74a0e --- /dev/null +++ b/resource/opentelemetry-resource-detector-azure-app-service/pyproject.toml @@ -0,0 +1,51 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "opentelemetry-resource-detector-container" +dynamic = ["version"] +description = "Container Resource Detector for OpenTelemetry" +readme = "README.rst" +license = "Apache-2.0" +requires-python = ">=3.7" +authors = [ + { name = "OpenTelemetry Authors", email = "cncf-opentelemetry-contributors@lists.cncf.io" }, +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", +] +dependencies = [ + "opentelemetry-sdk ~= 1.19", +] + +[project.optional-dependencies] +test = [] + +[project.entry-points.opentelemetry_resource_detector] +# TODO: could remove azure from class name +container = "opentelemetry.resource.detector.azure.app_service:AzureAppServiceResourceDetector" + +[project.urls] +Homepage = "https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/resource/opentelemetry-resource-detector-azure-app-service" + +[tool.hatch.version] +path = "src/opentelemetry/resource/detector/azure/app_service/version.py" + +[tool.hatch.build.targets.sdist] +include = [ + "/src", + "/tests", +] + +[tool.hatch.build.targets.wheel] +packages = ["src/opentelemetry"] diff --git a/resource/opentelemetry-resource-detector-azure-app-service/src/__init__.py b/resource/opentelemetry-resource-detector-azure-app-service/src/__init__.py new file mode 100644 index 0000000000..9b9bc59df5 --- /dev/null +++ b/resource/opentelemetry-resource-detector-azure-app-service/src/__init__.py @@ -0,0 +1,67 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +from os import environ + +from opentelemetry.sdk.resources import ResourceDetector, Resource +from opentelemetry.semconv.resource import ResourceAttributes, CloudPlatformValues, CloudProviderValues + +# TODO: change +from azure.monitor.opentelemetry.exporter._constants import ( + _AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE, + _CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE, + _REGION_NAME, + _WEBSITE_HOME_STAMPNAME, + _WEBSITE_HOSTNAME, + _WEBSITE_INSTANCE_ID, + _WEBSITE_OWNER_NAME, + _WEBSITE_RESOURCE_GROUP, + _WEBSITE_SITE_NAME, + _WEBSITE_SLOT_NAME, +) + + +_APP_SERVICE_ATTRIBUTE_ENV_VARS = { + ResourceAttributes.CLOUD_REGION: _REGION_NAME, + ResourceAttributes.DEPLOYMENT_ENVIRONMENT: _WEBSITE_SLOT_NAME, + ResourceAttributes.HOST_ID: _WEBSITE_HOSTNAME, + ResourceAttributes.SERVICE_INSTANCE_ID: _WEBSITE_INSTANCE_ID, + _AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE: _WEBSITE_HOME_STAMPNAME, +} + +class AzureAppServiceResourceDetector(ResourceDetector): + def detect(self) -> "Resource": + attributes = {} + website_site_name = environ.get(_WEBSITE_SITE_NAME) + if website_site_name: + print(_WEBSITE_SITE_NAME) + attributes[ResourceAttributes.SERVICE_NAME] = website_site_name + attributes[ResourceAttributes.CLOUD_PROVIDER] = CloudProviderValues.AZURE.value + attributes[ResourceAttributes.CLOUD_PLATFORM] = CloudPlatformValues.AZURE_APP_SERVICE.value + + azure_resource_uri = _get_azure_resource_uri(website_site_name) + if azure_resource_uri: + attributes[_CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE] = azure_resource_uri + for (key, env_var) in _APP_SERVICE_ATTRIBUTE_ENV_VARS.items(): + value = environ.get(env_var) + if value: + attributes[key] = value + + print(attributes) + return Resource(attributes) + +def _get_azure_resource_uri(website_site_name): + website_resource_group = environ.get(_WEBSITE_RESOURCE_GROUP) + website_owner_name = environ.get(_WEBSITE_OWNER_NAME) + + subscription_id = website_owner_name + if website_owner_name and '+' in website_owner_name: + subscription_id = website_owner_name[0:website_owner_name.index('+')] + + if not (website_resource_group and subscription_id): + return None + + return "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Web/sites/%s" % ( + subscription_id, + website_resource_group, + website_site_name, + ) diff --git a/resource/opentelemetry-resource-detector-azure-app-service/tests/__init__.py b/resource/opentelemetry-resource-detector-azure-app-service/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/resource/opentelemetry-resource-detector-azure-app-service/tests/test_app_service_resource_detector.py b/resource/opentelemetry-resource-detector-azure-app-service/tests/test_app_service_resource_detector.py new file mode 100644 index 0000000000..f099f8a297 --- /dev/null +++ b/resource/opentelemetry-resource-detector-azure-app-service/tests/test_app_service_resource_detector.py @@ -0,0 +1,114 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +import unittest +from unittest.mock import patch + +from azure.monitor.opentelemetry.exporter.resource.app_service_resource_detector import ( + AzureAppServiceResourceDetector, +) + +TEST_WEBSITE_SITE_NAME = "TEST_WEBSITE_SITE_NAME" +TEST_REGION_NAME = "TEST_REGION_NAME" +TEST_WEBSITE_SLOT_NAME = "TEST_WEBSITE_SLOT_NAME" +TEST_WEBSITE_HOSTNAME = "TEST_WEBSITE_HOSTNAME" +TEST_WEBSITE_INSTANCE_ID = "TEST_WEBSITE_INSTANCE_ID" +TEST_WEBSITE_HOME_STAMPNAME = "TEST_WEBSITE_HOME_STAMPNAME" + +TEST_WEBSITE_RESOURCE_GROUP = "TEST_WEBSITE_RESOURCE_GROUP" +TEST_WEBSITE_OWNER_NAME = "TEST_WEBSITE_OWNER_NAME" + +class TestAzureAppServiceResourceDetector(unittest.TestCase): + @patch.dict("os.environ", { + "WEBSITE_SITE_NAME": TEST_WEBSITE_SITE_NAME, + "REGION_NAME": TEST_REGION_NAME, + "WEBSITE_SLOT_NAME": TEST_WEBSITE_SLOT_NAME, + "WEBSITE_HOSTNAME": TEST_WEBSITE_HOSTNAME, + "WEBSITE_INSTANCE_ID": TEST_WEBSITE_INSTANCE_ID, + "WEBSITE_HOME_STAMPNAME": TEST_WEBSITE_HOME_STAMPNAME, + "WEBSITE_RESOURCE_GROUP": TEST_WEBSITE_RESOURCE_GROUP, + "WEBSITE_OWNER_NAME": TEST_WEBSITE_OWNER_NAME, + }, clear=True) + def test_on_app_service(self): + resource = AzureAppServiceResourceDetector().detect() + attributes = resource.attributes + # self.assertEqual(attributes { + # "service.name": TEST_WEBSITE_SITE_NAME, + # "cloud.provider": , + # "cloud.platform": , + # "cloud.resource_id": , + # "cloud.region": , + # "deployment.environment": , + # "deployment.environment": , + # }) + self.assertEqual(attributes["service.name"], TEST_WEBSITE_SITE_NAME) + self.assertEqual(attributes["cloud.provider"], "azure") + self.assertEqual(attributes["cloud.platform"], "azure_app_service") + + self.assertEqual(attributes["cloud.resource_id"], \ + f"/subscriptions/{TEST_WEBSITE_OWNER_NAME}/resourceGroups/{TEST_WEBSITE_RESOURCE_GROUP}/providers/Microsoft.Web/sites/{TEST_WEBSITE_SITE_NAME}") + + self.assertEqual(attributes["cloud.region"], TEST_REGION_NAME) + self.assertEqual(attributes["deployment.environment"], TEST_WEBSITE_SLOT_NAME) + self.assertEqual(attributes["host.id"], TEST_WEBSITE_HOSTNAME) + self.assertEqual(attributes["service.instance.id"], TEST_WEBSITE_INSTANCE_ID) + self.assertEqual(attributes["azure.app.service.stamp"], TEST_WEBSITE_HOME_STAMPNAME) + + @patch.dict("os.environ", { + "WEBSITE_SITE_NAME": TEST_WEBSITE_SITE_NAME, + "REGION_NAME": TEST_REGION_NAME, + "WEBSITE_SLOT_NAME": TEST_WEBSITE_SLOT_NAME, + "WEBSITE_HOSTNAME": TEST_WEBSITE_HOSTNAME, + "WEBSITE_INSTANCE_ID": TEST_WEBSITE_INSTANCE_ID, + "WEBSITE_HOME_STAMPNAME": TEST_WEBSITE_HOME_STAMPNAME, + "WEBSITE_OWNER_NAME": TEST_WEBSITE_OWNER_NAME, + }, clear=True) + def test_on_app_service_no_resource_group(self): + resource = AzureAppServiceResourceDetector().detect() + attributes = resource.attributes + self.assertEqual(attributes["service.name"], TEST_WEBSITE_SITE_NAME) + self.assertEqual(attributes["cloud.provider"], "azure") + self.assertEqual(attributes["cloud.platform"], "azure_app_service") + + self.assertTrue("cloud.resource_id" not in attributes) + + self.assertEqual(attributes["cloud.region"], TEST_REGION_NAME) + self.assertEqual(attributes["deployment.environment"], TEST_WEBSITE_SLOT_NAME) + self.assertEqual(attributes["host.id"], TEST_WEBSITE_HOSTNAME) + self.assertEqual(attributes["service.instance.id"], TEST_WEBSITE_INSTANCE_ID) + self.assertEqual(attributes["azure.app.service.stamp"], TEST_WEBSITE_HOME_STAMPNAME) + + @patch.dict("os.environ", { + "WEBSITE_SITE_NAME": TEST_WEBSITE_SITE_NAME, + "REGION_NAME": TEST_REGION_NAME, + "WEBSITE_SLOT_NAME": TEST_WEBSITE_SLOT_NAME, + "WEBSITE_HOSTNAME": TEST_WEBSITE_HOSTNAME, + "WEBSITE_INSTANCE_ID": TEST_WEBSITE_INSTANCE_ID, + "WEBSITE_HOME_STAMPNAME": TEST_WEBSITE_HOME_STAMPNAME, + "WEBSITE_OWNER_NAME": TEST_WEBSITE_OWNER_NAME, + }, clear=True) + def test_on_app_service_no_owner(self): + resource = AzureAppServiceResourceDetector().detect() + attributes = resource.attributes + self.assertEqual(attributes["service.name"], TEST_WEBSITE_SITE_NAME) + self.assertEqual(attributes["cloud.provider"], "azure") + self.assertEqual(attributes["cloud.platform"], "azure_app_service") + + self.assertTrue("cloud.resource_id" not in attributes) + + self.assertEqual(attributes["cloud.region"], TEST_REGION_NAME) + self.assertEqual(attributes["deployment.environment"], TEST_WEBSITE_SLOT_NAME) + self.assertEqual(attributes["host.id"], TEST_WEBSITE_HOSTNAME) + self.assertEqual(attributes["service.instance.id"], TEST_WEBSITE_INSTANCE_ID) + self.assertEqual(attributes["azure.app.service.stamp"], TEST_WEBSITE_HOME_STAMPNAME) + + @patch.dict("os.environ", { + "REGION_NAME": TEST_REGION_NAME, + "WEBSITE_SLOT_NAME": TEST_WEBSITE_SLOT_NAME, + "WEBSITE_HOSTNAME": TEST_WEBSITE_HOSTNAME, + "WEBSITE_INSTANCE_ID": TEST_WEBSITE_INSTANCE_ID, + "WEBSITE_HOME_STAMPNAME": TEST_WEBSITE_HOME_STAMPNAME, + "WEBSITE_OWNER_NAME": TEST_WEBSITE_OWNER_NAME, + }, clear=True) + def test_off_app_service(self): + resource = AzureAppServiceResourceDetector().detect() + self.assertEqual(resource.attributes, {}) From 67dbe64c6cc989dbf66f2d7817f01387c1fc65f3 Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Fri, 4 Aug 2023 10:39:29 -0700 Subject: [PATCH 02/26] Tests pass --- .../LICENSE | 222 ++---------------- .../detector/azure/app_service}/__init__.py | 24 +- .../detector/azure/app_service/version.py | 4 + .../tests/__init__.py | 2 + .../test_app_service_resource_detector.py | 2 +- 5 files changed, 39 insertions(+), 215 deletions(-) rename resource/opentelemetry-resource-detector-azure-app-service/src/{ => opentelemetry/resource/detector/azure/app_service}/__init__.py (80%) create mode 100644 resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/version.py diff --git a/resource/opentelemetry-resource-detector-azure-app-service/LICENSE b/resource/opentelemetry-resource-detector-azure-app-service/LICENSE index 1ef7dad2c5..63447fd8bb 100644 --- a/resource/opentelemetry-resource-detector-azure-app-service/LICENSE +++ b/resource/opentelemetry-resource-detector-azure-app-service/LICENSE @@ -1,201 +1,21 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright The OpenTelemetry Authors - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +Copyright (c) Microsoft Corporation. + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/resource/opentelemetry-resource-detector-azure-app-service/src/__init__.py b/resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/__init__.py similarity index 80% rename from resource/opentelemetry-resource-detector-azure-app-service/src/__init__.py rename to resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/__init__.py index 9b9bc59df5..b05a869394 100644 --- a/resource/opentelemetry-resource-detector-azure-app-service/src/__init__.py +++ b/resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/__init__.py @@ -5,19 +5,17 @@ from opentelemetry.sdk.resources import ResourceDetector, Resource from opentelemetry.semconv.resource import ResourceAttributes, CloudPlatformValues, CloudProviderValues -# TODO: change -from azure.monitor.opentelemetry.exporter._constants import ( - _AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE, - _CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE, - _REGION_NAME, - _WEBSITE_HOME_STAMPNAME, - _WEBSITE_HOSTNAME, - _WEBSITE_INSTANCE_ID, - _WEBSITE_OWNER_NAME, - _WEBSITE_RESOURCE_GROUP, - _WEBSITE_SITE_NAME, - _WEBSITE_SLOT_NAME, -) +_AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE = "azure.app.service.stamp" +# TODO: Remove once this resource attribute is no longer missing from SDK +_CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE = "cloud.resource_id" +_REGION_NAME = "REGION_NAME" +_WEBSITE_HOME_STAMPNAME = "WEBSITE_HOME_STAMPNAME" +_WEBSITE_HOSTNAME = "WEBSITE_HOSTNAME" +_WEBSITE_INSTANCE_ID = "WEBSITE_INSTANCE_ID" +_WEBSITE_OWNER_NAME = "WEBSITE_OWNER_NAME" +_WEBSITE_RESOURCE_GROUP = "WEBSITE_RESOURCE_GROUP" +_WEBSITE_SITE_NAME = "WEBSITE_SITE_NAME" +_WEBSITE_SLOT_NAME = "WEBSITE_SLOT_NAME" _APP_SERVICE_ATTRIBUTE_ENV_VARS = { diff --git a/resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/version.py b/resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/version.py new file mode 100644 index 0000000000..a0e1bb43d9 --- /dev/null +++ b/resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/version.py @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +__version__ = "0.41b0.dev" diff --git a/resource/opentelemetry-resource-detector-azure-app-service/tests/__init__.py b/resource/opentelemetry-resource-detector-azure-app-service/tests/__init__.py index e69de29bb2..5b7f7a925c 100644 --- a/resource/opentelemetry-resource-detector-azure-app-service/tests/__init__.py +++ b/resource/opentelemetry-resource-detector-azure-app-service/tests/__init__.py @@ -0,0 +1,2 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. diff --git a/resource/opentelemetry-resource-detector-azure-app-service/tests/test_app_service_resource_detector.py b/resource/opentelemetry-resource-detector-azure-app-service/tests/test_app_service_resource_detector.py index f099f8a297..233656b8ee 100644 --- a/resource/opentelemetry-resource-detector-azure-app-service/tests/test_app_service_resource_detector.py +++ b/resource/opentelemetry-resource-detector-azure-app-service/tests/test_app_service_resource_detector.py @@ -3,7 +3,7 @@ import unittest from unittest.mock import patch -from azure.monitor.opentelemetry.exporter.resource.app_service_resource_detector import ( +from opentelemetry.resource.detector.azure.app_service import ( AzureAppServiceResourceDetector, ) From 0fcf824cdd6f8db88c153a3e3dfc9db8d5bfe4a1 Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Fri, 4 Aug 2023 10:43:11 -0700 Subject: [PATCH 03/26] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c22afff6b..63f7d7e33c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-instrumentation-asgi` Fix UnboundLocalError local variable 'start' referenced before assignment ([#1889](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1889)) +### Added + +- `opentelemetry-resource-detector-azure-app-service` Add resource detector for Azure App Service + ([#XXXX](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/XXXX)) ## Version 1.19.0/0.40b0 (2023-07-13) - `opentelemetry-instrumentation-asgi` Add `http.server.request.size` metric From 68ca05c0c59f9d6add4a6b7b4a92c82c79c2709c Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Fri, 4 Aug 2023 10:52:01 -0700 Subject: [PATCH 04/26] readme --- .../README.rst | 18 +++++++++++------- .../pyproject.toml | 3 +-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/resource/opentelemetry-resource-detector-azure-app-service/README.rst b/resource/opentelemetry-resource-detector-azure-app-service/README.rst index b6b149254f..6a9f03cd8b 100644 --- a/resource/opentelemetry-resource-detector-azure-app-service/README.rst +++ b/resource/opentelemetry-resource-detector-azure-app-service/README.rst @@ -3,11 +3,11 @@ OpenTelemetry Resource detectors for Azure App Services |pypi| -.. |pypi| image:: TODO - :target: TODO +.. |pypi| image:: https://badge.fury.io/py/opentelemetry-resource-detector-azure-app-service.svg + :target: https://pypi.org/project/opentelemetry-resource-detector-azure-app-service/ -This library provides custom resource detector for container platforms +This library provides custom resource detector for Azure App Services Installation ------------ @@ -18,14 +18,14 @@ Installation --------------------------- -Usage example for `opentelemetry-resource-detector-container` +Usage example for `opentelemetry-resource-detector-azure-app-service` .. code-block:: python from opentelemetry import trace from opentelemetry.sdk.trace import TracerProvider - from opentelemetry.resource.detector.container import ( - ContainerResourceDetector, + from opentelemetry.resource.detector.azure.app_service import ( + AzureAppServiceResourceDetector, ) from opentelemetry.sdk.resources import get_aggregated_resources @@ -34,12 +34,16 @@ Usage example for `opentelemetry-resource-detector-container` TracerProvider( resource=get_aggregated_resources( [ - ContainerResourceDetector(), + AzureAppServiceResourceDetector(), ] ), ) ) +You can also enable the App Service Resource Detector by adding `azure_app_service` to the `OTEL_EXPERIMENTAL_RESOURCE_DETECTORS` environment variable: + +`export OTEL_EXPERIMENTAL_RESOURCE_DETECTORS=azure_app_service` + References ---------- diff --git a/resource/opentelemetry-resource-detector-azure-app-service/pyproject.toml b/resource/opentelemetry-resource-detector-azure-app-service/pyproject.toml index 9503d74a0e..8de8be8af1 100644 --- a/resource/opentelemetry-resource-detector-azure-app-service/pyproject.toml +++ b/resource/opentelemetry-resource-detector-azure-app-service/pyproject.toml @@ -32,8 +32,7 @@ dependencies = [ test = [] [project.entry-points.opentelemetry_resource_detector] -# TODO: could remove azure from class name -container = "opentelemetry.resource.detector.azure.app_service:AzureAppServiceResourceDetector" +azure_app_service = "opentelemetry.resource.detector.azure.app_service:AzureAppServiceResourceDetector" [project.urls] Homepage = "https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/resource/opentelemetry-resource-detector-azure-app-service" From 0a661791a590ef5cdb6a0d15156b59bc1b188203 Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Fri, 4 Aug 2023 11:11:28 -0700 Subject: [PATCH 05/26] readme --- .../README.rst | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/resource/opentelemetry-resource-detector-azure-app-service/README.rst b/resource/opentelemetry-resource-detector-azure-app-service/README.rst index 6a9f03cd8b..57f6fa09dc 100644 --- a/resource/opentelemetry-resource-detector-azure-app-service/README.rst +++ b/resource/opentelemetry-resource-detector-azure-app-service/README.rst @@ -7,7 +7,18 @@ OpenTelemetry Resource detectors for Azure App Services :target: https://pypi.org/project/opentelemetry-resource-detector-azure-app-service/ -This library provides custom resource detector for Azure App Services +This library provides custom resource detector for Azure App Services. OpenTelemetry Python has an experimental feature whereby Resource Detectors can be injected to Resource Attributes. This package includes a resource detector for Azure App Service. This detector fills out the following Resource Attributes: + * `service.name` + * `cloud.provider` + * `cloud.platform` + * `cloud.resource_id` + * `cloud.region` + * `deployment.environment` + * `host.id` + * `service.instance.id` + * `azure.app.service.stamp` + + For more information, see the Semantic Conventions for Cloud Resource Attributes. Installation ------------ @@ -48,3 +59,5 @@ References ---------- * `OpenTelemetry Project `_ +* `Resource Detector Docs ` +* `Cloud Semantic Conventions `_ From 72d979783509c6c4dcf04c09114138713e4edc18 Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Mon, 7 Aug 2023 11:39:35 -0700 Subject: [PATCH 06/26] Readme and commented code --- .../README.rst | 24 ++++++++++++------- .../test_app_service_resource_detector.py | 9 ------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/resource/opentelemetry-resource-detector-azure-app-service/README.rst b/resource/opentelemetry-resource-detector-azure-app-service/README.rst index 57f6fa09dc..9df5dbccdd 100644 --- a/resource/opentelemetry-resource-detector-azure-app-service/README.rst +++ b/resource/opentelemetry-resource-detector-azure-app-service/README.rst @@ -8,15 +8,21 @@ OpenTelemetry Resource detectors for Azure App Services This library provides custom resource detector for Azure App Services. OpenTelemetry Python has an experimental feature whereby Resource Detectors can be injected to Resource Attributes. This package includes a resource detector for Azure App Service. This detector fills out the following Resource Attributes: - * `service.name` - * `cloud.provider` - * `cloud.platform` - * `cloud.resource_id` - * `cloud.region` - * `deployment.environment` - * `host.id` - * `service.instance.id` - * `azure.app.service.stamp` + * `service.name` set to the value of the WEBSITE_SITE_NAME environment variable. + * `cloud.provider` set to the value of the "azure". + * `cloud.platform` set to the value of the "azure_app_service". + * `cloud.resource_id` set using the WEBSITE_RESOURCE_GROUP WEBSITE_OWNER_NAME and WEBSITE_SITE_NAME environment variables. + * `cloud.region` set to the value of the REGION_NAME environment variable. + * `deployment.environment` set to the value of the WEBSITE_SLOT_NAME environment variable. + * `host.id` set to the value of the WEBSITE_HOSTNAME environment variable. + * `service.instance.id` set to the value of the WEBSITE_INSTANCE_ID environment variable. + * `azure.app.service.stamp` set to the value of the WEBSITE_HOME_STAMPNAME environment variable. + + ResourceAttributes.CLOUD_REGION: _REGION_NAME, + ResourceAttributes.DEPLOYMENT_ENVIRONMENT: _WEBSITE_SLOT_NAME, + ResourceAttributes.HOST_ID: _WEBSITE_HOSTNAME, + ResourceAttributes.SERVICE_INSTANCE_ID: _WEBSITE_INSTANCE_ID, + _AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE: _WEBSITE_HOME_STAMPNAME, For more information, see the Semantic Conventions for Cloud Resource Attributes. diff --git a/resource/opentelemetry-resource-detector-azure-app-service/tests/test_app_service_resource_detector.py b/resource/opentelemetry-resource-detector-azure-app-service/tests/test_app_service_resource_detector.py index 233656b8ee..e520e311f4 100644 --- a/resource/opentelemetry-resource-detector-azure-app-service/tests/test_app_service_resource_detector.py +++ b/resource/opentelemetry-resource-detector-azure-app-service/tests/test_app_service_resource_detector.py @@ -31,15 +31,6 @@ class TestAzureAppServiceResourceDetector(unittest.TestCase): def test_on_app_service(self): resource = AzureAppServiceResourceDetector().detect() attributes = resource.attributes - # self.assertEqual(attributes { - # "service.name": TEST_WEBSITE_SITE_NAME, - # "cloud.provider": , - # "cloud.platform": , - # "cloud.resource_id": , - # "cloud.region": , - # "deployment.environment": , - # "deployment.environment": , - # }) self.assertEqual(attributes["service.name"], TEST_WEBSITE_SITE_NAME) self.assertEqual(attributes["cloud.provider"], "azure") self.assertEqual(attributes["cloud.platform"], "azure_app_service") From 09c4ee12e6e53c4cb4f41a9677bd0e3a062c6932 Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Mon, 7 Aug 2023 11:40:57 -0700 Subject: [PATCH 07/26] removed prints --- .../resource/detector/azure/app_service/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/__init__.py b/resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/__init__.py index b05a869394..028b3b073c 100644 --- a/resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/__init__.py +++ b/resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/__init__.py @@ -31,7 +31,6 @@ def detect(self) -> "Resource": attributes = {} website_site_name = environ.get(_WEBSITE_SITE_NAME) if website_site_name: - print(_WEBSITE_SITE_NAME) attributes[ResourceAttributes.SERVICE_NAME] = website_site_name attributes[ResourceAttributes.CLOUD_PROVIDER] = CloudProviderValues.AZURE.value attributes[ResourceAttributes.CLOUD_PLATFORM] = CloudPlatformValues.AZURE_APP_SERVICE.value @@ -44,7 +43,6 @@ def detect(self) -> "Resource": if value: attributes[key] = value - print(attributes) return Resource(attributes) def _get_azure_resource_uri(website_site_name): From 120a2465966f4b230775ff6694814dcdec16f7e8 Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Mon, 7 Aug 2023 11:42:47 -0700 Subject: [PATCH 08/26] manifest typo --- .../{MANITEST.rst => MANIFEST.rst} | 0 .../{MANITEST.rst => MANIFEST.rst} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename resource/opentelemetry-resource-detector-azure-app-service/{MANITEST.rst => MANIFEST.rst} (100%) rename resource/opentelemetry-resource-detector-container/{MANITEST.rst => MANIFEST.rst} (100%) diff --git a/resource/opentelemetry-resource-detector-azure-app-service/MANITEST.rst b/resource/opentelemetry-resource-detector-azure-app-service/MANIFEST.rst similarity index 100% rename from resource/opentelemetry-resource-detector-azure-app-service/MANITEST.rst rename to resource/opentelemetry-resource-detector-azure-app-service/MANIFEST.rst diff --git a/resource/opentelemetry-resource-detector-container/MANITEST.rst b/resource/opentelemetry-resource-detector-container/MANIFEST.rst similarity index 100% rename from resource/opentelemetry-resource-detector-container/MANITEST.rst rename to resource/opentelemetry-resource-detector-container/MANIFEST.rst From ffd725815600b08260e2e2b1e8f0319ba7c03f36 Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Mon, 7 Aug 2023 13:57:18 -0700 Subject: [PATCH 09/26] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63f7d7e33c..baa2a9bac8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `opentelemetry-resource-detector-azure-app-service` Add resource detector for Azure App Service - ([#XXXX](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/XXXX)) + ([#1901](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1901)) ## Version 1.19.0/0.40b0 (2023-07-13) - `opentelemetry-instrumentation-asgi` Add `http.server.request.size` metric From e903aa429fd84c163a8356ab87befb41d0c08efe Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Mon, 7 Aug 2023 13:58:35 -0700 Subject: [PATCH 10/26] Resource declaration --- .../resource/detector/azure/app_service/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/__init__.py b/resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/__init__.py index 028b3b073c..95df839c3e 100644 --- a/resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/__init__.py +++ b/resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/__init__.py @@ -27,7 +27,7 @@ } class AzureAppServiceResourceDetector(ResourceDetector): - def detect(self) -> "Resource": + def detect(self) -> Resource: attributes = {} website_site_name = environ.get(_WEBSITE_SITE_NAME) if website_site_name: From e05dcc923297a792496f05159bef1226a1b7fa98 Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Mon, 7 Aug 2023 14:00:47 -0700 Subject: [PATCH 11/26] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index baa2a9bac8..34351f01c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-instrumentation-asgi` Fix UnboundLocalError local variable 'start' referenced before assignment ([#1889](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1889)) + ### Added - `opentelemetry-resource-detector-azure-app-service` Add resource detector for Azure App Service From be060f573ce9244bd2b104e39c1b2af0dc02111c Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Mon, 7 Aug 2023 14:36:13 -0700 Subject: [PATCH 12/26] rename to combine --- .../LICENSE | 0 .../MANIFEST.rst | 0 .../README.rst | 0 .../pyproject.toml | 0 .../resource/detector/azure/app_service.py} | 0 .../resource/detector/azure}/version.py | 0 .../resource/detector/azure/vm.py | 85 +++++++++++++++++++ .../tests/__init__.py | 0 .../test_app_service_resource_detector.py | 0 9 files changed, 85 insertions(+) rename resource/{opentelemetry-resource-detector-azure-app-service => opentelemetry-resource-detector-azure}/LICENSE (100%) rename resource/{opentelemetry-resource-detector-azure-app-service => opentelemetry-resource-detector-azure}/MANIFEST.rst (100%) rename resource/{opentelemetry-resource-detector-azure-app-service => opentelemetry-resource-detector-azure}/README.rst (100%) rename resource/{opentelemetry-resource-detector-azure-app-service => opentelemetry-resource-detector-azure}/pyproject.toml (100%) rename resource/{opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/__init__.py => opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/app_service.py} (100%) rename resource/{opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service => opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure}/version.py (100%) create mode 100644 resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/vm.py rename resource/{opentelemetry-resource-detector-azure-app-service => opentelemetry-resource-detector-azure}/tests/__init__.py (100%) rename resource/{opentelemetry-resource-detector-azure-app-service => opentelemetry-resource-detector-azure}/tests/test_app_service_resource_detector.py (100%) diff --git a/resource/opentelemetry-resource-detector-azure-app-service/LICENSE b/resource/opentelemetry-resource-detector-azure/LICENSE similarity index 100% rename from resource/opentelemetry-resource-detector-azure-app-service/LICENSE rename to resource/opentelemetry-resource-detector-azure/LICENSE diff --git a/resource/opentelemetry-resource-detector-azure-app-service/MANIFEST.rst b/resource/opentelemetry-resource-detector-azure/MANIFEST.rst similarity index 100% rename from resource/opentelemetry-resource-detector-azure-app-service/MANIFEST.rst rename to resource/opentelemetry-resource-detector-azure/MANIFEST.rst diff --git a/resource/opentelemetry-resource-detector-azure-app-service/README.rst b/resource/opentelemetry-resource-detector-azure/README.rst similarity index 100% rename from resource/opentelemetry-resource-detector-azure-app-service/README.rst rename to resource/opentelemetry-resource-detector-azure/README.rst diff --git a/resource/opentelemetry-resource-detector-azure-app-service/pyproject.toml b/resource/opentelemetry-resource-detector-azure/pyproject.toml similarity index 100% rename from resource/opentelemetry-resource-detector-azure-app-service/pyproject.toml rename to resource/opentelemetry-resource-detector-azure/pyproject.toml diff --git a/resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/__init__.py b/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/app_service.py similarity index 100% rename from resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/__init__.py rename to resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/app_service.py diff --git a/resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/version.py b/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/version.py similarity index 100% rename from resource/opentelemetry-resource-detector-azure-app-service/src/opentelemetry/resource/detector/azure/app_service/version.py rename to resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/version.py diff --git a/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/vm.py b/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/vm.py new file mode 100644 index 0000000000..0e9c4aa185 --- /dev/null +++ b/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/vm.py @@ -0,0 +1,85 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +from json import loads +from logging import getLogger +from os import environ +from urllib.request import Request, urlopen +from urllib.error import URLError + +from opentelemetry.sdk.resources import ResourceDetector, Resource +from opentelemetry.semconv.resource import ResourceAttributes, CloudPlatformValues, CloudProviderValues + + +# TODO: Remove when cloud resource id is no longer missing in Resource Attributes +_CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE = "cloud.resource_id" +_AZURE_VM_METADATA_ENDPOINT = "http://169.254.169.254/metadata/instance/compute?api-version=2021-12-13&format=json" +_AZURE_VM_SCALE_SET_NAME_ATTRIBUTE = "azure.vm.scaleset.name" +_AZURE_VM_SKU_ATTRIBUTE = "azure.vm.sku" +_logger = getLogger(__name__) + +EXPECTED_AZURE_AMS_ATTRIBUTES = [ + _AZURE_VM_SCALE_SET_NAME_ATTRIBUTE, + _AZURE_VM_SKU_ATTRIBUTE, + ResourceAttributes.CLOUD_PLATFORM, + ResourceAttributes.CLOUD_PROVIDER, + ResourceAttributes.CLOUD_REGION, + _CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE, + ResourceAttributes.HOST_ID, + ResourceAttributes.HOST_NAME, + ResourceAttributes.HOST_TYPE, + ResourceAttributes.OS_TYPE, + ResourceAttributes.OS_VERSION, + ResourceAttributes.SERVICE_INSTANCE_ID, +] + +class AzureVMResourceDetector(ResourceDetector): + # pylint: disable=no-self-use + def detect(self) -> "Resource": + attributes = {} + metadata_json = _AzureVMMetadataServiceRequestor().get_azure_vm_metadata() + if not metadata_json: + return Resource(attributes) + for attribute_key in EXPECTED_AZURE_AMS_ATTRIBUTES: + attributes[attribute_key] = _AzureVMMetadataServiceRequestor().get_attribute_from_metadata(metadata_json, attribute_key) + return Resource(attributes) + +class _AzureVMMetadataServiceRequestor: + def get_azure_vm_metadata(self): + request = Request(_AZURE_VM_METADATA_ENDPOINT) + request.add_header("Metadata", "True") + try: + response = urlopen(request).read() + return loads(response) + except URLError: + # Not on Azure VM + return None + except Exception as e: + _logger.exception("Failed to receive Azure VM metadata: %s", e) + return None + + def get_attribute_from_metadata(self, metadata_json, attribute_key): + ams_value = "" + if attribute_key == _AZURE_VM_SCALE_SET_NAME_ATTRIBUTE: + ams_value = metadata_json["vmScaleSetName"] + elif attribute_key == _AZURE_VM_SKU_ATTRIBUTE: + ams_value = metadata_json["sku"] + elif attribute_key == ResourceAttributes.CLOUD_PLATFORM: + ams_value = CloudPlatformValues.AZURE_VM.value + elif attribute_key == ResourceAttributes.CLOUD_PROVIDER: + ams_value = CloudProviderValues.AZURE.value + elif attribute_key == ResourceAttributes.CLOUD_REGION: + ams_value = metadata_json["location"] + elif attribute_key == _CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE: + ams_value = metadata_json["resourceId"] + elif attribute_key == ResourceAttributes.HOST_ID or \ + attribute_key == ResourceAttributes.SERVICE_INSTANCE_ID: + ams_value = metadata_json["vmId"] + elif attribute_key == ResourceAttributes.HOST_NAME: + ams_value = metadata_json["name"] + elif attribute_key == ResourceAttributes.HOST_TYPE: + ams_value = metadata_json["vmSize"] + elif attribute_key == ResourceAttributes.OS_TYPE: + ams_value = metadata_json["osType"] + elif attribute_key == ResourceAttributes.OS_VERSION: + ams_value = metadata_json["version"] + return ams_value diff --git a/resource/opentelemetry-resource-detector-azure-app-service/tests/__init__.py b/resource/opentelemetry-resource-detector-azure/tests/__init__.py similarity index 100% rename from resource/opentelemetry-resource-detector-azure-app-service/tests/__init__.py rename to resource/opentelemetry-resource-detector-azure/tests/__init__.py diff --git a/resource/opentelemetry-resource-detector-azure-app-service/tests/test_app_service_resource_detector.py b/resource/opentelemetry-resource-detector-azure/tests/test_app_service_resource_detector.py similarity index 100% rename from resource/opentelemetry-resource-detector-azure-app-service/tests/test_app_service_resource_detector.py rename to resource/opentelemetry-resource-detector-azure/tests/test_app_service_resource_detector.py From fc9ce6e02ec44c770b177166863e16dc31b79075 Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Mon, 7 Aug 2023 14:38:53 -0700 Subject: [PATCH 13/26] Combined. Need to fix tests --- .../pyproject.toml | 5 +- ...source_detector.py => test_app_service.py} | 0 .../tests/test_vm.py | 374 ++++++++++++++++++ 3 files changed, 377 insertions(+), 2 deletions(-) rename resource/opentelemetry-resource-detector-azure/tests/{test_app_service_resource_detector.py => test_app_service.py} (100%) create mode 100644 resource/opentelemetry-resource-detector-azure/tests/test_vm.py diff --git a/resource/opentelemetry-resource-detector-azure/pyproject.toml b/resource/opentelemetry-resource-detector-azure/pyproject.toml index 8de8be8af1..c4aecbb56b 100644 --- a/resource/opentelemetry-resource-detector-azure/pyproject.toml +++ b/resource/opentelemetry-resource-detector-azure/pyproject.toml @@ -33,12 +33,13 @@ test = [] [project.entry-points.opentelemetry_resource_detector] azure_app_service = "opentelemetry.resource.detector.azure.app_service:AzureAppServiceResourceDetector" +azure_vm = "opentelemetry.resource.detector.azure.vm:AzureVMResourceDetector" [project.urls] -Homepage = "https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/resource/opentelemetry-resource-detector-azure-app-service" +Homepage = "https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/resource/opentelemetry-resource-detector-azure" [tool.hatch.version] -path = "src/opentelemetry/resource/detector/azure/app_service/version.py" +path = "src/opentelemetry/resource/detector/azure/version.py" [tool.hatch.build.targets.sdist] include = [ diff --git a/resource/opentelemetry-resource-detector-azure/tests/test_app_service_resource_detector.py b/resource/opentelemetry-resource-detector-azure/tests/test_app_service.py similarity index 100% rename from resource/opentelemetry-resource-detector-azure/tests/test_app_service_resource_detector.py rename to resource/opentelemetry-resource-detector-azure/tests/test_app_service.py diff --git a/resource/opentelemetry-resource-detector-azure/tests/test_vm.py b/resource/opentelemetry-resource-detector-azure/tests/test_vm.py new file mode 100644 index 0000000000..739df55030 --- /dev/null +++ b/resource/opentelemetry-resource-detector-azure/tests/test_vm.py @@ -0,0 +1,374 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +import unittest +from unittest.mock import patch, Mock + +from opentelemetry.semconv.resource import ResourceAttributes +from opentelemetry.resource.detector.azure.vm import ( + AzureVMResourceDetector, +) + +LINUX_JSON = """ +{ + "compute": { + "azEnvironment": "AZUREPUBLICCLOUD", + "additionalCapabilities": { + "hibernationEnabled": "true" + }, + "hostGroup": { + "id": "testHostGroupId" + }, + "extendedLocation": { + "type": "edgeZone", + "name": "microsoftlosangeles" + }, + "evictionPolicy": "", + "isHostCompatibilityLayerVm": "true", + "licenseType": "", + "location": "westus", + "name": "examplevmname", + "offer": "UbuntuServer", + "osProfile": { + "adminUsername": "admin", + "computerName": "examplevmname", + "disablePasswordAuthentication": "true" + }, + "osType": "Linux", + "placementGroupId": "f67c14ab-e92c-408c-ae2d-da15866ec79a", + "plan": { + "name": "planName", + "product": "planProduct", + "publisher": "planPublisher" + }, + "platformFaultDomain": "36", + "platformSubFaultDomain": "", + "platformUpdateDomain": "42", + "priority": "Regular", + "publicKeys": [{ + "keyData": "ssh-rsa 0", + "path": "/home/user/.ssh/authorized_keys0" + }, + { + "keyData": "ssh-rsa 1", + "path": "/home/user/.ssh/authorized_keys1" + } + ], + "publisher": "Canonical", + "resourceGroupName": "macikgo-test-may-23", + "resourceId": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/virtualMachines/examplevmname", + "securityProfile": { + "secureBootEnabled": "true", + "virtualTpmEnabled": "false", + "encryptionAtHost": "true", + "securityType": "TrustedLaunch" + }, + "sku": "18.04-LTS", + "storageProfile": { + "dataDisks": [{ + "bytesPerSecondThrottle": "979202048", + "caching": "None", + "createOption": "Empty", + "diskCapacityBytes": "274877906944", + "diskSizeGB": "1024", + "image": { + "uri": "" + }, + "isSharedDisk": "false", + "isUltraDisk": "true", + "lun": "0", + "managedDisk": { + "id": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/disks/exampledatadiskname", + "storageAccountType": "StandardSSD_LRS" + }, + "name": "exampledatadiskname", + "opsPerSecondThrottle": "65280", + "vhd": { + "uri": "" + }, + "writeAcceleratorEnabled": "false" + }], + "imageReference": { + "id": "", + "offer": "UbuntuServer", + "publisher": "Canonical", + "sku": "16.04.0-LTS", + "version": "latest" + }, + "osDisk": { + "caching": "ReadWrite", + "createOption": "FromImage", + "diskSizeGB": "30", + "diffDiskSettings": { + "option": "Local" + }, + "encryptionSettings": { + "enabled": "false", + "diskEncryptionKey": { + "sourceVault": { + "id": "/subscriptions/test-source-guid/resourceGroups/testrg/providers/Microsoft.KeyVault/vaults/test-kv" + }, + "secretUrl": "https://test-disk.vault.azure.net/secrets/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" + }, + "keyEncryptionKey": { + "sourceVault": { + "id": "/subscriptions/test-key-guid/resourceGroups/testrg/providers/Microsoft.KeyVault/vaults/test-kv" + }, + "keyUrl": "https://test-key.vault.azure.net/secrets/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" + } + }, + "image": { + "uri": "" + }, + "managedDisk": { + "id": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/disks/exampleosdiskname", + "storageAccountType": "StandardSSD_LRS" + }, + "name": "exampleosdiskname", + "osType": "Linux", + "vhd": { + "uri": "" + }, + "writeAcceleratorEnabled": "false" + }, + "resourceDisk": { + "size": "4096" + } + }, + "subscriptionId": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx", + "tags": "baz:bash;foo:bar", + "version": "15.05.22", + "virtualMachineScaleSet": { + "id": "/subscriptions/xxxxxxxx-xxxxx-xxx-xxx-xxxx/resourceGroups/resource-group-name/providers/Microsoft.Compute/virtualMachineScaleSets/virtual-machine-scale-set-name" + }, + "vmId": "02aab8a4-74ef-476e-8182-f6d2ba4166a6", + "vmScaleSetName": "crpteste9vflji9", + "vmSize": "Standard_A3", + "zone": "" + }, + "network": { + "interface": [{ + "ipv4": { + "ipAddress": [{ + "privateIpAddress": "10.144.133.132", + "publicIpAddress": "" + }], + "subnet": [{ + "address": "10.144.133.128", + "prefix": "26" + }] + }, + "ipv6": { + "ipAddress": [ + ] + }, + "macAddress": "0011AAFFBB22" + }] + } +} +""" +WINDOWS_JSON ="""{ + "compute": { + "azEnvironment": "AZUREPUBLICCLOUD", + "additionalCapabilities": { + "hibernationEnabled": "true" + }, + "hostGroup": { + "id": "testHostGroupId" + }, + "extendedLocation": { + "type": "edgeZone", + "name": "microsoftlosangeles" + }, + "evictionPolicy": "", + "isHostCompatibilityLayerVm": "true", + "licenseType": "Windows_Client", + "location": "westus", + "name": "examplevmname", + "offer": "WindowsServer", + "osProfile": { + "adminUsername": "admin", + "computerName": "examplevmname", + "disablePasswordAuthentication": "true" + }, + "osType": "Windows", + "placementGroupId": "f67c14ab-e92c-408c-ae2d-da15866ec79a", + "plan": { + "name": "planName", + "product": "planProduct", + "publisher": "planPublisher" + }, + "platformFaultDomain": "36", + "platformSubFaultDomain": "", + "platformUpdateDomain": "42", + "priority": "Regular", + "publicKeys": [{ + "keyData": "ssh-rsa 0", + "path": "/home/user/.ssh/authorized_keys0" + }, + { + "keyData": "ssh-rsa 1", + "path": "/home/user/.ssh/authorized_keys1" + } + ], + "publisher": "RDFE-Test-Microsoft-Windows-Server-Group", + "resourceGroupName": "macikgo-test-may-23", + "resourceId": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/virtualMachines/examplevmname", + "securityProfile": { + "secureBootEnabled": "true", + "virtualTpmEnabled": "false", + "encryptionAtHost": "true", + "securityType": "TrustedLaunch" + }, + "sku": "2019-Datacenter", + "storageProfile": { + "dataDisks": [{ + "bytesPerSecondThrottle": "979202048", + "caching": "None", + "createOption": "Empty", + "diskCapacityBytes": "274877906944", + "diskSizeGB": "1024", + "image": { + "uri": "" + }, + "isSharedDisk": "false", + "isUltraDisk": "true", + "lun": "0", + "managedDisk": { + "id": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/disks/exampledatadiskname", + "storageAccountType": "StandardSSD_LRS" + }, + "name": "exampledatadiskname", + "opsPerSecondThrottle": "65280", + "vhd": { + "uri": "" + }, + "writeAcceleratorEnabled": "false" + }], + "imageReference": { + "id": "", + "offer": "WindowsServer", + "publisher": "MicrosoftWindowsServer", + "sku": "2019-Datacenter", + "version": "latest" + }, + "osDisk": { + "caching": "ReadWrite", + "createOption": "FromImage", + "diskSizeGB": "30", + "diffDiskSettings": { + "option": "Local" + }, + "encryptionSettings": { + "enabled": "false", + "diskEncryptionKey": { + "sourceVault": { + "id": "/subscriptions/test-source-guid/resourceGroups/testrg/providers/Microsoft.KeyVault/vaults/test-kv" + }, + "secretUrl": "https://test-disk.vault.azure.net/secrets/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" + }, + "keyEncryptionKey": { + "sourceVault": { + "id": "/subscriptions/test-key-guid/resourceGroups/testrg/providers/Microsoft.KeyVault/vaults/test-kv" + }, + "keyUrl": "https://test-key.vault.azure.net/secrets/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" + } + }, + "image": { + "uri": "" + }, + "managedDisk": { + "id": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/disks/exampleosdiskname", + "storageAccountType": "StandardSSD_LRS" + }, + "name": "exampleosdiskname", + "osType": "Windows", + "vhd": { + "uri": "" + }, + "writeAcceleratorEnabled": "false" + }, + "resourceDisk": { + "size": "4096" + } + }, + "subscriptionId": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx", + "tags": "baz:bash;foo:bar", + "userData": "Zm9vYmFy", + "version": "15.05.22", + "virtualMachineScaleSet": { + "id": "/subscriptions/xxxxxxxx-xxxxx-xxx-xxx-xxxx/resourceGroups/resource-group-name/providers/Microsoft.Compute/virtualMachineScaleSets/virtual-machine-scale-set-name" + }, + "vmId": "02aab8a4-74ef-476e-8182-f6d2ba4166a6", + "vmScaleSetName": "crpteste9vflji9", + "vmSize": "Standard_A3", + "zone": "" + }, + "network": { + "interface": [{ + "ipv4": { + "ipAddress": [{ + "privateIpAddress": "10.144.133.132", + "publicIpAddress": "" + }], + "subnet": [{ + "address": "10.144.133.128", + "prefix": "26" + }] + }, + "ipv6": { + "ipAddress": [ + ] + }, + "macAddress": "0011AAFFBB22" + }] + } +} +""" +LINUX_ATTRIBUTES = { + "azure.vm.scaleset.name": "crpteste9vflji9", + "azure.vm.sku": "18.04-LTS", + "cloud.platform": "azure_vm", + "cloud.provider": "azure", + "cloud.region": "westus", + "cloud.resource_id": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/virtualMachines/examplevmname", + "host.id": "02aab8a4-74ef-476e-8182-f6d2ba4166a6", + "host.name": "examplevmname", + "host.type": "Standard_A3", + "os.type": "Linux", + "os.version": "15.05.22", + "service.instance.id": "02aab8a4-74ef-476e-8182-f6d2ba4166a6", +} +WINDOWS_ATTRIBUTES = { + "azure.vm.scaleset.name": "crpteste9vflji9", + "azure.vm.sku": "2019-Datacenter", + "cloud.platform": "azure_vm", + "cloud.provider": "azure", + "cloud.region": "westus", + "cloud.resource_id": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/virtualMachines/examplevmname", + "host.id": "02aab8a4-74ef-476e-8182-f6d2ba4166a6", + "host.name": "examplevmname", + "host.type": "Standard_A3", + "os.type": "Windows", + "os.version": "15.05.22", + "service.instance.id": "02aab8a4-74ef-476e-8182-f6d2ba4166a6", +} + + +class TestAzureVMResourceDetector(unittest.TestCase): + @patch("opentelemetry.resource.detector.azure.vm.urlopen") + def test_linux(self, mock_urlopen): + mock_open = Mock() + mock_urlopen.return_value = mock_open + mock_open.read.return_value = LINUX_JSON + attributes = AzureVMResourceDetector().detect().attributes + for attribute_key in LINUX_ATTRIBUTES: + self.assertEqual(attributes[attribute_key], LINUX_ATTRIBUTES[attribute_key]) + + @patch("opentelemetry.resource.detector.azure.vm.urlopen") + def test_windows(self, mock_urlopen): + mock_open = Mock() + mock_urlopen.return_value = mock_open + mock_open.read.return_value = WINDOWS_JSON + attributes = AzureVMResourceDetector().detect().attributes + for attribute_key in WINDOWS_ATTRIBUTES: + self.assertEqual(attributes[attribute_key], WINDOWS_ATTRIBUTES[attribute_key]) From 40636fd5541a0fed2a3f98f6eb7c7340af15e1ef Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Mon, 7 Aug 2023 14:52:02 -0700 Subject: [PATCH 14/26] updated linux json --- .../tests/test_vm.py | 496 +++++++++--------- 1 file changed, 246 insertions(+), 250 deletions(-) diff --git a/resource/opentelemetry-resource-detector-azure/tests/test_vm.py b/resource/opentelemetry-resource-detector-azure/tests/test_vm.py index 739df55030..765492041a 100644 --- a/resource/opentelemetry-resource-detector-azure/tests/test_vm.py +++ b/resource/opentelemetry-resource-detector-azure/tests/test_vm.py @@ -10,318 +10,314 @@ LINUX_JSON = """ { - "compute": { - "azEnvironment": "AZUREPUBLICCLOUD", - "additionalCapabilities": { - "hibernationEnabled": "true" - }, - "hostGroup": { - "id": "testHostGroupId" - }, - "extendedLocation": { - "type": "edgeZone", - "name": "microsoftlosangeles" - }, - "evictionPolicy": "", - "isHostCompatibilityLayerVm": "true", - "licenseType": "", - "location": "westus", - "name": "examplevmname", - "offer": "UbuntuServer", - "osProfile": { - "adminUsername": "admin", - "computerName": "examplevmname", - "disablePasswordAuthentication": "true" - }, - "osType": "Linux", - "placementGroupId": "f67c14ab-e92c-408c-ae2d-da15866ec79a", - "plan": { - "name": "planName", - "product": "planProduct", - "publisher": "planPublisher" + "additionalCapabilities": { + "hibernationEnabled": "false" + }, + "azEnvironment": "AzurePublicCloud", + "customData": "", + "evictionPolicy": "", + "extendedLocation": { + "name": "", + "type": "" + }, + "host": { + "id": "" + }, + "hostGroup": { + "id": "" + }, + "isHostCompatibilityLayerVm": "true", + "licenseType": "", + "location": "westus2", + "name": "examplevmname", + "offer": "0001-com-ubuntu-server-focal", + "osProfile": { + "adminUsername": "azureuser", + "computerName": "examplevmname", + "disablePasswordAuthentication": "true" + }, + "osType": "Linux", + "placementGroupId": "", + "plan": { + "name": "", + "product": "", + "publisher": "" + }, + "platformFaultDomain": "0", + "platformSubFaultDomain": "", + "platformUpdateDomain": "0", + "priority": "", + "provider": "Microsoft.Compute", + "publicKeys": [ + { + "keyData": "ssh-rsa 0", + "path": "/home/user/.ssh/authorized_keys0" }, - "platformFaultDomain": "36", - "platformSubFaultDomain": "", - "platformUpdateDomain": "42", - "priority": "Regular", - "publicKeys": [{ - "keyData": "ssh-rsa 0", - "path": "/home/user/.ssh/authorized_keys0" - }, + { + "keyData": "ssh-rsa 1", + "path": "/home/user/.ssh/authorized_keys1" + } + ], + "publisher": "canonical", + "resourceGroupName": "macikgo-test-may-23", + "resourceId": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/virtualMachines/examplevmname", + "securityProfile": { + "encryptionAtHost": "false", + "secureBootEnabled": "true", + "securityType": "TrustedLaunch", + "virtualTpmEnabled": "true" + }, + "sku": "20_04-lts-gen2", + "storageProfile": { + "dataDisks": [ { - "keyData": "ssh-rsa 1", - "path": "/home/user/.ssh/authorized_keys1" - } - ], - "publisher": "Canonical", - "resourceGroupName": "macikgo-test-may-23", - "resourceId": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/virtualMachines/examplevmname", - "securityProfile": { - "secureBootEnabled": "true", - "virtualTpmEnabled": "false", - "encryptionAtHost": "true", - "securityType": "TrustedLaunch" - }, - "sku": "18.04-LTS", - "storageProfile": { - "dataDisks": [{ "bytesPerSecondThrottle": "979202048", "caching": "None", "createOption": "Empty", "diskCapacityBytes": "274877906944", "diskSizeGB": "1024", "image": { - "uri": "" + "uri": "" }, "isSharedDisk": "false", "isUltraDisk": "true", "lun": "0", "managedDisk": { - "id": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/disks/exampledatadiskname", - "storageAccountType": "StandardSSD_LRS" + "id": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/disks/exampledatadiskname", + "storageAccountType": "StandardSSD_LRS" }, "name": "exampledatadiskname", "opsPerSecondThrottle": "65280", "vhd": { - "uri": "" + "uri": "" }, "writeAcceleratorEnabled": "false" - }], - "imageReference": { - "id": "", - "offer": "UbuntuServer", - "publisher": "Canonical", - "sku": "16.04.0-LTS", - "version": "latest" + } + ], + "imageReference": { + "id": "", + "offer": "0001-com-ubuntu-server-focal", + "publisher": "canonical", + "sku": "20_04-lts-gen2", + "version": "latest" + }, + "osDisk": { + "caching": "ReadWrite", + "createOption": "FromImage", + "diffDiskSettings": { + "option": "" }, - "osDisk": { - "caching": "ReadWrite", - "createOption": "FromImage", - "diskSizeGB": "30", - "diffDiskSettings": { - "option": "Local" - }, - "encryptionSettings": { - "enabled": "false", - "diskEncryptionKey": { + "diskSizeGB": "30", + "encryptionSettings": { + "enabled": "false", + "diskEncryptionKey": { "sourceVault": { - "id": "/subscriptions/test-source-guid/resourceGroups/testrg/providers/Microsoft.KeyVault/vaults/test-kv" + "id": "/subscriptions/test-source-guid/resourceGroups/testrg/providers/Microsoft.KeyVault/vaults/test-kv" }, "secretUrl": "https://test-disk.vault.azure.net/secrets/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" - }, - "keyEncryptionKey": { + }, + "keyEncryptionKey": { "sourceVault": { - "id": "/subscriptions/test-key-guid/resourceGroups/testrg/providers/Microsoft.KeyVault/vaults/test-kv" + "id": "/subscriptions/test-key-guid/resourceGroups/testrg/providers/Microsoft.KeyVault/vaults/test-kv" }, "keyUrl": "https://test-key.vault.azure.net/secrets/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" - } - }, - "image": { - "uri": "" - }, - "managedDisk": { - "id": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/disks/exampleosdiskname", - "storageAccountType": "StandardSSD_LRS" - }, - "name": "exampleosdiskname", - "osType": "Linux", - "vhd": { - "uri": "" - }, - "writeAcceleratorEnabled": "false" + } }, - "resourceDisk": { - "size": "4096" - } + "image": { + "uri": "" + }, + "managedDisk": { + "id": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/disks/exampleosdiskname", + "storageAccountType": "StandardSSD_LRS" + }, + "name": "exampledatadiskname", + "osType": "Linux", + "vhd": { + "uri": "" + }, + "writeAcceleratorEnabled": "false" }, - "subscriptionId": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx", - "tags": "baz:bash;foo:bar", - "version": "15.05.22", - "virtualMachineScaleSet": { - "id": "/subscriptions/xxxxxxxx-xxxxx-xxx-xxx-xxxx/resourceGroups/resource-group-name/providers/Microsoft.Compute/virtualMachineScaleSets/virtual-machine-scale-set-name" + "resourceDisk": { + "size": "16384" + } + }, + "subscriptionId": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx", + "tags": "azsecpack:nonprod;platformsettings.host_environment.service.platform_optedin_for_rootcerts:true", + "tagsList": [ + { + "name": "azsecpack", + "value": "nonprod" }, - "vmId": "02aab8a4-74ef-476e-8182-f6d2ba4166a6", - "vmScaleSetName": "crpteste9vflji9", - "vmSize": "Standard_A3", - "zone": "" + { + "name": "platformsettings.host_environment.service.platform_optedin_for_rootcerts", + "value": "true" + } + ], + "userData": "", + "version": "20.04.202307240", + "virtualMachineScaleSet": { + "id": "/subscriptions/xxxxxxxx-xxxxx-xxx-xxx-xxxx/resourceGroups/resource-group-name/providers/Microsoft.Compute/virtualMachineScaleSets/virtual-machine-scale-set-name" }, - "network": { - "interface": [{ - "ipv4": { - "ipAddress": [{ - "privateIpAddress": "10.144.133.132", - "publicIpAddress": "" - }], - "subnet": [{ - "address": "10.144.133.128", - "prefix": "26" - }] - }, - "ipv6": { - "ipAddress": [ - ] - }, - "macAddress": "0011AAFFBB22" - }] - } + "vmId": "ed985de8-ade2-4904-9fd4-78247564d5b9", + "vmScaleSetName": "", + "vmSize": "Standard_D2s_v3", + "zone": "1" } """ -WINDOWS_JSON ="""{ - "compute": { - "azEnvironment": "AZUREPUBLICCLOUD", - "additionalCapabilities": { - "hibernationEnabled": "true" - }, - "hostGroup": { - "id": "testHostGroupId" - }, - "extendedLocation": { - "type": "edgeZone", - "name": "microsoftlosangeles" - }, - "evictionPolicy": "", - "isHostCompatibilityLayerVm": "true", - "licenseType": "Windows_Client", - "location": "westus", - "name": "examplevmname", - "offer": "WindowsServer", - "osProfile": { - "adminUsername": "admin", - "computerName": "examplevmname", - "disablePasswordAuthentication": "true" - }, - "osType": "Windows", - "placementGroupId": "f67c14ab-e92c-408c-ae2d-da15866ec79a", - "plan": { - "name": "planName", - "product": "planProduct", - "publisher": "planPublisher" +WINDOWS_JSON =""" +{ + "additionalCapabilities": { + "hibernationEnabled": "false" + }, + "azEnvironment": "AzurePublicCloud", + "customData": "", + "evictionPolicy": "", + "extendedLocation": { + "name": "", + "type": "" + }, + "host": { + "id": "" + }, + "hostGroup": { + "id": "" + }, + "isHostCompatibilityLayerVm": "true", + "licenseType": "", + "location": "westus2", + "name": "examplevmname", + "offer": "0001-com-ubuntu-server-focal", + "osProfile": { + "adminUsername": "azureuser", + "computerName": "examplevmname", + "disablePasswordAuthentication": "true" + }, + "osType": "Linux", + "placementGroupId": "", + "plan": { + "name": "", + "product": "", + "publisher": "" + }, + "platformFaultDomain": "0", + "platformSubFaultDomain": "", + "platformUpdateDomain": "0", + "priority": "", + "provider": "Microsoft.Compute", + "publicKeys": [ + { + "keyData": "ssh-rsa 0", + "path": "/home/user/.ssh/authorized_keys0" }, - "platformFaultDomain": "36", - "platformSubFaultDomain": "", - "platformUpdateDomain": "42", - "priority": "Regular", - "publicKeys": [{ - "keyData": "ssh-rsa 0", - "path": "/home/user/.ssh/authorized_keys0" - }, + { + "keyData": "ssh-rsa 1", + "path": "/home/user/.ssh/authorized_keys1" + } + ], + "publisher": "canonical", + "resourceGroupName": "macikgo-test-may-23", + "resourceId": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/virtualMachines/examplevmname", + "securityProfile": { + "encryptionAtHost": "false", + "secureBootEnabled": "true", + "securityType": "TrustedLaunch", + "virtualTpmEnabled": "true" + }, + "sku": "20_04-lts-gen2", + "storageProfile": { + "dataDisks": [ { - "keyData": "ssh-rsa 1", - "path": "/home/user/.ssh/authorized_keys1" - } - ], - "publisher": "RDFE-Test-Microsoft-Windows-Server-Group", - "resourceGroupName": "macikgo-test-may-23", - "resourceId": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/virtualMachines/examplevmname", - "securityProfile": { - "secureBootEnabled": "true", - "virtualTpmEnabled": "false", - "encryptionAtHost": "true", - "securityType": "TrustedLaunch" - }, - "sku": "2019-Datacenter", - "storageProfile": { - "dataDisks": [{ "bytesPerSecondThrottle": "979202048", "caching": "None", "createOption": "Empty", "diskCapacityBytes": "274877906944", "diskSizeGB": "1024", "image": { - "uri": "" + "uri": "" }, "isSharedDisk": "false", "isUltraDisk": "true", "lun": "0", "managedDisk": { - "id": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/disks/exampledatadiskname", - "storageAccountType": "StandardSSD_LRS" + "id": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/disks/exampledatadiskname", + "storageAccountType": "StandardSSD_LRS" }, "name": "exampledatadiskname", "opsPerSecondThrottle": "65280", "vhd": { - "uri": "" + "uri": "" }, "writeAcceleratorEnabled": "false" - }], - "imageReference": { - "id": "", - "offer": "WindowsServer", - "publisher": "MicrosoftWindowsServer", - "sku": "2019-Datacenter", - "version": "latest" + } + ], + "imageReference": { + "id": "", + "offer": "0001-com-ubuntu-server-focal", + "publisher": "canonical", + "sku": "20_04-lts-gen2", + "version": "latest" + }, + "osDisk": { + "caching": "ReadWrite", + "createOption": "FromImage", + "diffDiskSettings": { + "option": "" }, - "osDisk": { - "caching": "ReadWrite", - "createOption": "FromImage", - "diskSizeGB": "30", - "diffDiskSettings": { - "option": "Local" - }, - "encryptionSettings": { - "enabled": "false", - "diskEncryptionKey": { + "diskSizeGB": "30", + "encryptionSettings": { + "enabled": "false", + "diskEncryptionKey": { "sourceVault": { - "id": "/subscriptions/test-source-guid/resourceGroups/testrg/providers/Microsoft.KeyVault/vaults/test-kv" + "id": "/subscriptions/test-source-guid/resourceGroups/testrg/providers/Microsoft.KeyVault/vaults/test-kv" }, "secretUrl": "https://test-disk.vault.azure.net/secrets/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" - }, - "keyEncryptionKey": { + }, + "keyEncryptionKey": { "sourceVault": { - "id": "/subscriptions/test-key-guid/resourceGroups/testrg/providers/Microsoft.KeyVault/vaults/test-kv" + "id": "/subscriptions/test-key-guid/resourceGroups/testrg/providers/Microsoft.KeyVault/vaults/test-kv" }, "keyUrl": "https://test-key.vault.azure.net/secrets/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" - } - }, - "image": { - "uri": "" - }, - "managedDisk": { - "id": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/disks/exampleosdiskname", - "storageAccountType": "StandardSSD_LRS" - }, - "name": "exampleosdiskname", - "osType": "Windows", - "vhd": { - "uri": "" - }, - "writeAcceleratorEnabled": "false" + } }, - "resourceDisk": { - "size": "4096" - } + "image": { + "uri": "" + }, + "managedDisk": { + "id": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/disks/exampleosdiskname", + "storageAccountType": "StandardSSD_LRS" + }, + "name": "exampledatadiskname", + "osType": "Linux", + "vhd": { + "uri": "" + }, + "writeAcceleratorEnabled": "false" }, - "subscriptionId": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx", - "tags": "baz:bash;foo:bar", - "userData": "Zm9vYmFy", - "version": "15.05.22", - "virtualMachineScaleSet": { - "id": "/subscriptions/xxxxxxxx-xxxxx-xxx-xxx-xxxx/resourceGroups/resource-group-name/providers/Microsoft.Compute/virtualMachineScaleSets/virtual-machine-scale-set-name" + "resourceDisk": { + "size": "16384" + } + }, + "subscriptionId": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx", + "tags": "azsecpack:nonprod;platformsettings.host_environment.service.platform_optedin_for_rootcerts:true", + "tagsList": [ + { + "name": "azsecpack", + "value": "nonprod" }, - "vmId": "02aab8a4-74ef-476e-8182-f6d2ba4166a6", - "vmScaleSetName": "crpteste9vflji9", - "vmSize": "Standard_A3", - "zone": "" + { + "name": "platformsettings.host_environment.service.platform_optedin_for_rootcerts", + "value": "true" + } + ], + "userData": "", + "version": "20.04.202307240", + "virtualMachineScaleSet": { + "id": "/subscriptions/xxxxxxxx-xxxxx-xxx-xxx-xxxx/resourceGroups/resource-group-name/providers/Microsoft.Compute/virtualMachineScaleSets/virtual-machine-scale-set-name" }, - "network": { - "interface": [{ - "ipv4": { - "ipAddress": [{ - "privateIpAddress": "10.144.133.132", - "publicIpAddress": "" - }], - "subnet": [{ - "address": "10.144.133.128", - "prefix": "26" - }] - }, - "ipv6": { - "ipAddress": [ - ] - }, - "macAddress": "0011AAFFBB22" - }] - } + "vmId": "ed985de8-ade2-4904-9fd4-78247564d5b9", + "vmScaleSetName": "", + "vmSize": "Standard_D2s_v3", + "zone": "1" } """ LINUX_ATTRIBUTES = { From 41a01364f7fd6a2dcf1edc9d34f13da658513f33 Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Mon, 7 Aug 2023 15:03:39 -0700 Subject: [PATCH 15/26] tests pass --- .../tests/test_vm.py | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/resource/opentelemetry-resource-detector-azure/tests/test_vm.py b/resource/opentelemetry-resource-detector-azure/tests/test_vm.py index 765492041a..b61c31e852 100644 --- a/resource/opentelemetry-resource-detector-azure/tests/test_vm.py +++ b/resource/opentelemetry-resource-detector-azure/tests/test_vm.py @@ -28,7 +28,7 @@ }, "isHostCompatibilityLayerVm": "true", "licenseType": "", - "location": "westus2", + "location": "westus", "name": "examplevmname", "offer": "0001-com-ubuntu-server-focal", "osProfile": { @@ -158,9 +158,9 @@ "virtualMachineScaleSet": { "id": "/subscriptions/xxxxxxxx-xxxxx-xxx-xxx-xxxx/resourceGroups/resource-group-name/providers/Microsoft.Compute/virtualMachineScaleSets/virtual-machine-scale-set-name" }, - "vmId": "ed985de8-ade2-4904-9fd4-78247564d5b9", - "vmScaleSetName": "", - "vmSize": "Standard_D2s_v3", + "vmId": "02aab8a4-74ef-476e-8182-f6d2ba4166a6", + "vmScaleSetName": "crpteste9vflji9", + "vmSize": "Standard_A3", "zone": "1" } """ @@ -183,16 +183,16 @@ "id": "" }, "isHostCompatibilityLayerVm": "true", - "licenseType": "", - "location": "westus2", + "licenseType": "Windows_Client", + "location": "westus", "name": "examplevmname", - "offer": "0001-com-ubuntu-server-focal", + "offer": "WindowsServer", "osProfile": { "adminUsername": "azureuser", "computerName": "examplevmname", "disablePasswordAuthentication": "true" }, - "osType": "Linux", + "osType": "Windows", "placementGroupId": "", "plan": { "name": "", @@ -214,7 +214,7 @@ "path": "/home/user/.ssh/authorized_keys1" } ], - "publisher": "canonical", + "publisher": "RDFE-Test-Microsoft-Windows-Server-Group", "resourceGroupName": "macikgo-test-may-23", "resourceId": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/macikgo-test-may-23/providers/Microsoft.Compute/virtualMachines/examplevmname", "securityProfile": { @@ -223,7 +223,7 @@ "securityType": "TrustedLaunch", "virtualTpmEnabled": "true" }, - "sku": "20_04-lts-gen2", + "sku": "2019-Datacenter", "storageProfile": { "dataDisks": [ { @@ -252,9 +252,9 @@ ], "imageReference": { "id": "", - "offer": "0001-com-ubuntu-server-focal", - "publisher": "canonical", - "sku": "20_04-lts-gen2", + "offer": "WindowsServer", + "publisher": "MicrosoftWindowsServer", + "sku": "2019-Datacenter", "version": "latest" }, "osDisk": { @@ -287,7 +287,7 @@ "storageAccountType": "StandardSSD_LRS" }, "name": "exampledatadiskname", - "osType": "Linux", + "osType": "Windows", "vhd": { "uri": "" }, @@ -299,6 +299,7 @@ }, "subscriptionId": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx", "tags": "azsecpack:nonprod;platformsettings.host_environment.service.platform_optedin_for_rootcerts:true", + "userData": "Zm9vYmFy", "tagsList": [ { "name": "azsecpack", @@ -314,15 +315,15 @@ "virtualMachineScaleSet": { "id": "/subscriptions/xxxxxxxx-xxxxx-xxx-xxx-xxxx/resourceGroups/resource-group-name/providers/Microsoft.Compute/virtualMachineScaleSets/virtual-machine-scale-set-name" }, - "vmId": "ed985de8-ade2-4904-9fd4-78247564d5b9", - "vmScaleSetName": "", - "vmSize": "Standard_D2s_v3", + "vmId": "02aab8a4-74ef-476e-8182-f6d2ba4166a6", + "vmScaleSetName": "crpteste9vflji9", + "vmSize": "Standard_A3", "zone": "1" } """ LINUX_ATTRIBUTES = { "azure.vm.scaleset.name": "crpteste9vflji9", - "azure.vm.sku": "18.04-LTS", + "azure.vm.sku": "20_04-lts-gen2", "cloud.platform": "azure_vm", "cloud.provider": "azure", "cloud.region": "westus", @@ -331,7 +332,7 @@ "host.name": "examplevmname", "host.type": "Standard_A3", "os.type": "Linux", - "os.version": "15.05.22", + "os.version": "20.04.202307240", "service.instance.id": "02aab8a4-74ef-476e-8182-f6d2ba4166a6", } WINDOWS_ATTRIBUTES = { @@ -345,7 +346,7 @@ "host.name": "examplevmname", "host.type": "Standard_A3", "os.type": "Windows", - "os.version": "15.05.22", + "os.version": "20.04.202307240", "service.instance.id": "02aab8a4-74ef-476e-8182-f6d2ba4166a6", } From 234d5da504c85366cad70f899aa129afc4c4f837 Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Mon, 7 Aug 2023 15:04:49 -0700 Subject: [PATCH 16/26] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34351f01c0..398b8859e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- `opentelemetry-resource-detector-azure-app-service` Add resource detector for Azure App Service +- `opentelemetry-resource-detector-azure` Add resource detectors for Azure App Service and VM ([#1901](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1901)) ## Version 1.19.0/0.40b0 (2023-07-13) From d133e598d2a98f5038df592d126f6d90d1ce56e2 Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Mon, 7 Aug 2023 15:48:19 -0700 Subject: [PATCH 17/26] Combined readme --- .../README.rst | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/resource/opentelemetry-resource-detector-azure/README.rst b/resource/opentelemetry-resource-detector-azure/README.rst index 9df5dbccdd..d64414ed7a 100644 --- a/resource/opentelemetry-resource-detector-azure/README.rst +++ b/resource/opentelemetry-resource-detector-azure/README.rst @@ -1,13 +1,13 @@ -OpenTelemetry Resource detectors for Azure App Services +OpenTelemetry Resource detectors for Azure ========================================================== |pypi| -.. |pypi| image:: https://badge.fury.io/py/opentelemetry-resource-detector-azure-app-service.svg - :target: https://pypi.org/project/opentelemetry-resource-detector-azure-app-service/ +.. |pypi| image:: https://badge.fury.io/py/opentelemetry-resource-detector-azure.svg + :target: https://pypi.org/project/opentelemetry-resource-detector-azure/ -This library provides custom resource detector for Azure App Services. OpenTelemetry Python has an experimental feature whereby Resource Detectors can be injected to Resource Attributes. This package includes a resource detector for Azure App Service. This detector fills out the following Resource Attributes: +The Azure App Service Resource Detector sets the following Resource Attributes: * `service.name` set to the value of the WEBSITE_SITE_NAME environment variable. * `cloud.provider` set to the value of the "azure". * `cloud.platform` set to the value of the "azure_app_service". @@ -18,11 +18,19 @@ This library provides custom resource detector for Azure App Services. OpenTelem * `service.instance.id` set to the value of the WEBSITE_INSTANCE_ID environment variable. * `azure.app.service.stamp` set to the value of the WEBSITE_HOME_STAMPNAME environment variable. - ResourceAttributes.CLOUD_REGION: _REGION_NAME, - ResourceAttributes.DEPLOYMENT_ENVIRONMENT: _WEBSITE_SLOT_NAME, - ResourceAttributes.HOST_ID: _WEBSITE_HOSTNAME, - ResourceAttributes.SERVICE_INSTANCE_ID: _WEBSITE_INSTANCE_ID, - _AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE: _WEBSITE_HOME_STAMPNAME, +The Azure VM Resource Detector sets the following Resource Attributes: + * `azure.vm.scaleset.name` + * `azure.vm.sku` + * `cloud.platform` + * `cloud.provider` + * `cloud.region` + * `cloud.resource_id` + * `host.id` + * `host.name` + * `host.type` + * `os.type` + * `os.version` + * `service.instance.id` For more information, see the Semantic Conventions for Cloud Resource Attributes. @@ -31,11 +39,11 @@ Installation :: - pip install opentelemetry-resource-detector-azure-app-service + pip install opentelemetry-resource-detector-azure --------------------------- -Usage example for `opentelemetry-resource-detector-azure-app-service` +Usage example for `opentelemetry-resource-detector-azure` .. code-block:: python @@ -43,6 +51,10 @@ Usage example for `opentelemetry-resource-detector-azure-app-service` from opentelemetry.sdk.trace import TracerProvider from opentelemetry.resource.detector.azure.app_service import ( AzureAppServiceResourceDetector, + AzureVMResourceDetector, + ) + from opentelemetry.resource.detector.azure.vm import ( + AzureVMResourceDetector, ) from opentelemetry.sdk.resources import get_aggregated_resources @@ -52,14 +64,15 @@ Usage example for `opentelemetry-resource-detector-azure-app-service` resource=get_aggregated_resources( [ AzureAppServiceResourceDetector(), + AzureVMResourceDetector(), ] ), ) ) -You can also enable the App Service Resource Detector by adding `azure_app_service` to the `OTEL_EXPERIMENTAL_RESOURCE_DETECTORS` environment variable: +You can also enable the Resource Detectors by adding `azure_app_service` and/or `azure_vm` to the `OTEL_EXPERIMENTAL_RESOURCE_DETECTORS` environment variable: -`export OTEL_EXPERIMENTAL_RESOURCE_DETECTORS=azure_app_service` +`export OTEL_EXPERIMENTAL_RESOURCE_DETECTORS=azure_app_service,azure_vm` References ---------- From cad0e160b7149f4cc070f40ccd51fa29fa9ab902 Mon Sep 17 00:00:00 2001 From: Jeremy Voss Date: Wed, 9 Aug 2023 10:07:20 -0700 Subject: [PATCH 18/26] Update resource/opentelemetry-resource-detector-azure/README.rst Co-authored-by: Leighton Chen --- resource/opentelemetry-resource-detector-azure/README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resource/opentelemetry-resource-detector-azure/README.rst b/resource/opentelemetry-resource-detector-azure/README.rst index d64414ed7a..48b4b37335 100644 --- a/resource/opentelemetry-resource-detector-azure/README.rst +++ b/resource/opentelemetry-resource-detector-azure/README.rst @@ -1,5 +1,5 @@ OpenTelemetry Resource detectors for Azure -========================================================== +========================================== |pypi| From 1e6b26fddb6bcc3564ca04fd6163710f758b8036 Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Wed, 9 Aug 2023 13:20:44 -0700 Subject: [PATCH 19/26] Beta --- resource/opentelemetry-resource-detector-azure/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resource/opentelemetry-resource-detector-azure/pyproject.toml b/resource/opentelemetry-resource-detector-azure/pyproject.toml index c4aecbb56b..db892a86bf 100644 --- a/resource/opentelemetry-resource-detector-azure/pyproject.toml +++ b/resource/opentelemetry-resource-detector-azure/pyproject.toml @@ -13,7 +13,7 @@ authors = [ { name = "OpenTelemetry Authors", email = "cncf-opentelemetry-contributors@lists.cncf.io" }, ] classifiers = [ - "Development Status :: 5 - Production/Stable", + "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", From b177c8c4c11aeb99d3368597bda9be2ec48c5e2f Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Wed, 9 Aug 2023 13:40:36 -0700 Subject: [PATCH 20/26] Improved readme --- .../README.rst | 57 +++++++++---------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/resource/opentelemetry-resource-detector-azure/README.rst b/resource/opentelemetry-resource-detector-azure/README.rst index 48b4b37335..6bb3cd692a 100644 --- a/resource/opentelemetry-resource-detector-azure/README.rst +++ b/resource/opentelemetry-resource-detector-azure/README.rst @@ -8,31 +8,31 @@ OpenTelemetry Resource detectors for Azure The Azure App Service Resource Detector sets the following Resource Attributes: - * `service.name` set to the value of the WEBSITE_SITE_NAME environment variable. - * `cloud.provider` set to the value of the "azure". - * `cloud.platform` set to the value of the "azure_app_service". - * `cloud.resource_id` set using the WEBSITE_RESOURCE_GROUP WEBSITE_OWNER_NAME and WEBSITE_SITE_NAME environment variables. - * `cloud.region` set to the value of the REGION_NAME environment variable. - * `deployment.environment` set to the value of the WEBSITE_SLOT_NAME environment variable. - * `host.id` set to the value of the WEBSITE_HOSTNAME environment variable. - * `service.instance.id` set to the value of the WEBSITE_INSTANCE_ID environment variable. - * `azure.app.service.stamp` set to the value of the WEBSITE_HOME_STAMPNAME environment variable. - -The Azure VM Resource Detector sets the following Resource Attributes: - * `azure.vm.scaleset.name` - * `azure.vm.sku` - * `cloud.platform` - * `cloud.provider` - * `cloud.region` - * `cloud.resource_id` - * `host.id` - * `host.name` - * `host.type` - * `os.type` - * `os.version` - * `service.instance.id` - - For more information, see the Semantic Conventions for Cloud Resource Attributes. + * ``service.name`` set to the value of the WEBSITE_SITE_NAME environment variable. + * ``cloud.platform`` set to "azure_app_service". + * ``cloud.provider`` set to "azure". + * ``cloud.resource_id`` set using the WEBSITE_RESOURCE_GROUP WEBSITE_OWNER_NAME and WEBSITE_SITE_NAME environment variables. + * ``cloud.region`` set to the value of the REGION_NAME environment variable. + * ``deployment.environment`` set to the value of the WEBSITE_SLOT_NAME environment variable. + * ``host.id`` set to the value of the WEBSITE_HOSTNAME environment variable. + * ``service.instance.id`` set to the value of the WEBSITE_INSTANCE_ID environment variable. + * ``azure.app.service.stamp`` set to the value of the WEBSITE_HOME_STAMPNAME environment variable. + +The Azure VM Resource Detector sets the following Resource Attributes according to the response from the `Azure Metadata Service`: + * ``azure.vm.scaleset.name`` set to the value of the ``vmScaleSetName`` field. + * ``azure.vm.sku`` set to the value of the ``sku`` field. + * ``cloud.platform`` set to the value of the ``azure_vm``. + * ``cloud.provider`` set to the value of the ``azure``. + * ``cloud.region`` set to the value of the ``location`` field. + * ``cloud.resource_id`` set to the value of the ``resourceId`` field. + * ``host.id`` set to the value of the ``vmId`` field. + * ``host.name`` set to the value of the ``name`` field. + * ``host.type`` set to the value of the ``vmSize`` field. + * ``os.type`` set to the value of the ``osType`` field. + * ``os.version`` set to the value of the ``version`` field. + * ``service.instance.id`` set to the value of the ``vmId`` field. + + For more information, see the `Semantic Conventions for Cloud Resource Attributes`. Installation ------------ @@ -43,7 +43,7 @@ Installation --------------------------- -Usage example for `opentelemetry-resource-detector-azure` +Usage example for ``opentelemetry-resource-detector-azure`` .. code-block:: python @@ -70,13 +70,8 @@ Usage example for `opentelemetry-resource-detector-azure` ) ) -You can also enable the Resource Detectors by adding `azure_app_service` and/or `azure_vm` to the `OTEL_EXPERIMENTAL_RESOURCE_DETECTORS` environment variable: - -`export OTEL_EXPERIMENTAL_RESOURCE_DETECTORS=azure_app_service,azure_vm` - References ---------- * `OpenTelemetry Project `_ * `Resource Detector Docs ` -* `Cloud Semantic Conventions `_ From 43e5a091915979f82c8da206c61263e35851a7be Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Wed, 9 Aug 2023 13:46:41 -0700 Subject: [PATCH 21/26] Fixed readme links --- .../README.rst | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/resource/opentelemetry-resource-detector-azure/README.rst b/resource/opentelemetry-resource-detector-azure/README.rst index 6bb3cd692a..08df3f0fbc 100644 --- a/resource/opentelemetry-resource-detector-azure/README.rst +++ b/resource/opentelemetry-resource-detector-azure/README.rst @@ -8,17 +8,17 @@ OpenTelemetry Resource detectors for Azure The Azure App Service Resource Detector sets the following Resource Attributes: - * ``service.name`` set to the value of the WEBSITE_SITE_NAME environment variable. - * ``cloud.platform`` set to "azure_app_service". - * ``cloud.provider`` set to "azure". - * ``cloud.resource_id`` set using the WEBSITE_RESOURCE_GROUP WEBSITE_OWNER_NAME and WEBSITE_SITE_NAME environment variables. - * ``cloud.region`` set to the value of the REGION_NAME environment variable. - * ``deployment.environment`` set to the value of the WEBSITE_SLOT_NAME environment variable. - * ``host.id`` set to the value of the WEBSITE_HOSTNAME environment variable. - * ``service.instance.id`` set to the value of the WEBSITE_INSTANCE_ID environment variable. - * ``azure.app.service.stamp`` set to the value of the WEBSITE_HOME_STAMPNAME environment variable. - -The Azure VM Resource Detector sets the following Resource Attributes according to the response from the `Azure Metadata Service`: + * ``service.name`` set to the value of the ``WEBSITE_SITE_NAME`` environment variable. + * ``cloud.platform`` set to ``azure_app_service``. + * ``cloud.provider`` set to ``azure``. + * ``cloud.resource_id`` set using the ``WEBSITE_RESOURCE_GROUP``, ``WEBSITE_OWNER_NAME``, and ``WEBSITE_SITE_NAME`` environment variables. + * ``cloud.region`` set to the value of the ``REGION_NAME`` environment variable. + * ``deployment.environment`` set to the value of the ``WEBSITE_SLOT_NAME`` environment variable. + * ``host.id`` set to the value of the ``WEBSITE_HOSTNAME`` environment variable. + * ``service.instance.id`` set to the value of the ``WEBSITE_INSTANCE_ID`` environment variable. + * ``azure.app.service.stamp`` set to the value of the ``WEBSITE_HOME_STAMPNAME`` environment variable. + +The Azure VM Resource Detector sets the following Resource Attributes according to the response from the `Azure Metadata Service `_: * ``azure.vm.scaleset.name`` set to the value of the ``vmScaleSetName`` field. * ``azure.vm.sku`` set to the value of the ``sku`` field. * ``cloud.platform`` set to the value of the ``azure_vm``. @@ -32,7 +32,7 @@ The Azure VM Resource Detector sets the following Resource Attributes according * ``os.version`` set to the value of the ``version`` field. * ``service.instance.id`` set to the value of the ``vmId`` field. - For more information, see the `Semantic Conventions for Cloud Resource Attributes`. + For more information, see the `Semantic Conventions for Cloud Resource Attributes `_. Installation ------------ @@ -74,4 +74,4 @@ References ---------- * `OpenTelemetry Project `_ -* `Resource Detector Docs ` +* `Resource Detector Docs _` From 776a3c75dfc929e6704d58c055e62c05066a69fa Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Wed, 9 Aug 2023 13:51:09 -0700 Subject: [PATCH 22/26] Updated readme --- .../opentelemetry-resource-detector-azure/README.rst | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/resource/opentelemetry-resource-detector-azure/README.rst b/resource/opentelemetry-resource-detector-azure/README.rst index 08df3f0fbc..9b4609bb21 100644 --- a/resource/opentelemetry-resource-detector-azure/README.rst +++ b/resource/opentelemetry-resource-detector-azure/README.rst @@ -6,6 +6,12 @@ OpenTelemetry Resource detectors for Azure .. |pypi| image:: https://badge.fury.io/py/opentelemetry-resource-detector-azure.svg :target: https://pypi.org/project/opentelemetry-resource-detector-azure/ +This library contains OpenTelemetry `Resource Detectors _` for the following Azure resources: + * `Azure App Service _` + * `Azure Virtual Machines _` + +Mappings +-------- The Azure App Service Resource Detector sets the following Resource Attributes: * ``service.name`` set to the value of the ``WEBSITE_SITE_NAME`` environment variable. @@ -32,7 +38,7 @@ The Azure VM Resource Detector sets the following Resource Attributes according * ``os.version`` set to the value of the ``version`` field. * ``service.instance.id`` set to the value of the ``vmId`` field. - For more information, see the `Semantic Conventions for Cloud Resource Attributes `_. +For more information, see the `Semantic Conventions for Cloud Resource Attributes `_. Installation ------------ @@ -73,5 +79,4 @@ Usage example for ``opentelemetry-resource-detector-azure`` References ---------- -* `OpenTelemetry Project `_ -* `Resource Detector Docs _` +* `OpenTelemetry Project `_ \ No newline at end of file From 8168d22e59bad68c6a09142e55e4e90e82e6d541 Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Wed, 9 Aug 2023 13:54:06 -0700 Subject: [PATCH 23/26] Fixed hyperlinks --- resource/opentelemetry-resource-detector-azure/README.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resource/opentelemetry-resource-detector-azure/README.rst b/resource/opentelemetry-resource-detector-azure/README.rst index 9b4609bb21..8ee1c939de 100644 --- a/resource/opentelemetry-resource-detector-azure/README.rst +++ b/resource/opentelemetry-resource-detector-azure/README.rst @@ -6,9 +6,9 @@ OpenTelemetry Resource detectors for Azure .. |pypi| image:: https://badge.fury.io/py/opentelemetry-resource-detector-azure.svg :target: https://pypi.org/project/opentelemetry-resource-detector-azure/ -This library contains OpenTelemetry `Resource Detectors _` for the following Azure resources: - * `Azure App Service _` - * `Azure Virtual Machines _` +This library contains OpenTelemetry `Resource Detectors `_ for the following Azure resources: + * `Azure App Service `_ + * `Azure Virtual Machines `_ Mappings -------- From b7af5278dd0827123ed8874a427f717619aac3e6 Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Wed, 9 Aug 2023 13:55:40 -0700 Subject: [PATCH 24/26] Reordered readme --- .../README.rst | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/resource/opentelemetry-resource-detector-azure/README.rst b/resource/opentelemetry-resource-detector-azure/README.rst index 8ee1c939de..6a376534ad 100644 --- a/resource/opentelemetry-resource-detector-azure/README.rst +++ b/resource/opentelemetry-resource-detector-azure/README.rst @@ -10,36 +10,6 @@ This library contains OpenTelemetry `Resource Detectors `_ * `Azure Virtual Machines `_ -Mappings --------- - -The Azure App Service Resource Detector sets the following Resource Attributes: - * ``service.name`` set to the value of the ``WEBSITE_SITE_NAME`` environment variable. - * ``cloud.platform`` set to ``azure_app_service``. - * ``cloud.provider`` set to ``azure``. - * ``cloud.resource_id`` set using the ``WEBSITE_RESOURCE_GROUP``, ``WEBSITE_OWNER_NAME``, and ``WEBSITE_SITE_NAME`` environment variables. - * ``cloud.region`` set to the value of the ``REGION_NAME`` environment variable. - * ``deployment.environment`` set to the value of the ``WEBSITE_SLOT_NAME`` environment variable. - * ``host.id`` set to the value of the ``WEBSITE_HOSTNAME`` environment variable. - * ``service.instance.id`` set to the value of the ``WEBSITE_INSTANCE_ID`` environment variable. - * ``azure.app.service.stamp`` set to the value of the ``WEBSITE_HOME_STAMPNAME`` environment variable. - -The Azure VM Resource Detector sets the following Resource Attributes according to the response from the `Azure Metadata Service `_: - * ``azure.vm.scaleset.name`` set to the value of the ``vmScaleSetName`` field. - * ``azure.vm.sku`` set to the value of the ``sku`` field. - * ``cloud.platform`` set to the value of the ``azure_vm``. - * ``cloud.provider`` set to the value of the ``azure``. - * ``cloud.region`` set to the value of the ``location`` field. - * ``cloud.resource_id`` set to the value of the ``resourceId`` field. - * ``host.id`` set to the value of the ``vmId`` field. - * ``host.name`` set to the value of the ``name`` field. - * ``host.type`` set to the value of the ``vmSize`` field. - * ``os.type`` set to the value of the ``osType`` field. - * ``os.version`` set to the value of the ``version`` field. - * ``service.instance.id`` set to the value of the ``vmId`` field. - -For more information, see the `Semantic Conventions for Cloud Resource Attributes `_. - Installation ------------ @@ -76,6 +46,36 @@ Usage example for ``opentelemetry-resource-detector-azure`` ) ) +Mappings +-------- + +The Azure App Service Resource Detector sets the following Resource Attributes: + * ``service.name`` set to the value of the ``WEBSITE_SITE_NAME`` environment variable. + * ``cloud.platform`` set to ``azure_app_service``. + * ``cloud.provider`` set to ``azure``. + * ``cloud.resource_id`` set using the ``WEBSITE_RESOURCE_GROUP``, ``WEBSITE_OWNER_NAME``, and ``WEBSITE_SITE_NAME`` environment variables. + * ``cloud.region`` set to the value of the ``REGION_NAME`` environment variable. + * ``deployment.environment`` set to the value of the ``WEBSITE_SLOT_NAME`` environment variable. + * ``host.id`` set to the value of the ``WEBSITE_HOSTNAME`` environment variable. + * ``service.instance.id`` set to the value of the ``WEBSITE_INSTANCE_ID`` environment variable. + * ``azure.app.service.stamp`` set to the value of the ``WEBSITE_HOME_STAMPNAME`` environment variable. + +The Azure VM Resource Detector sets the following Resource Attributes according to the response from the `Azure Metadata Service `_: + * ``azure.vm.scaleset.name`` set to the value of the ``vmScaleSetName`` field. + * ``azure.vm.sku`` set to the value of the ``sku`` field. + * ``cloud.platform`` set to the value of the ``azure_vm``. + * ``cloud.provider`` set to the value of the ``azure``. + * ``cloud.region`` set to the value of the ``location`` field. + * ``cloud.resource_id`` set to the value of the ``resourceId`` field. + * ``host.id`` set to the value of the ``vmId`` field. + * ``host.name`` set to the value of the ``name`` field. + * ``host.type`` set to the value of the ``vmSize`` field. + * ``os.type`` set to the value of the ``osType`` field. + * ``os.version`` set to the value of the ``version`` field. + * ``service.instance.id`` set to the value of the ``vmId`` field. + +For more information, see the `Semantic Conventions for Cloud Resource Attributes `_. + References ---------- From abf44aaaa5feb4e3d8b6849674b466b184844ab8 Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Mon, 14 Aug 2023 16:23:35 -0700 Subject: [PATCH 25/26] Replace MIT license with apache 2.0 --- .../LICENSE | 222 ++++++++++++++++-- .../resource/detector/azure/app_service.py | 16 +- .../resource/detector/azure/vm.py | 16 +- .../tests/__init__.py | 15 +- .../tests/test_app_service.py | 15 +- .../tests/test_vm.py | 15 +- 6 files changed, 268 insertions(+), 31 deletions(-) diff --git a/resource/opentelemetry-resource-detector-azure/LICENSE b/resource/opentelemetry-resource-detector-azure/LICENSE index 63447fd8bb..1ef7dad2c5 100644 --- a/resource/opentelemetry-resource-detector-azure/LICENSE +++ b/resource/opentelemetry-resource-detector-azure/LICENSE @@ -1,21 +1,201 @@ -Copyright (c) Microsoft Corporation. - -MIT License - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright The OpenTelemetry Authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/app_service.py b/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/app_service.py index 95df839c3e..ea0959cb93 100644 --- a/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/app_service.py +++ b/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/app_service.py @@ -1,5 +1,17 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from os import environ from opentelemetry.sdk.resources import ResourceDetector, Resource diff --git a/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/vm.py b/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/vm.py index 0e9c4aa185..02f8ea537f 100644 --- a/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/vm.py +++ b/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/vm.py @@ -1,5 +1,17 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from json import loads from logging import getLogger from os import environ diff --git a/resource/opentelemetry-resource-detector-azure/tests/__init__.py b/resource/opentelemetry-resource-detector-azure/tests/__init__.py index 5b7f7a925c..b0a6f42841 100644 --- a/resource/opentelemetry-resource-detector-azure/tests/__init__.py +++ b/resource/opentelemetry-resource-detector-azure/tests/__init__.py @@ -1,2 +1,13 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/resource/opentelemetry-resource-detector-azure/tests/test_app_service.py b/resource/opentelemetry-resource-detector-azure/tests/test_app_service.py index e520e311f4..f5d6a0dd3d 100644 --- a/resource/opentelemetry-resource-detector-azure/tests/test_app_service.py +++ b/resource/opentelemetry-resource-detector-azure/tests/test_app_service.py @@ -1,5 +1,16 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. import unittest from unittest.mock import patch diff --git a/resource/opentelemetry-resource-detector-azure/tests/test_vm.py b/resource/opentelemetry-resource-detector-azure/tests/test_vm.py index b61c31e852..0531fa02b1 100644 --- a/resource/opentelemetry-resource-detector-azure/tests/test_vm.py +++ b/resource/opentelemetry-resource-detector-azure/tests/test_vm.py @@ -1,5 +1,16 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. import unittest from unittest.mock import patch, Mock From 057a58e8766c25670d70026b3af1de15739e52dc Mon Sep 17 00:00:00 2001 From: jeremydvoss Date: Tue, 15 Aug 2023 10:22:11 -0700 Subject: [PATCH 26/26] license --- .../resource/detector/azure/version.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/version.py b/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/version.py index a0e1bb43d9..7f88144cf6 100644 --- a/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/version.py +++ b/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/version.py @@ -1,4 +1,15 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. __version__ = "0.41b0.dev"