Skip to content

Commit 124081b

Browse files
author
Andrew Xue
committed
address comments
1 parent 4829210 commit 124081b

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

ext/opentelemetry-ext-cloud-trace/README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
OpenTelemetry Cloud Trace Exporters
22
=====================================
33

4-
This library provides integration with Google Cloud Trace.
4+
This library provides classes for exporting trace data to Google Cloud Trace.
55

66
Installation
77
------------

ext/opentelemetry-ext-cloud-trace/src/opentelemetry/ext/cloud_trace/__init__.py

+11-13
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def translate_to_cloud_trace(
109109
{
110110
"name": span_name,
111111
"span_id": span_id,
112-
"display_name": get_truncatable_str(span.name),
112+
"display_name": get_truncatable_str_object(span.name),
113113
"start_time": start_time,
114114
"end_time": end_time,
115115
"parent_span_id": parent_id,
@@ -141,13 +141,11 @@ def get_time_from_ns(nanoseconds):
141141
return {"seconds": int(nanoseconds / 1e9), "nanos": int(nanoseconds % 1e9)}
142142

143143

144-
def get_truncatable_str(str_to_convert, max_length=MAX_LENGTH):
144+
def get_truncatable_str_object(str_to_convert, max_length=MAX_LENGTH):
145145
"""Truncate the string if it exceeds the length limit and record the truncated bytes
146146
count.
147147
"""
148-
truncated, truncated_byte_count = check_str_length(
149-
str_to_convert, max_length
150-
)
148+
truncated, truncated_byte_count = truncate_str(str_to_convert, max_length)
151149

152150
result = {
153151
"value": truncated,
@@ -156,7 +154,7 @@ def get_truncatable_str(str_to_convert, max_length=MAX_LENGTH):
156154
return result
157155

158156

159-
def check_str_length(str_to_check, limit=MAX_LENGTH):
157+
def truncate_str(str_to_check, limit=MAX_LENGTH):
160158
"""Check the length of a string. If exceeds limit, then truncate it.
161159
"""
162160
str_bytes = str_to_check.encode("utf-8")
@@ -213,7 +211,7 @@ def _extract_events(events: Sequence[Event]):
213211
{
214212
"time": get_time_from_ns(event.timestamp),
215213
"annotation": {
216-
"description": get_truncatable_str(event.name, 256),
214+
"description": get_truncatable_str_object(event.name, 256),
217215
"attributes": _extract_attributes(event.attributes),
218216
},
219217
}
@@ -223,15 +221,15 @@ def _extract_events(events: Sequence[Event]):
223221

224222
def _extract_attributes(attrs: types.Attributes):
225223
"""Convert span.attributes to dict."""
226-
attributes_json = {}
224+
attributes_dict = {}
227225

228226
for key, value in attrs.items():
229-
key = check_str_length(key)[0]
227+
key = truncate_str(key)[0]
230228
value = _format_attribute_value(value)
231229

232230
if value is not None:
233-
attributes_json[key] = value
234-
return {"attribute_map": attributes_json}
231+
attributes_dict[key] = value
232+
return {"attribute_map": attributes_dict}
235233

236234

237235
def _format_attribute_value(value: types.AttributeValue):
@@ -241,10 +239,10 @@ def _format_attribute_value(value: types.AttributeValue):
241239
value_type = "int_value"
242240
elif isinstance(value, str):
243241
value_type = "string_value"
244-
value = get_truncatable_str(value)
242+
value = get_truncatable_str_object(value)
245243
elif isinstance(value, float):
246244
value_type = "string_value"
247-
value = get_truncatable_str(str(value))
245+
value = get_truncatable_str_object(str(value))
248246
else:
249247
logger.warning(
250248
"ignoring attribute value %s of type %s. Values type must be one of bool, int, string or float",

0 commit comments

Comments
 (0)