def encode_span(self, span):
        """Encodes a single span to JSON."""

        json_span = {
            'traceId': span.trace_id,
            'id': span.span_id,
        }

        if span.name:
            json_span['name'] = span.name
        if span.parent_id:
            json_span['parentId'] = span.parent_id
        if span.timestamp:
            json_span['timestamp'] = int(span.timestamp * 1000000)
        if span.duration:
            json_span['duration'] = int(span.duration * 1000000)
        if span.shared is True:
            json_span['shared'] = True
        if span.kind and span.kind.value is not None:
            json_span['kind'] = span.kind.value
        if span.local_endpoint:
            json_span['localEndpoint'] = self._create_json_endpoint(
                span.local_endpoint,
                False,
            )
        if span.remote_endpoint:
            json_span['remoteEndpoint'] = self._create_json_endpoint(
                span.remote_endpoint,
                False,
            )
        if span.tags and len(span.tags) > 0:
            json_span['tags'] = span.tags

        if span.annotations:
            json_span['annotations'] = [
                {
                    'timestamp': int(timestamp * 1000000),
                    'value': key,
                }
                for key, timestamp in span.annotations.items()
            ]

        encoded_span = json.dumps(json_span)

        return encoded_span