def encode_span(self, span):
json_span = {<EOL>'<STR_LIT>': span.trace_id,<EOL>'<STR_LIT:id>': span.span_id,<EOL>}<EOL>if span.name:<EOL><INDENT>json_span['<STR_LIT:name>'] = span.name<EOL><DEDENT>if span.parent_id:<EOL><INDENT>json_span['<STR_LIT>'] = span.parent_id<EOL><DEDENT>if span.timestamp:<EOL><INDENT>json_span['<STR_LIT>'] = int(span.timestamp * <NUM_LIT>)<EOL><DEDENT>if span.duration:<EOL><INDENT>json_span['<STR_LIT>'] = int(span.duration * <NUM_LIT>)<EOL><DEDENT>if span.shared is True:<EOL><INDENT>json_span['<STR_LIT>'] = True<EOL><DEDENT>if span.kind and span.kind.value is not None:<EOL><INDENT>json_span['<STR_LIT>'] = span.kind.value<EOL><DEDENT>if span.local_endpoint:<EOL><INDENT>json_span['<STR_LIT>'] = self._create_json_endpoint(<EOL>span.local_endpoint,<EOL>False,<EOL>)<EOL><DEDENT>if span.remote_endpoint:<EOL><INDENT>json_span['<STR_LIT>'] = self._create_json_endpoint(<EOL>span.remote_endpoint,<EOL>False,<EOL>)<EOL><DEDENT>if span.tags and len(span.tags) > <NUM_LIT:0>:<EOL><INDENT>json_span['<STR_LIT>'] = span.tags<EOL><DEDENT>if span.annotations:<EOL><INDENT>json_span['<STR_LIT>'] = [<EOL>{<EOL>'<STR_LIT>': int(timestamp * <NUM_LIT>),<EOL>'<STR_LIT:value>': key,<EOL>}<EOL>for key, timestamp in span.annotations.items()<EOL>]<EOL><DEDENT>encoded_span = json.dumps(json_span)<EOL>return encoded_span<EOL>
Encodes a single span to JSON.