|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
| 15 | +from logging import getLogger |
15 | 16 | from os import environ
|
16 | 17 |
|
17 | 18 | from opentelemetry.sdk.resources import Resource, ResourceDetector
|
|
30 | 31 | _WEBSITE_RESOURCE_GROUP = "WEBSITE_RESOURCE_GROUP"
|
31 | 32 | _WEBSITE_SITE_NAME = "WEBSITE_SITE_NAME"
|
32 | 33 | _WEBSITE_SLOT_NAME = "WEBSITE_SLOT_NAME"
|
| 34 | +_logger = getLogger(__name__) |
33 | 35 |
|
34 | 36 |
|
35 | 37 | _APP_SERVICE_ATTRIBUTE_ENV_VARS = {
|
|
44 | 46 | class AzureAppServiceResourceDetector(ResourceDetector):
|
45 | 47 | def detect(self) -> Resource:
|
46 | 48 | attributes = {}
|
47 |
| - website_site_name = environ.get(_WEBSITE_SITE_NAME) |
48 |
| - if website_site_name: |
49 |
| - attributes[ResourceAttributes.SERVICE_NAME] = website_site_name |
50 |
| - attributes[ |
51 |
| - ResourceAttributes.CLOUD_PROVIDER |
52 |
| - ] = CloudProviderValues.AZURE.value |
53 |
| - attributes[ |
54 |
| - ResourceAttributes.CLOUD_PLATFORM |
55 |
| - ] = CloudPlatformValues.AZURE_APP_SERVICE.value |
56 |
| - |
57 |
| - azure_resource_uri = _get_azure_resource_uri(website_site_name) |
58 |
| - if azure_resource_uri: |
| 49 | + try: |
| 50 | + website_site_name = environ.get(_WEBSITE_SITE_NAME) |
| 51 | + if website_site_name: |
| 52 | + attributes[ResourceAttributes.SERVICE_NAME] = website_site_name |
| 53 | + attributes[ |
| 54 | + ResourceAttributes.CLOUD_PROVIDER |
| 55 | + ] = CloudProviderValues.AZURE.value |
59 | 56 | attributes[
|
60 |
| - ResourceAttributes.CLOUD_RESOURCE_ID |
61 |
| - ] = azure_resource_uri |
62 |
| - for (key, env_var) in _APP_SERVICE_ATTRIBUTE_ENV_VARS.items(): |
63 |
| - value = environ.get(env_var) |
64 |
| - if value: |
65 |
| - attributes[key] = value |
| 57 | + ResourceAttributes.CLOUD_PLATFORM |
| 58 | + ] = CloudPlatformValues.AZURE_APP_SERVICE.value |
66 | 59 |
|
| 60 | + azure_resource_uri = _get_azure_resource_uri(website_site_name) |
| 61 | + if azure_resource_uri: |
| 62 | + attributes[ |
| 63 | + ResourceAttributes.CLOUD_RESOURCE_ID |
| 64 | + ] = azure_resource_uri |
| 65 | + for (key, env_var) in _APP_SERVICE_ATTRIBUTE_ENV_VARS.items(): |
| 66 | + value = environ.get(env_var) |
| 67 | + if value: |
| 68 | + attributes[key] = value |
| 69 | + except Exception as e: |
| 70 | + _logger.info("Could not detect Azure App Service metadata: %s", e) |
67 | 71 | return Resource(attributes)
|
68 | 72 |
|
69 | 73 |
|
|
0 commit comments