Skip to content

Commit

Permalink
sdk: Specify to_json indent from arguments (#718)
Browse files Browse the repository at this point in the history
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.

Co-authored-by: alrex <aboten@lightstep.com>
Co-authored-by: Yusuke Tsutsumi <yusuke@tsutsumi.io>
  • Loading branch information
3 people authored May 21, 2020
1 parent 58b7bcc commit b4e135b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def _format_links(links):
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):
Expand Down Expand Up @@ -397,7 +397,7 @@ def to_json(self):
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
Expand Down

0 comments on commit b4e135b

Please sign in to comment.