sdk: Specify to_json indent from arguments
We want to get a json of span without indent, but it's not possible with Span#to_json because the method uses hard-coded indent. We currently use a workaround of json.loads(span.to_json()) which is not efficient in the performance.
@@ -360,7 +360,7 @@ class Span(trace_api.Span):
f_links.append(f_link)
return f_links
- def to_json(self):
+ def to_json(self, indent=4):
parent_id = None
if self.parent is not None:
if isinstance(self.parent, Span):
@@ -397,7 +397,7 @@ class Span(trace_api.Span):
f_span["events"] = self._format_events(self.events)
f_span["links"] = self._format_links(self.links)
- return json.dumps(f_span, indent=4)
+ return json.dumps(f_span, indent=indent)
def get_context(self):
return self.context
