py_zipkin/encoding/_encoders.py
def encode_span(self, v2_span):
        """Encodes a single span to JSON."""
        span = v2_span.build_v1_span()

        json_span = {
            'traceId': span.trace_id,
            'name': span.name,
            'id': span.id,
            'annotations': [],
            'binaryAnnotations': [],
        }

        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)

        v1_endpoint = self._create_json_endpoint(span.endpoint, True)

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

        for key, value in span.binary_annotations.items():
            json_span['binaryAnnotations'].append({
                'key': key,
                'value': value,
                'endpoint': v1_endpoint,
            })

        # Add sa/ca binary annotations
        if v2_span.remote_endpoint:
            self.encode_remote_endpoint(
                v2_span.remote_endpoint,
                v2_span.kind,
                json_span['binaryAnnotations'],
            )

        encoded_span = json.dumps(json_span)

        return encoded_span
def encode_span(self, v2_span):
        """Encodes a single span to JSON."""
        span = v2_span.build_v1_span()

        json_span = {
            'traceId': span.trace_id,
            'name': span.name,
            'id': span.id,
            'annotations': [],
            'binaryAnnotations': [],
        }

        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)

        v1_endpoint = self._create_json_endpoint(span.endpoint, True)

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

        for key, value in span.binary_annotations.items():
            json_span['binaryAnnotations'].append({
                'key': key,
                'value': value,
                'endpoint': v1_endpoint,
            })

        # Add sa/ca binary annotations
        if v2_span.remote_endpoint:
            self.encode_remote_endpoint(
                v2_span.remote_endpoint,
                v2_span.kind,
                json_span['binaryAnnotations'],
            )

        encoded_span = json.dumps(json_span)

        return encoded_span
def encode_span ( self , v2_span ) : span = v2_span . build_v1_span ( ) json_span = { 'traceId' : span . trace_id , 'name' : span . name , 'id' : span . id , 'annotations' : [ ] , 'binaryAnnotations' : [ ] , } 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 ) v1_endpoint = self . _create_json_endpoint ( span . endpoint , True ) for key , timestamp in span . annotations . items ( ) : json_span [ 'annotations' ] . append ( { 'endpoint' : v1_endpoint , 'timestamp' : int ( timestamp * 1000000 ) , 'value' : key , } ) for key , value in span . binary_annotations . items ( ) : json_span [ 'binaryAnnotations' ] . append ( { 'key' : key , 'value' : value , 'endpoint' : v1_endpoint , } ) # Add sa/ca binary annotations if v2_span . remote_endpoint : self . encode_remote_endpoint ( v2_span . remote_endpoint , v2_span . kind , json_span [ 'binaryAnnotations' ] , ) encoded_span = json . dumps ( json_span ) return encoded_span
Encodes a single span to JSON.
Encodes a single span to JSON .