Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/opentelemetry/sdk/util/instrumentation.py: 50%

62 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:35 +0000

1# Copyright The OpenTelemetry Authors 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14from json import dumps 

15from typing import Optional 

16 

17from deprecated import deprecated 

18 

19 

20class InstrumentationInfo: 

21 """Immutable information about an instrumentation library module. 

22 

23 See `opentelemetry.trace.TracerProvider.get_tracer` for the meaning of these 

24 properties. 

25 """ 

26 

27 __slots__ = ("_name", "_version", "_schema_url") 

28 

29 @deprecated(version="1.11.1", reason="You should use InstrumentationScope") 

30 def __init__( 

31 self, 

32 name: str, 

33 version: Optional[str] = None, 

34 schema_url: Optional[str] = None, 

35 ): 

36 self._name = name 

37 self._version = version 

38 if schema_url is None: 

39 schema_url = "" 

40 self._schema_url = schema_url 

41 

42 def __repr__(self): 

43 return f"{type(self).__name__}({self._name}, {self._version}, {self._schema_url})" 

44 

45 def __hash__(self): 

46 return hash((self._name, self._version, self._schema_url)) 

47 

48 def __eq__(self, value): 

49 return type(value) is type(self) and ( 

50 self._name, 

51 self._version, 

52 self._schema_url, 

53 ) == (value._name, value._version, value._schema_url) 

54 

55 def __lt__(self, value): 

56 if type(value) is not type(self): 

57 return NotImplemented 

58 return (self._name, self._version, self._schema_url) < ( 

59 value._name, 

60 value._version, 

61 value._schema_url, 

62 ) 

63 

64 @property 

65 def schema_url(self) -> Optional[str]: 

66 return self._schema_url 

67 

68 @property 

69 def version(self) -> Optional[str]: 

70 return self._version 

71 

72 @property 

73 def name(self) -> str: 

74 return self._name 

75 

76 

77class InstrumentationScope: 

78 """A logical unit of the application code with which the emitted telemetry can be 

79 associated. 

80 

81 See `opentelemetry.trace.TracerProvider.get_tracer` for the meaning of these 

82 properties. 

83 """ 

84 

85 __slots__ = ("_name", "_version", "_schema_url") 

86 

87 def __init__( 

88 self, 

89 name: str, 

90 version: Optional[str] = None, 

91 schema_url: Optional[str] = None, 

92 ) -> None: 

93 self._name = name 

94 self._version = version 

95 if schema_url is None: 

96 schema_url = "" 

97 self._schema_url = schema_url 

98 

99 def __repr__(self) -> str: 

100 return f"{type(self).__name__}({self._name}, {self._version}, {self._schema_url})" 

101 

102 def __hash__(self) -> int: 

103 return hash((self._name, self._version, self._schema_url)) 

104 

105 def __eq__(self, value: object) -> bool: 

106 if not isinstance(value, InstrumentationScope): 

107 return NotImplemented 

108 return (self._name, self._version, self._schema_url) == ( 

109 value._name, 

110 value._version, 

111 value._schema_url, 

112 ) 

113 

114 def __lt__(self, value: object) -> bool: 

115 if not isinstance(value, InstrumentationScope): 

116 return NotImplemented 

117 return (self._name, self._version, self._schema_url) < ( 

118 value._name, 

119 value._version, 

120 value._schema_url, 

121 ) 

122 

123 @property 

124 def schema_url(self) -> Optional[str]: 

125 return self._schema_url 

126 

127 @property 

128 def version(self) -> Optional[str]: 

129 return self._version 

130 

131 @property 

132 def name(self) -> str: 

133 return self._name 

134 

135 def to_json(self, indent=4) -> str: 

136 return dumps( 

137 { 

138 "name": self._name, 

139 "version": self._version, 

140 "schema_url": self._schema_url, 

141 }, 

142 indent=indent, 

143 )