-
Notifications
You must be signed in to change notification settings - Fork 609
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 5411759. * Remove deployment.environment from readme * Release 0.1.5 --------- Co-authored-by: jeremydvoss <[email protected]>
- Loading branch information
1 parent
460fc33
commit f8758c6
Showing
11 changed files
with
274 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...ntelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/functions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.