예제 #1
0
def test_mutate_closed_entity():

    segment = Segment('seg')
    segment.close()

    with pytest.raises(AlreadyEndedException):
        segment.put_annotation('key', 'value')

    with pytest.raises(AlreadyEndedException):
        segment.put_metadata('key', 'value')

    with pytest.raises(AlreadyEndedException):
        segment.put_http_meta('url', 'my url')

    with pytest.raises(AlreadyEndedException):
        segment.close()
예제 #2
0
def test_put_annotation():

    segment = Segment('seg')
    invalid = {
        'key1': 'value1',
        'key2': 'value2',
    }
    # invalid annotation key-value pair should be dropped
    segment.put_annotation('invalid', invalid)
    segment.put_annotation('number', 1)

    subsegment = Subsegment('sub', 'local', segment)
    segment.add_subsegment(subsegment)
    subsegment.put_annotation('bool', False)

    doc = entity_to_dict(segment)
    assert doc['annotations']['number'] == 1
    assert 'invalid' not in doc['annotations']

    sub_doc = doc['subsegments'][0]
    assert not sub_doc['annotations']['bool']
def test_serialize_segment_with_annotation():

    segment = Segment('test')
    
    segment.put_annotation('key', 'value')
    
    segment.close()
    
    expected_segment_dict = {
    "id": segment.id,
    "name": "test",
    "start_time": segment.start_time,
    "in_progress": False,
    "annotations": {
        "key": "value"
    },
    "trace_id": segment.trace_id,
    "end_time": segment.end_time
    }
 
    actual_segment_dict = entity_to_dict(segment)
      
    assert  expected_segment_dict == actual_segment_dict