Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit ab1953f

Browse files
wkiserliyanhui1228
authored andcommitted
Fix bug preventing unicode attributes from being set in python 2.7 (#171)
1 parent 0cd85da commit ab1953f

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

opencensus/trace/attributes.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import six
1415

1516
from opencensus.trace import utils
1617

@@ -20,7 +21,7 @@ def _format_attribute_value(value):
2021
value_type = 'bool_value'
2122
elif isinstance(value, int):
2223
value_type = 'int_value'
23-
elif isinstance(value, str):
24+
elif isinstance(value, six.string_types):
2425
value_type = 'string_value'
2526
value = utils._get_truncatable_str(value)
2627
else:
@@ -38,7 +39,7 @@ class Attributes(object):
3839
bytes, an integer, or the Boolean values true and false.
3940
"""
4041
def __init__(self, attributes=None):
41-
self.attributes = dict(attributes or {})
42+
self.attributes = attributes or {}
4243

4344
def set_attribute(self, key, value):
4445
"""Set a key value pair."""
@@ -54,11 +55,6 @@ def get_attribute(self, key):
5455

5556
def format_attributes_json(self):
5657
"""Convert the Attributes object to json format."""
57-
attributes_json = {
58-
utils.check_str_length(key)[0]: _format_attribute_value(value)
59-
for key, value in self.attributes.items()
60-
}
61-
6258
attributes_json = {}
6359

6460
for key, value in self.attributes.items():

0 commit comments

Comments
 (0)