mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-28 20:52:57 +08:00
Implement functions resource detector (#2523)
* Update .pylintrc * fn * Update CHANGELOG.md * commments * Add deployment.environment to functions detector * Revert "Add deployment.environment to functions detector" This reverts commit 5411759711b8bc9976705deb416d5ffd8f65590f. * Remove deployment.environment from readme * Release 0.1.5 --------- Co-authored-by: jeremydvoss <jerevoss@gmail.com>
This commit is contained in:
@ -5,10 +5,12 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## Unreleased
|
## Version 0.1.5 (2024-05-16)
|
||||||
|
|
||||||
- Ignore vm detector if already in other rps
|
- Ignore vm detector if already in other rps
|
||||||
([#2456](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2456))
|
([#2456](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2456))
|
||||||
|
- Implement functions resource detector
|
||||||
|
([#2523](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2523))
|
||||||
|
|
||||||
## Version 0.1.4 (2024-04-05)
|
## Version 0.1.4 (2024-04-05)
|
||||||
|
|
||||||
|
@ -60,7 +60,17 @@ The Azure App Service Resource Detector sets the following Resource Attributes:
|
|||||||
* ``service.instance.id`` set to the value of the ``WEBSITE_INSTANCE_ID`` 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.
|
* ``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 <https://learn.microsoft.com/en-us/azure/virtual-machines/instance-metadata-service?tabs=windows>`_:
|
The Azure Functions Resource Detector sets the following Resource Attributes:
|
||||||
|
* ``service.name`` set to the value of the ``WEBSITE_SITE_NAME`` environment variable.
|
||||||
|
* ``process.id`` set to the process ID collected from the running process.
|
||||||
|
* ``cloud.platform`` set to ``azure_functions``.
|
||||||
|
* ``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.
|
||||||
|
* ``faas.instance`` set to the value of the ``WEBSITE_INSTANCE_ID`` environment variable.
|
||||||
|
* ``faas.max_memory`` set to the value of the ``WEBSITE_MEMORY_LIMIT_MB`` environment variable.
|
||||||
|
|
||||||
|
The Azure VM Resource Detector sets the following Resource Attributes according to the response from the `Azure Metadata Service <https://learn.microsoft.com/azure/virtual-machines/instance-metadata-service?tabs=windows>`_:
|
||||||
* ``azure.vm.scaleset.name`` set to the value of the ``vmScaleSetName`` field.
|
* ``azure.vm.scaleset.name`` set to the value of the ``vmScaleSetName`` field.
|
||||||
* ``azure.vm.sku`` set to the value of the ``sku`` field.
|
* ``azure.vm.sku`` set to the value of the ``sku`` field.
|
||||||
* ``cloud.platform`` set to the value of the ``azure_vm``.
|
* ``cloud.platform`` set to the value of the ``azure_vm``.
|
||||||
|
@ -29,6 +29,7 @@ dependencies = [
|
|||||||
|
|
||||||
[project.entry-points.opentelemetry_resource_detector]
|
[project.entry-points.opentelemetry_resource_detector]
|
||||||
azure_app_service = "opentelemetry.resource.detector.azure.app_service:AzureAppServiceResourceDetector"
|
azure_app_service = "opentelemetry.resource.detector.azure.app_service:AzureAppServiceResourceDetector"
|
||||||
|
azure_functions = "opentelemetry.resource.detector.azure.functions:AzureFunctionsResourceDetector"
|
||||||
azure_vm = "opentelemetry.resource.detector.azure.vm:AzureVMResourceDetector"
|
azure_vm = "opentelemetry.resource.detector.azure.vm:AzureVMResourceDetector"
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
|
@ -15,11 +15,13 @@
|
|||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
|
|
||||||
from .app_service import AzureAppServiceResourceDetector
|
from .app_service import AzureAppServiceResourceDetector
|
||||||
|
from .functions import AzureFunctionsResourceDetector
|
||||||
from .version import __version__
|
from .version import __version__
|
||||||
from .vm import AzureVMResourceDetector
|
from .vm import AzureVMResourceDetector
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"AzureAppServiceResourceDetector",
|
"AzureAppServiceResourceDetector",
|
||||||
|
"AzureFunctionsResourceDetector",
|
||||||
"AzureVMResourceDetector",
|
"AzureVMResourceDetector",
|
||||||
"__version__",
|
"__version__",
|
||||||
]
|
]
|
||||||
|
@ -43,6 +43,12 @@ _APP_SERVICE_ATTRIBUTE_ENV_VARS = {
|
|||||||
# Functions
|
# Functions
|
||||||
|
|
||||||
_FUNCTIONS_WORKER_RUNTIME = "FUNCTIONS_WORKER_RUNTIME"
|
_FUNCTIONS_WORKER_RUNTIME = "FUNCTIONS_WORKER_RUNTIME"
|
||||||
|
_WEBSITE_MEMORY_LIMIT_MB = "WEBSITE_MEMORY_LIMIT_MB"
|
||||||
|
|
||||||
|
_FUNCTIONS_ATTRIBUTE_ENV_VARS = {
|
||||||
|
ResourceAttributes.FAAS_INSTANCE: _WEBSITE_INSTANCE_ID,
|
||||||
|
ResourceAttributes.FAAS_MAX_MEMORY: _WEBSITE_MEMORY_LIMIT_MB,
|
||||||
|
}
|
||||||
|
|
||||||
# Vm
|
# Vm
|
||||||
|
|
||||||
|
@ -11,27 +11,44 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
from os import environ
|
||||||
import os
|
from typing import Optional
|
||||||
|
|
||||||
from ._constants import (
|
from ._constants import (
|
||||||
_AKS_ARM_NAMESPACE_ID,
|
_AKS_ARM_NAMESPACE_ID,
|
||||||
_FUNCTIONS_WORKER_RUNTIME,
|
_FUNCTIONS_WORKER_RUNTIME,
|
||||||
|
_WEBSITE_OWNER_NAME,
|
||||||
|
_WEBSITE_RESOURCE_GROUP,
|
||||||
_WEBSITE_SITE_NAME,
|
_WEBSITE_SITE_NAME,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _is_on_aks() -> bool:
|
def _is_on_aks() -> bool:
|
||||||
return os.environ.get(_AKS_ARM_NAMESPACE_ID) is not None
|
return environ.get(_AKS_ARM_NAMESPACE_ID) is not None
|
||||||
|
|
||||||
|
|
||||||
def _is_on_app_service() -> bool:
|
def _is_on_app_service() -> bool:
|
||||||
return os.environ.get(_WEBSITE_SITE_NAME) is not None
|
return environ.get(_WEBSITE_SITE_NAME) is not None
|
||||||
|
|
||||||
|
|
||||||
def _is_on_functions() -> bool:
|
def _is_on_functions() -> bool:
|
||||||
return os.environ.get(_FUNCTIONS_WORKER_RUNTIME) is not None
|
return environ.get(_FUNCTIONS_WORKER_RUNTIME) is not None
|
||||||
|
|
||||||
|
|
||||||
def _can_ignore_vm_detect() -> bool:
|
def _can_ignore_vm_detect() -> bool:
|
||||||
return _is_on_aks() or _is_on_app_service() or _is_on_functions()
|
return _is_on_aks() or _is_on_app_service() or _is_on_functions()
|
||||||
|
|
||||||
|
|
||||||
|
def _get_azure_resource_uri() -> Optional[str]:
|
||||||
|
website_site_name = environ.get(_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_site_name and website_resource_group and subscription_id):
|
||||||
|
return None
|
||||||
|
|
||||||
|
return f"/subscriptions/{subscription_id}/resourceGroups/{website_resource_group}/providers/Microsoft.Web/sites/{website_site_name}"
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
from os import environ
|
from os import environ
|
||||||
|
|
||||||
from opentelemetry.sdk.resources import Resource, ResourceDetector
|
from opentelemetry.sdk.resources import Resource, ResourceDetector
|
||||||
@ -20,29 +21,32 @@ from opentelemetry.semconv.resource import (
|
|||||||
CloudProviderValues,
|
CloudProviderValues,
|
||||||
ResourceAttributes,
|
ResourceAttributes,
|
||||||
)
|
)
|
||||||
|
from opentelemetry.resource.detector.azure._utils import _get_azure_resource_uri
|
||||||
|
|
||||||
from ._constants import (
|
from ._constants import (
|
||||||
_APP_SERVICE_ATTRIBUTE_ENV_VARS,
|
_APP_SERVICE_ATTRIBUTE_ENV_VARS,
|
||||||
_WEBSITE_OWNER_NAME,
|
|
||||||
_WEBSITE_RESOURCE_GROUP,
|
|
||||||
_WEBSITE_SITE_NAME,
|
_WEBSITE_SITE_NAME,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from opentelemetry.resource.detector.azure._utils import _is_on_functions
|
||||||
|
|
||||||
|
|
||||||
class AzureAppServiceResourceDetector(ResourceDetector):
|
class AzureAppServiceResourceDetector(ResourceDetector):
|
||||||
def detect(self) -> Resource:
|
def detect(self) -> Resource:
|
||||||
attributes = {}
|
attributes = {}
|
||||||
website_site_name = environ.get(_WEBSITE_SITE_NAME)
|
website_site_name = environ.get(_WEBSITE_SITE_NAME)
|
||||||
if website_site_name:
|
if website_site_name:
|
||||||
attributes[ResourceAttributes.SERVICE_NAME] = website_site_name
|
# Functions resource detector takes priority with `service.name` and `cloud.platform`
|
||||||
|
if not _is_on_functions():
|
||||||
|
attributes[ResourceAttributes.SERVICE_NAME] = website_site_name
|
||||||
|
attributes[ResourceAttributes.CLOUD_PLATFORM] = (
|
||||||
|
CloudPlatformValues.AZURE_APP_SERVICE.value
|
||||||
|
)
|
||||||
attributes[ResourceAttributes.CLOUD_PROVIDER] = (
|
attributes[ResourceAttributes.CLOUD_PROVIDER] = (
|
||||||
CloudProviderValues.AZURE.value
|
CloudProviderValues.AZURE.value
|
||||||
)
|
)
|
||||||
attributes[ResourceAttributes.CLOUD_PLATFORM] = (
|
|
||||||
CloudPlatformValues.AZURE_APP_SERVICE.value
|
|
||||||
)
|
|
||||||
|
|
||||||
azure_resource_uri = _get_azure_resource_uri(website_site_name)
|
azure_resource_uri = _get_azure_resource_uri()
|
||||||
if azure_resource_uri:
|
if azure_resource_uri:
|
||||||
attributes[ResourceAttributes.CLOUD_RESOURCE_ID] = (
|
attributes[ResourceAttributes.CLOUD_RESOURCE_ID] = (
|
||||||
azure_resource_uri
|
azure_resource_uri
|
||||||
@ -53,17 +57,3 @@ class AzureAppServiceResourceDetector(ResourceDetector):
|
|||||||
attributes[key] = value
|
attributes[key] = value
|
||||||
|
|
||||||
return Resource(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 f"/subscriptions/{subscription_id}/resourceGroups/{website_resource_group}/providers/Microsoft.Web/sites/{website_site_name}"
|
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
# 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, getpid
|
||||||
|
|
||||||
|
from opentelemetry.sdk.resources import Resource, ResourceDetector
|
||||||
|
from opentelemetry.semconv.resource import (
|
||||||
|
CloudPlatformValues,
|
||||||
|
CloudProviderValues,
|
||||||
|
ResourceAttributes,
|
||||||
|
)
|
||||||
|
|
||||||
|
from ._constants import (
|
||||||
|
_FUNCTIONS_ATTRIBUTE_ENV_VARS,
|
||||||
|
_REGION_NAME,
|
||||||
|
_WEBSITE_SITE_NAME,
|
||||||
|
)
|
||||||
|
from opentelemetry.resource.detector.azure._utils import (
|
||||||
|
_get_azure_resource_uri,
|
||||||
|
_is_on_functions,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class AzureFunctionsResourceDetector(ResourceDetector):
|
||||||
|
def detect(self) -> Resource:
|
||||||
|
attributes = {}
|
||||||
|
if _is_on_functions():
|
||||||
|
website_site_name = environ.get(_WEBSITE_SITE_NAME)
|
||||||
|
if website_site_name:
|
||||||
|
attributes[ResourceAttributes.SERVICE_NAME] = website_site_name
|
||||||
|
attributes[ResourceAttributes.PROCESS_PID] = getpid()
|
||||||
|
attributes[ResourceAttributes.CLOUD_PROVIDER] = (
|
||||||
|
CloudProviderValues.AZURE.value
|
||||||
|
)
|
||||||
|
attributes[ResourceAttributes.CLOUD_PLATFORM] = (
|
||||||
|
CloudPlatformValues.AZURE_FUNCTIONS.value
|
||||||
|
)
|
||||||
|
cloud_region = environ.get(_REGION_NAME)
|
||||||
|
if cloud_region:
|
||||||
|
attributes[ResourceAttributes.CLOUD_REGION] = cloud_region
|
||||||
|
azure_resource_uri = _get_azure_resource_uri()
|
||||||
|
if azure_resource_uri:
|
||||||
|
attributes[ResourceAttributes.CLOUD_RESOURCE_ID] = (
|
||||||
|
azure_resource_uri
|
||||||
|
)
|
||||||
|
for key, env_var in _FUNCTIONS_ATTRIBUTE_ENV_VARS.items():
|
||||||
|
value = environ.get(env_var)
|
||||||
|
if value:
|
||||||
|
if key == ResourceAttributes.FAAS_MAX_MEMORY:
|
||||||
|
try:
|
||||||
|
value = int(value)
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
attributes[key] = value
|
||||||
|
|
||||||
|
return Resource(attributes)
|
||||||
|
|
@ -12,4 +12,4 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
__version__ = "0.1.4"
|
__version__ = "0.1.5"
|
||||||
|
@ -68,6 +68,45 @@ class TestAzureAppServiceResourceDetector(unittest.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
attributes["azure.app.service.stamp"], TEST_WEBSITE_HOME_STAMPNAME
|
attributes["azure.app.service.stamp"], TEST_WEBSITE_HOME_STAMPNAME
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@patch.dict(
|
||||||
|
"os.environ",
|
||||||
|
{
|
||||||
|
"FUNCTIONS_WORKER_RUNTIME": "1",
|
||||||
|
"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_with_functions(self):
|
||||||
|
resource = AzureAppServiceResourceDetector().detect()
|
||||||
|
attributes = resource.attributes
|
||||||
|
self.assertIsNone(attributes.get("service.name"))
|
||||||
|
self.assertEqual(attributes["cloud.provider"], "azure")
|
||||||
|
self.assertIsNone(attributes.get("cloud.platform"))
|
||||||
|
|
||||||
|
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(
|
@patch.dict(
|
||||||
"os.environ",
|
"os.environ",
|
||||||
|
@ -0,0 +1,110 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
# pylint: disable=no-name-in-module
|
||||||
|
from opentelemetry.resource.detector.azure.functions import (
|
||||||
|
AzureFunctionsResourceDetector,
|
||||||
|
)
|
||||||
|
|
||||||
|
TEST_WEBSITE_SITE_NAME = "TEST_WEBSITE_SITE_NAME"
|
||||||
|
TEST_REGION_NAME = "TEST_REGION_NAME"
|
||||||
|
TEST_WEBSITE_INSTANCE_ID = "TEST_WEBSITE_INSTANCE_ID"
|
||||||
|
|
||||||
|
TEST_WEBSITE_RESOURCE_GROUP = "TEST_WEBSITE_RESOURCE_GROUP"
|
||||||
|
TEST_WEBSITE_OWNER_NAME = "TEST_WEBSITE_OWNER_NAME"
|
||||||
|
TEST_WEBSITE_MEMORY_LIMIT_MB = "1024"
|
||||||
|
|
||||||
|
|
||||||
|
class TestAzureAppServiceResourceDetector(unittest.TestCase):
|
||||||
|
@patch.dict(
|
||||||
|
"os.environ",
|
||||||
|
{
|
||||||
|
"FUNCTIONS_WORKER_RUNTIME": "1",
|
||||||
|
"WEBSITE_SITE_NAME": TEST_WEBSITE_SITE_NAME,
|
||||||
|
"REGION_NAME": TEST_REGION_NAME,
|
||||||
|
"WEBSITE_INSTANCE_ID": TEST_WEBSITE_INSTANCE_ID,
|
||||||
|
"WEBSITE_RESOURCE_GROUP": TEST_WEBSITE_RESOURCE_GROUP,
|
||||||
|
"WEBSITE_OWNER_NAME": TEST_WEBSITE_OWNER_NAME,
|
||||||
|
"WEBSITE_MEMORY_LIMIT_MB": TEST_WEBSITE_MEMORY_LIMIT_MB,
|
||||||
|
},
|
||||||
|
clear=True,
|
||||||
|
)
|
||||||
|
@patch("opentelemetry.resource.detector.azure.functions.getpid")
|
||||||
|
def test_on_functions(self, pid_mock):
|
||||||
|
pid_mock.return_value = 1000
|
||||||
|
resource = AzureFunctionsResourceDetector().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_functions")
|
||||||
|
self.assertEqual(attributes["process.pid"], 1000)
|
||||||
|
|
||||||
|
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["faas.instance"], TEST_WEBSITE_INSTANCE_ID)
|
||||||
|
self.assertEqual(attributes["faas.max_memory"], 1024)
|
||||||
|
|
||||||
|
@patch.dict(
|
||||||
|
"os.environ",
|
||||||
|
{
|
||||||
|
"FUNCTIONS_WORKER_RUNTIME": "1",
|
||||||
|
"WEBSITE_SITE_NAME": TEST_WEBSITE_SITE_NAME,
|
||||||
|
"REGION_NAME": TEST_REGION_NAME,
|
||||||
|
"WEBSITE_INSTANCE_ID": TEST_WEBSITE_INSTANCE_ID,
|
||||||
|
"WEBSITE_RESOURCE_GROUP": TEST_WEBSITE_RESOURCE_GROUP,
|
||||||
|
"WEBSITE_OWNER_NAME": TEST_WEBSITE_OWNER_NAME,
|
||||||
|
"WEBSITE_MEMORY_LIMIT_MB": "error",
|
||||||
|
},
|
||||||
|
clear=True,
|
||||||
|
)
|
||||||
|
@patch("opentelemetry.resource.detector.azure.functions.getpid")
|
||||||
|
def test_on_functions_error_memory(self, pid_mock):
|
||||||
|
pid_mock.return_value = 1000
|
||||||
|
resource = AzureFunctionsResourceDetector().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_functions")
|
||||||
|
self.assertEqual(attributes["process.pid"], 1000)
|
||||||
|
|
||||||
|
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["faas.instance"], TEST_WEBSITE_INSTANCE_ID)
|
||||||
|
self.assertIsNone(attributes.get("faas.max_memory"))
|
||||||
|
|
||||||
|
@patch.dict(
|
||||||
|
"os.environ",
|
||||||
|
{
|
||||||
|
"WEBSITE_SITE_NAME": TEST_WEBSITE_SITE_NAME,
|
||||||
|
"REGION_NAME": TEST_REGION_NAME,
|
||||||
|
"WEBSITE_INSTANCE_ID": TEST_WEBSITE_INSTANCE_ID,
|
||||||
|
"WEBSITE_RESOURCE_GROUP": TEST_WEBSITE_RESOURCE_GROUP,
|
||||||
|
"WEBSITE_OWNER_NAME": TEST_WEBSITE_OWNER_NAME,
|
||||||
|
"WEBSITE_MEMORY_LIMIT_MB": TEST_WEBSITE_MEMORY_LIMIT_MB,
|
||||||
|
},
|
||||||
|
clear=True,
|
||||||
|
)
|
||||||
|
def test_off_app_service(self):
|
||||||
|
resource = AzureFunctionsResourceDetector().detect()
|
||||||
|
self.assertEqual(resource.attributes, {})
|
Reference in New Issue
Block a user