Source code for multistorageclient.telemetry.attributes.msc_config
1# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 2# SPDX-License-Identifier: Apache-2.0 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.1516importcopy17importhashlib18fromcollections.abcimportMapping19fromtypingimportAny,TypedDict2021importjmespath22importjmespath.functionsasjmespath_functions23importopentelemetry.util.typesasapi_types2425from.baseimportAttributesProvider262728class_MSCConfigJMESPathFunctions(jmespath_functions.Functions):29"""30 Additional JMESPath functions.31 """3233@jmespath_functions.signature({"types":["string"]},{"types":["string"]})34def_func_hash(self,algorithm:str,value:str)->str:35"""36 Return the hexadecimal hash digest of a string.3738 :param algorithm: Hash algorithm.39 :param value: Hash value.40 :return: Hexadecimal hash digest.41 """42value_hash=hashlib.new(algorithm)43value_hash.update(value.encode())44returnvalue_hash.hexdigest()4546
[docs]47classMSCConfigAttributesProvider(AttributesProvider):48"""49 Provides :py:type:`opentelemetry.util.types.Attributes` from a multi-storage client configuration.50 """51
[docs]52classAttributeValueOptions(TypedDict):53"""54 MSC configuration attribute value options.55 """5657#: JMESPath expression.58#:59#: Additional JMESPath functions:60#:61#: - ``hash(algorithm: str, value: str)``62#: - Calculate the hash digest of a value using a specific hash algorithm (e.g. ``sha3-256``).63#: - See :py:meth:`hashlib.new` for algorithms.64expression:str
6566#: Static attributes.67_attributes:api_types.Attributes6869def__init__(self,attributes:Mapping[str,AttributeValueOptions],config_dict:Mapping[str,Any]):70"""71 :param attributes: Map of attribute key to map of attribute value options.72 """7374self._attributes={75attribute_key:jmespath.search(76attribute_value_options["expression"],77config_dict,78options=jmespath.Options(custom_functions=_MSCConfigJMESPathFunctions()),79)80forattribute_key,attribute_value_optionsinattributes.items()81}82