koichi12 commited on
Commit
596addb
·
verified ·
1 Parent(s): 11654ec

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .venv/lib/python3.11/site-packages/opencensus/__pycache__/__init__.cpython-311.pyc +0 -0
  2. .venv/lib/python3.11/site-packages/opencensus/log/__pycache__/__init__.cpython-311.pyc +0 -0
  3. .venv/lib/python3.11/site-packages/opencensus/metrics/label_value.py +42 -0
  4. .venv/lib/python3.11/site-packages/opencensus/tags/__init__.py +23 -0
  5. .venv/lib/python3.11/site-packages/opencensus/tags/__pycache__/__init__.cpython-311.pyc +0 -0
  6. .venv/lib/python3.11/site-packages/opencensus/tags/__pycache__/tag.cpython-311.pyc +0 -0
  7. .venv/lib/python3.11/site-packages/opencensus/tags/__pycache__/tag_key.cpython-311.pyc +0 -0
  8. .venv/lib/python3.11/site-packages/opencensus/tags/__pycache__/tag_map.cpython-311.pyc +0 -0
  9. .venv/lib/python3.11/site-packages/opencensus/tags/__pycache__/tag_value.cpython-311.pyc +0 -0
  10. .venv/lib/python3.11/site-packages/opencensus/tags/__pycache__/validation.cpython-311.pyc +0 -0
  11. .venv/lib/python3.11/site-packages/opencensus/tags/propagation/__init__.py +13 -0
  12. .venv/lib/python3.11/site-packages/opencensus/tags/propagation/__pycache__/__init__.cpython-311.pyc +0 -0
  13. .venv/lib/python3.11/site-packages/opencensus/tags/propagation/__pycache__/binary_serializer.cpython-311.pyc +0 -0
  14. .venv/lib/python3.11/site-packages/opencensus/tags/propagation/binary_serializer.py +109 -0
  15. .venv/lib/python3.11/site-packages/opencensus/tags/tag.py +38 -0
  16. .venv/lib/python3.11/site-packages/opencensus/tags/tag_key.py +35 -0
  17. .venv/lib/python3.11/site-packages/opencensus/tags/tag_map.py +104 -0
  18. .venv/lib/python3.11/site-packages/opencensus/tags/tag_value.py +35 -0
  19. .venv/lib/python3.11/site-packages/opencensus/tags/validation.py +42 -0
  20. .venv/lib/python3.11/site-packages/opencensus/trace/__init__.py +17 -0
  21. .venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/attributes.cpython-311.pyc +0 -0
  22. .venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/base_exporter.cpython-311.pyc +0 -0
  23. .venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/base_span.cpython-311.pyc +0 -0
  24. .venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/config_integration.cpython-311.pyc +0 -0
  25. .venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/execution_context.cpython-311.pyc +0 -0
  26. .venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/file_exporter.cpython-311.pyc +0 -0
  27. .venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/print_exporter.cpython-311.pyc +0 -0
  28. .venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/span_context.cpython-311.pyc +0 -0
  29. .venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/span_data.cpython-311.pyc +0 -0
  30. .venv/lib/python3.11/site-packages/opencensus/trace/attributes.py +74 -0
  31. .venv/lib/python3.11/site-packages/opencensus/trace/attributes_helper.py +43 -0
  32. .venv/lib/python3.11/site-packages/opencensus/trace/base_exporter.py +43 -0
  33. .venv/lib/python3.11/site-packages/opencensus/trace/base_span.py +109 -0
  34. .venv/lib/python3.11/site-packages/opencensus/trace/blank_span.py +165 -0
  35. .venv/lib/python3.11/site-packages/opencensus/trace/config_integration.py +38 -0
  36. .venv/lib/python3.11/site-packages/opencensus/trace/exceptions_status.py +25 -0
  37. .venv/lib/python3.11/site-packages/opencensus/trace/execution_context.py +89 -0
  38. .venv/lib/python3.11/site-packages/opencensus/trace/file_exporter.py +71 -0
  39. .venv/lib/python3.11/site-packages/opencensus/trace/integrations.py +52 -0
  40. .venv/lib/python3.11/site-packages/opencensus/trace/link.py +71 -0
  41. .venv/lib/python3.11/site-packages/opencensus/trace/logging_exporter.py +85 -0
  42. .venv/lib/python3.11/site-packages/opencensus/trace/print_exporter.py +51 -0
  43. .venv/lib/python3.11/site-packages/opencensus/trace/propagation/__init__.py +13 -0
  44. .venv/lib/python3.11/site-packages/opencensus/trace/propagation/__pycache__/__init__.cpython-311.pyc +0 -0
  45. .venv/lib/python3.11/site-packages/opencensus/trace/propagation/__pycache__/b3_format.cpython-311.pyc +0 -0
  46. .venv/lib/python3.11/site-packages/opencensus/trace/propagation/__pycache__/binary_format.cpython-311.pyc +0 -0
  47. .venv/lib/python3.11/site-packages/opencensus/trace/propagation/__pycache__/google_cloud_format.cpython-311.pyc +0 -0
  48. .venv/lib/python3.11/site-packages/opencensus/trace/propagation/__pycache__/text_format.cpython-311.pyc +0 -0
  49. .venv/lib/python3.11/site-packages/opencensus/trace/propagation/__pycache__/trace_context_http_header_format.cpython-311.pyc +0 -0
  50. .venv/lib/python3.11/site-packages/opencensus/trace/propagation/__pycache__/tracestate_string_format.cpython-311.pyc +0 -0
.venv/lib/python3.11/site-packages/opencensus/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (321 Bytes). View file
 
.venv/lib/python3.11/site-packages/opencensus/log/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (5.19 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/metrics/label_value.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2018, OpenCensus 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.
14
+
15
+
16
+ class LabelValue(object):
17
+ """The label values associated with the TimeSeries.
18
+
19
+ :type value: str
20
+ :param value: the value for the label
21
+ """
22
+ def __init__(self, value=None):
23
+ self._value = value
24
+
25
+ def __repr__(self):
26
+ return ("{}({})"
27
+ .format(
28
+ type(self).__name__,
29
+ self.value,
30
+ ))
31
+
32
+ @property
33
+ def value(self):
34
+ """the value for the label"""
35
+ return self._value
36
+
37
+ def __eq__(self, other):
38
+ return isinstance(other, LabelValue) and \
39
+ self.value == other.value
40
+
41
+ def __hash__(self):
42
+ return hash(self.value)
.venv/lib/python3.11/site-packages/opencensus/tags/__init__.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2018, OpenCensus 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.
14
+
15
+ from opencensus.common.runtime_context import RuntimeContext
16
+ from opencensus.tags.tag import Tag
17
+ from opencensus.tags.tag_key import TagKey
18
+ from opencensus.tags.tag_map import TagMap
19
+ from opencensus.tags.tag_value import TagValue
20
+
21
+ __all__ = ['Tag', 'TagContext', 'TagKey', 'TagValue', 'TagMap']
22
+
23
+ TagContext = RuntimeContext.register_slot('tag_context', None)
.venv/lib/python3.11/site-packages/opencensus/tags/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (700 Bytes). View file
 
.venv/lib/python3.11/site-packages/opencensus/tags/__pycache__/tag.cpython-311.pyc ADDED
Binary file (1.29 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/tags/__pycache__/tag_key.cpython-311.pyc ADDED
Binary file (1.32 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/tags/__pycache__/tag_map.cpython-311.pyc ADDED
Binary file (4.13 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/tags/__pycache__/tag_value.cpython-311.pyc ADDED
Binary file (1.35 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/tags/__pycache__/validation.cpython-311.pyc ADDED
Binary file (1.53 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/tags/propagation/__init__.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2018, OpenCensus 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.
.venv/lib/python3.11/site-packages/opencensus/tags/propagation/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (200 Bytes). View file
 
.venv/lib/python3.11/site-packages/opencensus/tags/propagation/__pycache__/binary_serializer.cpython-311.pyc ADDED
Binary file (4.96 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/tags/propagation/binary_serializer.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2018, OpenCensus 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.
14
+
15
+ # -*- coding: utf-8 -*-
16
+
17
+ import six
18
+
19
+ import logging
20
+
21
+ from google.protobuf.internal.encoder import _VarintBytes
22
+
23
+ from opencensus.tags import tag_map as tag_map_module
24
+
25
+ # Used for decoding hex bytes to hex string.
26
+ UTF8 = 'utf-8'
27
+
28
+ VERSION_ID = 0
29
+ TAG_FIELD_ID = 0
30
+ TAG_MAP_SERIALIZED_SIZE_LIMIT = 8192
31
+
32
+
33
+ class BinarySerializer(object):
34
+ def from_byte_array(self, binary):
35
+ if len(binary) <= 0:
36
+ logging.warning("Input byte[] cannot be empty/")
37
+ return tag_map_module.TagMap()
38
+ else:
39
+ buffer = memoryview(binary)
40
+ version_id = buffer[0]
41
+ if six.PY2:
42
+ version_id = ord(version_id)
43
+ if version_id != VERSION_ID:
44
+ raise ValueError("Invalid version id.")
45
+ return self._parse_tags(buffer)
46
+
47
+ def to_byte_array(self, tag_context):
48
+ encoded_bytes = b''
49
+ encoded_bytes += _VarintBytes(VERSION_ID)
50
+ total_chars = 0
51
+ for tag in tag_context:
52
+ tag_key, tag_value = tag
53
+ total_chars += len(tag_key)
54
+ total_chars += len(tag_value)
55
+ encoded_bytes = self._encode_tag(
56
+ tag_key, tag_value, encoded_bytes)
57
+ if total_chars <= TAG_MAP_SERIALIZED_SIZE_LIMIT:
58
+ return encoded_bytes
59
+ else: # pragma: NO COVER
60
+ logging.warning("Size of the tag context exceeds the maximum size")
61
+
62
+ def _parse_tags(self, buffer):
63
+ tag_context = tag_map_module.TagMap()
64
+ limit = len(buffer)
65
+ total_chars = 0
66
+ i = 1
67
+ while i < limit:
68
+ field_id = buffer[i] if six.PY3 else ord(buffer[i])
69
+ if field_id == TAG_FIELD_ID:
70
+ i += 1
71
+ key = self._decode_string(buffer, i)
72
+ i += len(key)
73
+ total_chars += len(key)
74
+ i += 1
75
+ val = self._decode_string(buffer, i)
76
+ i += len(val)
77
+ total_chars += len(val)
78
+ i += 1
79
+ if total_chars > \
80
+ TAG_MAP_SERIALIZED_SIZE_LIMIT: # pragma: NO COVER
81
+ logging.warning("Size of the tag context exceeds maximum")
82
+ break
83
+ else:
84
+ tag_context.insert(str(key), str(val))
85
+ else:
86
+ break
87
+ return tag_context
88
+
89
+ def _encode_tag(self, tag_key, tag_value, encoded_bytes):
90
+ encoded_bytes += _VarintBytes(TAG_FIELD_ID)
91
+ encoded_bytes = self._encode_string(tag_key, encoded_bytes)
92
+ encoded_bytes = self._encode_string(tag_value, encoded_bytes)
93
+ return encoded_bytes
94
+
95
+ def _encode_string(self, input_str, encoded_bytes):
96
+ encoded_bytes += _VarintBytes(len(input_str))
97
+ encoded_bytes += input_str.encode(UTF8)
98
+ return encoded_bytes
99
+
100
+ def _decode_string(self, buffer, pos):
101
+ length = buffer[pos] if six.PY3 else ord(buffer[pos])
102
+ builder = ""
103
+ i = 1
104
+ while i <= length:
105
+ bytes_to_decode = buffer[pos + i] if six.PY3 \
106
+ else ord(buffer[pos + i])
107
+ builder += _VarintBytes(bytes_to_decode).decode()
108
+ i += 1
109
+ return builder
.venv/lib/python3.11/site-packages/opencensus/tags/tag.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2018, OpenCensus 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.
14
+
15
+ from collections import namedtuple
16
+
17
+ from opencensus.tags.tag_key import TagKey
18
+ from opencensus.tags.tag_value import TagValue
19
+
20
+ Tag_ = namedtuple('Tag', ['key', 'value'])
21
+
22
+
23
+ class Tag(Tag_):
24
+ """A tag, in the format [KEY]:[VALUE].
25
+
26
+ :type key: str
27
+ :param key: The name of the tag
28
+
29
+ :type value: str
30
+ :param value: The value of the tag
31
+
32
+ """
33
+ def __new__(cls, key, value):
34
+ return super(Tag, cls).__new__(
35
+ cls,
36
+ key=TagKey(key),
37
+ value=TagValue(value),
38
+ )
.venv/lib/python3.11/site-packages/opencensus/tags/tag_key.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2018, OpenCensus 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.
14
+
15
+ from opencensus.tags.validation import is_valid_tag_name
16
+
17
+ _TAG_NAME_ERROR = \
18
+ 'tag name must not be empty,' \
19
+ 'no longer than 255 characters and of ascii values between 32 - 126'
20
+
21
+
22
+ class TagKey(str):
23
+ """A tag key with a property name"""
24
+
25
+ def __new__(cls, name):
26
+ """Create and return a new tag key
27
+
28
+ :type name: str
29
+ :param name: The name of the key
30
+ :return: TagKey
31
+ """
32
+ if not isinstance(name, cls):
33
+ if not is_valid_tag_name(name):
34
+ raise ValueError(_TAG_NAME_ERROR)
35
+ return super(TagKey, cls).__new__(cls, name)
.venv/lib/python3.11/site-packages/opencensus/tags/tag_map.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2018, OpenCensus 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.
14
+
15
+ from collections import OrderedDict
16
+
17
+ from opencensus.tags.tag_key import TagKey
18
+ from opencensus.tags.tag_value import TagValue
19
+
20
+
21
+ class TagMap(object):
22
+ """ A tag map is a map of tags from key to value
23
+
24
+ :type tags: list(:class: '~opencensus.tags.tag.Tag')
25
+ :param tags: a list of tags
26
+
27
+ """
28
+
29
+ def __init__(self, tags=None):
30
+ self.map = OrderedDict(tags if tags else [])
31
+
32
+ def __iter__(self):
33
+ return self.map.items().__iter__()
34
+
35
+ def insert(self, key, value):
36
+ """Inserts a key and value in the map if the map does not already
37
+ contain the key.
38
+
39
+ :type key: :class: '~opencensus.tags.tag_key.TagKey'
40
+ :param key: a tag key to insert into the map
41
+
42
+ :type value: :class: '~opencensus.tags.tag_value.TagValue'
43
+ :param value: a tag value that is associated with the tag key and
44
+ the value to insert into the tag map
45
+
46
+ """
47
+ if key in self.map:
48
+ return
49
+
50
+ try:
51
+ tag_key = TagKey(key)
52
+ tag_val = TagValue(value)
53
+ self.map[tag_key] = tag_val
54
+ except ValueError:
55
+ raise
56
+
57
+ def delete(self, key):
58
+ """Deletes a tag from the map if the key is in the map
59
+
60
+ :type key: :class: '~opencensus.tags.tag_key.TagKey'
61
+ :param key: A string representing a possible tag key
62
+
63
+ :returns: the value of the key in the dictionary if it is in there,
64
+ or None if it is not.
65
+ """
66
+ self.map.pop(key, None)
67
+
68
+ def update(self, key, value):
69
+ """Updates the map by updating the value of a key
70
+
71
+ :type key: :class: '~opencensus.tags.tag_key.TagKey'
72
+ :param key: A tag key to be updated
73
+
74
+ :type value: :class: '~opencensus.tags.tag_value.TagValue'
75
+ :param value: The value to update the key to in the map
76
+
77
+ """
78
+ if key in self.map:
79
+ self.map[key] = value
80
+
81
+ def tag_key_exists(self, key):
82
+ """Checking if the tag key exists in the map
83
+
84
+ :type key: '~opencensus.tags.tag_key.TagKey'
85
+ :param key: A string to check to see if that is a key in the map
86
+
87
+ :returns: True if the key is in map, False is it is not
88
+
89
+ """
90
+ return key in self.map
91
+
92
+ def get_value(self, key):
93
+ """ Gets the value of the key passed in if the key exists in the map
94
+
95
+ :type key: str
96
+ :param key: A string representing a key to get the value of in the map
97
+
98
+ :returns: A KeyError if the value is None, else returns the value
99
+
100
+ """
101
+ try:
102
+ return self.map[key]
103
+ except KeyError:
104
+ raise KeyError('key is not in map')
.venv/lib/python3.11/site-packages/opencensus/tags/tag_value.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2018, OpenCensus 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.
14
+
15
+ from opencensus.tags.validation import is_valid_tag_value
16
+
17
+ _TAG_VALUE_ERROR = \
18
+ 'tag value must not be longer than 255 characters ' \
19
+ 'and of ascii values between 32 - 126'
20
+
21
+
22
+ class TagValue(str):
23
+ """The value of a tag"""
24
+
25
+ def __new__(cls, value):
26
+ """Create and return a new tag value
27
+
28
+ :type value: str
29
+ :param value: A string representing the value of a key in a tag
30
+ :return: TagValue
31
+ """
32
+ if not isinstance(value, cls):
33
+ if not is_valid_tag_value(value):
34
+ raise ValueError(_TAG_VALUE_ERROR)
35
+ return super(TagValue, cls).__new__(cls, value)
.venv/lib/python3.11/site-packages/opencensus/tags/validation.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2018, OpenCensus 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.
14
+
15
+
16
+ def is_legal_chars(value):
17
+ return all(32 <= ord(char) <= 126 for char in value)
18
+
19
+
20
+ def is_valid_tag_name(name):
21
+ """Checks if the name of a tag key is valid
22
+
23
+ :type name: str
24
+ :param name: name to check
25
+
26
+ :rtype: bool
27
+ :returns: True if it valid, else returns False
28
+ """
29
+ return is_legal_chars(name) if 0 < len(name) <= 255 else False
30
+
31
+
32
+ def is_valid_tag_value(value):
33
+ """Checks if the value is valid
34
+
35
+ :type value: str
36
+ :param value: the value to be checked
37
+
38
+ :rtype: bool
39
+ :returns: True if valid, if not, False.
40
+
41
+ """
42
+ return is_legal_chars(value) if len(value) <= 255 else False
.venv/lib/python3.11/site-packages/opencensus/trace/__init__.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2017, OpenCensus 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.
14
+
15
+ from opencensus.trace.span import Span
16
+
17
+ __all__ = ['Span']
.venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/attributes.cpython-311.pyc ADDED
Binary file (3.09 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/base_exporter.cpython-311.pyc ADDED
Binary file (1.54 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/base_span.cpython-311.pyc ADDED
Binary file (4.17 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/config_integration.cpython-311.pyc ADDED
Binary file (1.47 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/execution_context.cpython-311.pyc ADDED
Binary file (3.85 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/file_exporter.cpython-311.pyc ADDED
Binary file (3.02 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/print_exporter.cpython-311.pyc ADDED
Binary file (2.19 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/span_context.cpython-311.pyc ADDED
Binary file (6.09 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/span_data.cpython-311.pyc ADDED
Binary file (7.21 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/trace/attributes.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2017, OpenCensus 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.
14
+ import six
15
+
16
+ from opencensus.common import utils
17
+
18
+
19
+ def _format_attribute_value(value):
20
+ if isinstance(value, bool):
21
+ value_type = 'bool_value'
22
+ elif isinstance(value, int):
23
+ value_type = 'int_value'
24
+ elif isinstance(value, six.string_types):
25
+ value_type = 'string_value'
26
+ value = utils.get_truncatable_str(value)
27
+ elif isinstance(value, float):
28
+ value_type = 'double_value'
29
+ else:
30
+ return None
31
+
32
+ return {value_type: value}
33
+
34
+
35
+ class Attributes(object):
36
+ """A set of attributes, each in the format [KEY]:[VALUE].
37
+
38
+ :type attributes: dict
39
+ :param attributes: The set of attributes. Each attribute's key can be up
40
+ to 128 bytes long. The value can be a string up to 256
41
+ bytes, an integer, a floating-point number, or the
42
+ Boolean values true and false.
43
+ """
44
+ def __init__(self, attributes=None):
45
+ self.attributes = attributes or {}
46
+
47
+ def set_attribute(self, key, value):
48
+ """Set a key value pair."""
49
+ self.attributes[key] = value
50
+
51
+ def delete_attribute(self, key):
52
+ """Delete an attribute given a key if existed."""
53
+ self.attributes.pop(key, None)
54
+
55
+ def get_attribute(self, key):
56
+ """Get a attribute value."""
57
+ return self.attributes.get(key, None)
58
+
59
+ def format_attributes_json(self):
60
+ """Convert the Attributes object to json format."""
61
+ attributes_json = {}
62
+
63
+ for key, value in self.attributes.items():
64
+ key = utils.check_str_length(key)[0]
65
+ value = _format_attribute_value(value)
66
+
67
+ if value is not None:
68
+ attributes_json[key] = value
69
+
70
+ result = {
71
+ 'attributeMap': attributes_json
72
+ }
73
+
74
+ return result
.venv/lib/python3.11/site-packages/opencensus/trace/attributes_helper.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2017, OpenCensus 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.
14
+
15
+ COMMON_ATTRIBUTES = {
16
+ 'AGENT': 'g.co/agent',
17
+ 'COMPONENT': 'component',
18
+ 'ERROR_MESSAGE': 'error.message',
19
+ 'ERROR_NAME': 'error.name',
20
+ 'HTTP_CLIENT_CITY': 'http.client_city',
21
+ 'HTTP_CLIENT_COUNTRY': 'http.client_country',
22
+ 'HTTP_CLIENT_PROTOCOL': 'http.client_protocol',
23
+ 'HTTP_CLIENT_REGION': 'http.client_region',
24
+ 'HTTP_HOST': 'http.host',
25
+ 'HTTP_METHOD': 'http.method',
26
+ 'HTTP_PATH': 'http.path',
27
+ 'HTTP_ROUTE': 'http.route',
28
+ 'HTTP_REDIRECTED_URL': 'http.redirected_url',
29
+ 'HTTP_REQUEST_SIZE': 'http.request_size',
30
+ 'HTTP_RESPONSE_SIZE': 'http.response_size',
31
+ 'HTTP_STATUS_CODE': 'http.status_code',
32
+ 'HTTP_URL': 'http.url',
33
+ 'HTTP_USER_AGENT': 'http.user_agent',
34
+ 'PID': 'pid',
35
+ 'STACKTRACE': 'stacktrace',
36
+ 'TID': 'tid',
37
+ }
38
+
39
+
40
+ GRPC_ATTRIBUTES = {
41
+ 'GRPC_HOST_PORT': 'grpc.host_port',
42
+ 'GRPC_METHOD': 'grpc.method',
43
+ }
.venv/lib/python3.11/site-packages/opencensus/trace/base_exporter.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2016-17, OpenCensus 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.
14
+
15
+ """Module containing base class for exporters."""
16
+
17
+
18
+ class Exporter(object):
19
+ """Base class for opencensus trace request exporters.
20
+
21
+ Subclasses of :class:`Exporter` must override :meth:`export`.
22
+ """
23
+
24
+ def emit(self, span_datas):
25
+ """
26
+ :type span_datas: list of :class:
27
+ `~opencensus.trace.span_data.SpanData`
28
+ :param list of opencensus.trace.span_data.SpanData span_datas:
29
+ SpanData tuples to emit
30
+ """
31
+ raise NotImplementedError
32
+
33
+ def export(self, span_datas):
34
+ """Export the trace. Send trace to transport, and transport will call
35
+ exporter.emit() to actually send the trace to the specified tracing
36
+ backend.
37
+
38
+ :type span_datas: list of :class:
39
+ `~opencensus.trace.span_data.SpanData`
40
+ :param list of opencensus.trace.span_data.SpanData span_datas:
41
+ SpanData tuples to export
42
+ """
43
+ raise NotImplementedError
.venv/lib/python3.11/site-packages/opencensus/trace/base_span.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2018, OpenCensus 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.
14
+
15
+ """Module containing base class for Span."""
16
+
17
+
18
+ class BaseSpan(object):
19
+ """Base class for Opencensus spans.
20
+ Subclasses of :class:`BaseSpan` must implement the below methods.
21
+ """
22
+
23
+ @staticmethod
24
+ def on_create(callback):
25
+ raise NotImplementedError
26
+
27
+ @property
28
+ def children(self):
29
+ """The child spans of the current span."""
30
+ raise NotImplementedError
31
+
32
+ def span(self, name='child_span'):
33
+ """Create a child span for the current span and append it to the child
34
+ spans list.
35
+
36
+ :type name: str
37
+ :param name: (Optional) The name of the child span.
38
+
39
+ :rtype: :class: `~opencensus.trace.span.Span`
40
+ :returns: A child Span to be added to the current span.
41
+ """
42
+ raise NotImplementedError
43
+
44
+ def add_attribute(self, attribute_key, attribute_value):
45
+ """Add attribute to span.
46
+
47
+ :type attribute_key: str
48
+ :param attribute_key: Attribute key.
49
+
50
+ :type attribute_value:str
51
+ :param attribute_value: Attribute value.
52
+ """
53
+ raise NotImplementedError
54
+
55
+ def add_annotation(self, description, **attrs):
56
+ """Add an annotation to span.
57
+
58
+ :type description: str
59
+ :param description: A user-supplied message describing the event.
60
+ The maximum length for the description is 256 bytes.
61
+
62
+ :type attrs: kwargs
63
+ :param attrs: keyworded arguments e.g. failed=True, name='Caching'
64
+ """
65
+ raise NotImplementedError
66
+
67
+ def add_message_event(self, message_event):
68
+ """Add a message event to this span.
69
+
70
+ :type message_event: :class:`opencensus.trace.time_event.MessageEvent`
71
+ :param message_event: The message event to attach to this span.
72
+ """
73
+ raise NotImplementedError
74
+
75
+ def add_link(self, link):
76
+ """Add a Link.
77
+
78
+ :type link: :class: `~opencensus.trace.link.Link`
79
+ :param link: A Link object.
80
+ """
81
+ raise NotImplementedError
82
+
83
+ def set_status(self, status):
84
+ """Sets span status.
85
+
86
+ :type code: :class: `~opencensus.trace.status.Status`
87
+ :param code: A Status object.
88
+ """
89
+ raise NotImplementedError
90
+
91
+ def start(self):
92
+ """Set the start time for a span."""
93
+ raise NotImplementedError
94
+
95
+ def finish(self):
96
+ """Set the end time for a span."""
97
+ raise NotImplementedError
98
+
99
+ def __iter__(self):
100
+ """Iterate through the span tree."""
101
+ raise NotImplementedError
102
+
103
+ def __enter__(self):
104
+ """Start a span."""
105
+ raise NotImplementedError
106
+
107
+ def __exit__(self, exception_type, exception_value, traceback):
108
+ """Finish a span."""
109
+ raise NotImplementedError
.venv/lib/python3.11/site-packages/opencensus/trace/blank_span.py ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2017, OpenCensus 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.
14
+
15
+ from opencensus.trace import base_span
16
+ from opencensus.trace.span_context import generate_span_id
17
+ from opencensus.trace.tracers import base
18
+
19
+
20
+ class BlankSpan(base_span.BaseSpan):
21
+ """A BlankSpan is an individual timed event which forms a node of the trace
22
+ tree. All operations are no-op.
23
+
24
+ :type name: str
25
+ :param name: The name of the span.
26
+
27
+ :type parent_span: :class:`~opencensus.trace.blank_span.BlankSpan`
28
+ :param parent_span: (Optional) Parent span.
29
+
30
+ :type status: :class: `~opencensus.trace.status.Status`
31
+ :param status: (Optional) An optional final status for this span.
32
+
33
+ :type context_tracer: :class:`~opencensus.trace.tracers.noop_tracer.
34
+ NoopTracer`
35
+ :param context_tracer: The tracer that holds a stack of spans. If this is
36
+ not None, then when exiting a span, use the end_span
37
+ method in the tracer class to finish a span. If no
38
+ tracer is passed in, then just finish the span using
39
+ the finish method in the Span class.
40
+ """
41
+
42
+ def __init__(
43
+ self,
44
+ name=None,
45
+ parent_span=None,
46
+ attributes=None,
47
+ start_time=None,
48
+ end_time=None,
49
+ span_id=None,
50
+ stack_trace=None,
51
+ annotations=None,
52
+ message_events=None,
53
+ links=None,
54
+ status=None,
55
+ same_process_as_parent_span=None,
56
+ context_tracer=None,
57
+ span_kind=None):
58
+ self.name = name
59
+ self.parent_span = parent_span
60
+ self.start_time = start_time
61
+ self.end_time = end_time
62
+
63
+ self.span_id = generate_span_id()
64
+ self.parent_span = base.NullContextManager()
65
+
66
+ self.attributes = {}
67
+ self.stack_trace = stack_trace
68
+ self.annotations = annotations
69
+ self.message_events = message_events
70
+ self.links = []
71
+ self.status = status
72
+ self.same_process_as_parent_span = same_process_as_parent_span
73
+ self._child_spans = []
74
+ self.context_tracer = context_tracer
75
+ self.span_kind = span_kind
76
+
77
+ @staticmethod
78
+ def on_create(callback):
79
+ pass
80
+
81
+ @property
82
+ def children(self):
83
+ """The child spans of the current BlankSpan."""
84
+ return list()
85
+
86
+ def span(self, name='child_span'):
87
+ """Create a child span for the current span and append it to the child
88
+ spans list.
89
+
90
+ :type name: str
91
+ :param name: (Optional) The name of the child span.
92
+
93
+ :rtype: :class: `~opencensus.trace.blankspan.BlankSpan`
94
+ :returns: A child Span to be added to the current span.
95
+ """
96
+ child_span = BlankSpan(name, parent_span=self)
97
+ self._child_spans.append(child_span)
98
+ return child_span
99
+
100
+ def add_attribute(self, attribute_key, attribute_value):
101
+ """No-op implementation of this method.
102
+
103
+ :type attribute_key: str
104
+ :param attribute_key: Attribute key.
105
+
106
+ :type attribute_value:str
107
+ :param attribute_value: Attribute value.
108
+ """
109
+ pass
110
+
111
+ def add_annotation(self, description, **attrs):
112
+ """No-op implementation of this method.
113
+
114
+ :type description: str
115
+ :param description: A user-supplied message describing the event.
116
+ The maximum length for the description is 256 bytes.
117
+
118
+ :type attrs: kwargs
119
+ :param attrs: keyworded arguments e.g. failed=True, name='Caching'
120
+ """
121
+ pass
122
+
123
+ def add_message_event(self, message_event):
124
+ """No-op implementation of this method.
125
+
126
+ :type message_event: :class:`opencensus.trace.time_event.MessageEvent`
127
+ :param message_event: The message event to attach to this span.
128
+ """
129
+ pass
130
+
131
+ def add_link(self, link):
132
+ """No-op implementation of this method.
133
+
134
+ :type link: :class: `~opencensus.trace.link.Link`
135
+ :param link: A Link object.
136
+ """
137
+ pass
138
+
139
+ def set_status(self, status):
140
+ """No-op implementation of this method.
141
+
142
+ :type code: :class: `~opencensus.trace.status.Status`
143
+ :param code: A Status object.
144
+ """
145
+ pass
146
+
147
+ def start(self):
148
+ """No-op implementation of this method."""
149
+ pass
150
+
151
+ def finish(self):
152
+ """No-op implementation of this method."""
153
+ pass
154
+
155
+ def __iter__(self):
156
+ """Iterate through the span tree."""
157
+ yield self
158
+
159
+ def __enter__(self):
160
+ """Start a span."""
161
+ return self
162
+
163
+ def __exit__(self, exception_type, exception_value, traceback):
164
+ """Finish a span."""
165
+ pass
.venv/lib/python3.11/site-packages/opencensus/trace/config_integration.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2017, OpenCensus 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.
14
+
15
+ import importlib
16
+ import logging
17
+
18
+ log = logging.getLogger(__name__)
19
+
20
+
21
+ def trace_integrations(integrations, tracer=None):
22
+ """Enable tracing on the selected integrations.
23
+ :type integrations: list
24
+ :param integrations: The integrations to be traced.
25
+ """
26
+ integrated = []
27
+
28
+ for item in integrations:
29
+ module_name = 'opencensus.ext.{}.trace'.format(item)
30
+ try:
31
+ module = importlib.import_module(module_name)
32
+ module.trace_integration(tracer=tracer)
33
+ integrated.append(item)
34
+ except Exception as e:
35
+ log.warning('Failed to integrate module: {}'.format(module_name))
36
+ log.warning('{}'.format(e))
37
+
38
+ return integrated
.venv/lib/python3.11/site-packages/opencensus/trace/exceptions_status.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2017, OpenCensus 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.
14
+
15
+ from google.rpc import code_pb2
16
+
17
+ from opencensus.trace.status import Status
18
+
19
+ CANCELLED = Status(code_pb2.CANCELLED)
20
+ INVALID_URL = Status(code_pb2.INVALID_ARGUMENT, message='invalid URL')
21
+ TIMEOUT = Status(code_pb2.DEADLINE_EXCEEDED, message='request timed out')
22
+
23
+
24
+ def unknown(exception):
25
+ return Status.from_exception(exception)
.venv/lib/python3.11/site-packages/opencensus/trace/execution_context.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2017, OpenCensus 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.
14
+
15
+ from opencensus.common.runtime_context import RuntimeContext
16
+ from opencensus.trace.tracers import noop_tracer
17
+
18
+ _attrs_slot = RuntimeContext.register_slot('attrs', lambda: {})
19
+ _current_span_slot = RuntimeContext.register_slot('current_span', None)
20
+ _exporter_slot = RuntimeContext.register_slot('is_exporter', False)
21
+ _tracer_slot = RuntimeContext.register_slot('tracer', noop_tracer.NoopTracer())
22
+
23
+
24
+ def is_exporter():
25
+ return RuntimeContext.is_exporter
26
+
27
+
28
+ def set_is_exporter(is_exporter):
29
+ RuntimeContext.is_exporter = is_exporter
30
+
31
+
32
+ def get_opencensus_tracer():
33
+ """Get the opencensus tracer from runtime context."""
34
+ return RuntimeContext.tracer
35
+
36
+
37
+ def set_opencensus_tracer(tracer):
38
+ """Add the tracer to runtime context."""
39
+ RuntimeContext.tracer = tracer
40
+
41
+
42
+ def set_opencensus_attr(attr_key, attr_value):
43
+ attrs = RuntimeContext.attrs.copy()
44
+ attrs[attr_key] = attr_value
45
+ RuntimeContext.attrs = attrs
46
+
47
+
48
+ def set_opencensus_attrs(attrs):
49
+ RuntimeContext.attrs = attrs
50
+
51
+
52
+ def get_opencensus_attr(attr_key):
53
+ return RuntimeContext.attrs.get(attr_key)
54
+
55
+
56
+ def get_opencensus_attrs():
57
+ return RuntimeContext.attrs
58
+
59
+
60
+ def get_current_span():
61
+ return RuntimeContext.current_span
62
+
63
+
64
+ def set_current_span(current_span):
65
+ RuntimeContext.current_span = current_span
66
+
67
+
68
+ def get_opencensus_full_context():
69
+ attrs = RuntimeContext.attrs
70
+ current_span = RuntimeContext.current_span
71
+ tracer = RuntimeContext.tracer
72
+ return tracer, current_span, attrs
73
+
74
+
75
+ def set_opencensus_full_context(tracer, span, attrs):
76
+ set_opencensus_tracer(tracer)
77
+ set_current_span(span)
78
+ set_opencensus_attrs(attrs or {})
79
+
80
+
81
+ def clean():
82
+ _attrs_slot.clear()
83
+ _current_span_slot.clear()
84
+ _tracer_slot.clear()
85
+
86
+
87
+ def clear():
88
+ """Clear the context, used in test."""
89
+ clean()
.venv/lib/python3.11/site-packages/opencensus/trace/file_exporter.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2017, OpenCensus 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.
14
+
15
+ """Export the trace spans to a local file."""
16
+
17
+ import json
18
+
19
+ from opencensus.common.transports import sync
20
+ from opencensus.trace import base_exporter, span_data
21
+
22
+ DEFAULT_FILENAME = 'opencensus-traces.json'
23
+
24
+
25
+ class FileExporter(base_exporter.Exporter):
26
+ """
27
+ :type file_name: str
28
+ :param file_name: The name of the output file.
29
+
30
+ :type transport: :class:`type`
31
+ :param transport: Class for creating new transport objects. It should
32
+ extend from the base_exporter :class:`.Transport` type
33
+ and implement :meth:`.Transport.export`. Defaults to
34
+ :class:`.SyncTransport`. The other option is
35
+ :class:`.AsyncTransport`.
36
+
37
+ :type file_mode: str
38
+ :param file_mode: The file mode to open the output file with.
39
+ Defaults to w+
40
+
41
+ """
42
+
43
+ def __init__(self, file_name=DEFAULT_FILENAME,
44
+ transport=sync.SyncTransport,
45
+ file_mode='w+'):
46
+ self.file_name = file_name
47
+ self.transport = transport(self)
48
+ self.file_mode = file_mode
49
+
50
+ def emit(self, span_datas):
51
+ """
52
+ :type span_datas: list of :class:
53
+ `~opencensus.trace.span_data.SpanData`
54
+ :param list of opencensus.trace.span_data.SpanData span_datas:
55
+ SpanData tuples to emit
56
+ """
57
+ with open(self.file_name, self.file_mode) as file:
58
+ # convert to the legacy trace json for easier refactoring
59
+ # TODO: refactor this to use the span data directly
60
+ legacy_trace_json = span_data.format_legacy_trace_json(span_datas)
61
+ trace_str = json.dumps(legacy_trace_json)
62
+ file.write(trace_str)
63
+
64
+ def export(self, span_datas):
65
+ """
66
+ :type span_datas: list of :class:
67
+ `~opencensus.trace.span_data.SpanData`
68
+ :param list of opencensus.trace.span_data.SpanData span_datas:
69
+ SpanData tuples to export
70
+ """
71
+ self.transport.export(span_datas)
.venv/lib/python3.11/site-packages/opencensus/trace/integrations.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2017, OpenCensus 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.
14
+
15
+ import threading
16
+
17
+ _INTEGRATIONS_BIT_MASK = 0
18
+ _INTEGRATIONS_LOCK = threading.Lock()
19
+
20
+
21
+ class _Integrations:
22
+ NONE = 0
23
+ DJANGO = 1
24
+ FLASK = 2
25
+ GOOGLE_CLOUD = 4
26
+ HTTP_LIB = 8
27
+ LOGGING = 16
28
+ MYSQL = 32
29
+ POSTGRESQL = 64
30
+ PYMONGO = 128
31
+ PYMYSQL = 256
32
+ PYRAMID = 512
33
+ REQUESTS = 1024
34
+ SQLALCHEMY = 2056
35
+ HTTPX = 16777216
36
+ FASTAPI = 4194304
37
+
38
+
39
+ def get_integrations():
40
+ return _INTEGRATIONS_BIT_MASK
41
+
42
+
43
+ def add_integration(integration):
44
+ with _INTEGRATIONS_LOCK:
45
+ global _INTEGRATIONS_BIT_MASK # pylint: disable=global-statement
46
+ _INTEGRATIONS_BIT_MASK |= integration
47
+
48
+
49
+ def remove_intregration(integration):
50
+ with _INTEGRATIONS_LOCK:
51
+ global _INTEGRATIONS_BIT_MASK # pylint: disable=global-statement
52
+ _INTEGRATIONS_BIT_MASK &= ~integration
.venv/lib/python3.11/site-packages/opencensus/trace/link.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2017, OpenCensus 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.
14
+
15
+
16
+ class Type(object):
17
+ """The relationship of the current span relative to the linked span: child,
18
+ parent, or unspecified.
19
+
20
+ Attributes:
21
+ TYPE_UNSPECIFIED (int): The relationship of the two spans is unknown.
22
+ CHILD_LINKED_SPAN (int): The linked span is a child of the current span.
23
+ PARENT_LINKED_SPAN (int): The linked span is a parent of the current
24
+ span.
25
+ """
26
+ TYPE_UNSPECIFIED = 0
27
+ CHILD_LINKED_SPAN = 1
28
+ PARENT_LINKED_SPAN = 2
29
+
30
+
31
+ class Link(object):
32
+ """A pointer from the current span to another span in the same trace or in
33
+ a different trace. For example, this can be used in batching operations,
34
+ where a single batch handler processes multiple requests from different
35
+ traces or when the handler receives a request from a different project.
36
+
37
+ :type trace_id: str
38
+ :param trace_id: The [TRACE_ID] for a trace within a project.
39
+
40
+ :type span_id: str
41
+ :param span_id: The [SPAN_ID] for a span within a trace.
42
+
43
+ :type type: Enum of :class:`~opencensus.trace.link.Type`
44
+ :param type: The relationship of the current span relative to the linked
45
+ span.
46
+
47
+ :type attributes: :class:`~opencensus.trace.attributes.Attributes`
48
+ :param attributes: A set of attributes on the link. You have have up to 32
49
+ attributes per link.
50
+ """
51
+ def __init__(self, trace_id, span_id, type=None, attributes=None):
52
+ self.trace_id = trace_id
53
+ self.span_id = span_id
54
+
55
+ if type is None:
56
+ type = Type.TYPE_UNSPECIFIED
57
+
58
+ self.type = type
59
+ self.attributes = attributes
60
+
61
+ def format_link_json(self):
62
+ """Convert a Link object to json format."""
63
+ link_json = {}
64
+ link_json['trace_id'] = self.trace_id
65
+ link_json['span_id'] = self.span_id
66
+ link_json['type'] = self.type
67
+
68
+ if self.attributes is not None:
69
+ link_json['attributes'] = self.attributes
70
+
71
+ return link_json
.venv/lib/python3.11/site-packages/opencensus/trace/logging_exporter.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2017, OpenCensus 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.
14
+
15
+ """Export the spans data to python logging."""
16
+
17
+ import logging
18
+
19
+ from opencensus.common.transports import sync
20
+ from opencensus.trace import base_exporter, span_data
21
+
22
+
23
+ class LoggingExporter(base_exporter.Exporter):
24
+ """A exporter to export the spans data to python logging. Also can use
25
+ handlers like CloudLoggingHandler to log to Stackdriver Logging API.
26
+
27
+ :type handler: :class:`logging.handler`
28
+ :param handler: the handler to attach to the global handler
29
+
30
+ :type transport: :class:`type`
31
+ :param transport: Class for creating new transport objects. It should
32
+ extend from the base_exporter :class:`.Transport` type
33
+ and implement :meth:`.Transport.export`. Defaults to
34
+ :class:`.SyncTransport`. The other option is
35
+ :class:`.AsyncTransport`.
36
+
37
+ Example:
38
+
39
+ .. code-block:: python
40
+
41
+ import google.cloud.logging
42
+ from google.cloud.logging.handlers import CloudLoggingHandler
43
+ from opencensus.trace import logging_exporter
44
+
45
+ client = google.cloud.logging.Client()
46
+ cloud_handler = CloudLoggingHandler(client)
47
+ exporter = logging_exporter.LoggingExporter(handler=cloud_handler)
48
+
49
+ exporter.export(your_spans_list)
50
+
51
+ Or initialize a context tracer with the logging exporter, then the traces
52
+ will be exported to logging when finished.
53
+ """
54
+
55
+ def __init__(self, handler=None, transport=sync.SyncTransport):
56
+ self.logger = logging.getLogger()
57
+
58
+ if handler is None:
59
+ handler = logging.StreamHandler()
60
+
61
+ self.handler = handler
62
+ self.logger.addHandler(handler)
63
+ self.logger.setLevel(logging.INFO)
64
+ self.transport = transport(self)
65
+
66
+ def emit(self, span_datas):
67
+ """
68
+ :type span_datas: list of :class:
69
+ `~opencensus.trace.span_data.SpanData`
70
+ :param list of opencensus.trace.span_data.SpanData span_datas:
71
+ SpanData tuples to emit
72
+ """
73
+ # convert to the legacy trace json for easier refactoring
74
+ # TODO: refactor this to use the span data directly
75
+ legacy_trace_json = span_data.format_legacy_trace_json(span_datas)
76
+ self.logger.info(legacy_trace_json)
77
+
78
+ def export(self, span_datas):
79
+ """
80
+ :type span_datas: list of :class:
81
+ `~opencensus.trace.span_data.SpanData`
82
+ :param list of opencensus.trace.span_data.SpanData span_datas:
83
+ SpanData tuples to export
84
+ """
85
+ self.transport.export(span_datas)
.venv/lib/python3.11/site-packages/opencensus/trace/print_exporter.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2017, OpenCensus 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.
14
+
15
+ """Export the trace spans by printing them out."""
16
+
17
+ from opencensus.common.transports import sync
18
+ from opencensus.trace import base_exporter
19
+
20
+
21
+ class PrintExporter(base_exporter.Exporter):
22
+ """Export the spans by printing them.
23
+
24
+ :type transport: :class:`type`
25
+ :param transport: Class for creating new transport objects. It should
26
+ extend from the base_exporter :class:`.Transport` type
27
+ and implement :meth:`.Transport.export`. Defaults to
28
+ :class:`.SyncTransport`. The other option is
29
+ :class:`.AsyncTransport`.
30
+ """
31
+
32
+ def __init__(self, transport=sync.SyncTransport):
33
+ self.transport = transport(self)
34
+
35
+ def emit(self, span_datas):
36
+ """
37
+ :type span_datas: list of :class:
38
+ `~opencensus.trace.span_data.SpanData`
39
+ :param list of opencensus.trace.span_data.SpanData span_datas:
40
+ SpanData tuples to emit
41
+ """
42
+ print(span_datas)
43
+
44
+ def export(self, span_datas):
45
+ """
46
+ :type span_datas: list of :class:
47
+ `~opencensus.trace.span_data.SpanData`
48
+ :param list of opencensus.trace.span_data.SpanData span_datas:
49
+ SpanData tuples to export
50
+ """
51
+ self.transport.export(span_datas)
.venv/lib/python3.11/site-packages/opencensus/trace/propagation/__init__.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2017, OpenCensus 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.
.venv/lib/python3.11/site-packages/opencensus/trace/propagation/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (201 Bytes). View file
 
.venv/lib/python3.11/site-packages/opencensus/trace/propagation/__pycache__/b3_format.cpython-311.pyc ADDED
Binary file (3.58 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/trace/propagation/__pycache__/binary_format.cpython-311.pyc ADDED
Binary file (5.56 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/trace/propagation/__pycache__/google_cloud_format.cpython-311.pyc ADDED
Binary file (5.06 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/trace/propagation/__pycache__/text_format.cpython-311.pyc ADDED
Binary file (3.28 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/trace/propagation/__pycache__/trace_context_http_header_format.cpython-311.pyc ADDED
Binary file (4.23 kB). View file
 
.venv/lib/python3.11/site-packages/opencensus/trace/propagation/__pycache__/tracestate_string_format.cpython-311.pyc ADDED
Binary file (2.16 kB). View file