Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle unicode and str in exporters for py2 #274

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion opencensus/trace/exporters/jaeger_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import logging
import socket

from six import text_type, string_types
from thrift.protocol import TBinaryProtocol, TCompactProtocol
from thrift.transport import THttpClient, TTransport

Expand Down Expand Up @@ -307,12 +308,14 @@ def _extract_tags(attr):

def _convert_attribute_to_tag(key, attr):
"""Convert the attributes to jaeger tags."""
if isinstance(attr, string_types):
attr = attr.decode('utf8')
if isinstance(attr, bool):
return jaeger.Tag(
key=key,
vBool=attr,
vType=jaeger.TagType.BOOL)
if isinstance(attr, str):
if isinstance(attr, text_type):
return jaeger.Tag(
key=key,
vStr=attr,
Expand Down
6 changes: 5 additions & 1 deletion opencensus/trace/exporters/zipkin_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import requests

from six import text_type, string_types

from opencensus.trace.exporters import base
from opencensus.trace.exporters.transports import sync
from opencensus.trace.utils import check_str_length
Expand Down Expand Up @@ -198,9 +200,11 @@ def _extract_tags_from_span(attr):
return {}
tags = {}
for attribute_key, attribute_value in attr.items():
if isinstance(attribute_value, string_types):
attribute_value = attribute_value.decode('utf8')
if isinstance(attribute_value, (int, bool)):
value = str(attribute_value)
elif isinstance(attribute_value, str):
elif isinstance(attribute_value, text_type):
res, _ = check_str_length(str_to_check=attribute_value)
value = res
else:
Expand Down