def test_custom_labels_override_trace(): event = RunnerEventMock() trace = trace_factory.get_or_create_trace() trace.clear_events() trace.set_runner(event) trace.add_label('test_label', 'test_value1') trace.add_label('test_label', 'test_value2') trace_metadata = trace.to_dict()['events'][0]['resource']['metadata'] assert trace_metadata.get('labels') is not None assert json.loads(trace_metadata['labels']) == {'test_label': 'test_value2'}
def test_multi_value_labels_sanity(): event = RunnerEventMock() trace = trace_factory.get_or_create_trace() trace.clear_events() trace.set_runner(event) trace.add_label('test_label', { 'test2_label': 15, 'test3_label': 'test', 4: 'hey' }) trace_metadata = trace.to_dict()['events'][0]['resource']['metadata'] assert trace_metadata.get('labels') is not None assert json.loads(trace_metadata['labels']) == { 'test_label.test2_label': '15', 'test_label.test3_label': 'test', 'test_label.4': 'hey', }
def test_custom_labels_sanity(): event = RunnerEventMock() trace = trace_factory.get_or_create_trace() trace.clear_events() trace.set_runner(event) trace.add_label('test_label', 'test_value') trace.add_label('test_label_2', 42) trace.add_label('test_label_3', 42.2) trace.add_label('test_label_4', True) # This is not an invalid label, but it won't be added because dict is empty. trace.add_label('test_label_invalid', {}) trace_metadata = trace.to_dict()['events'][0]['resource']['metadata'] assert trace_metadata.get('labels') is not None assert json.loads(trace_metadata['labels']) == { 'test_label': 'test_value', 'test_label_2': 42, 'test_label_3': 42.2, 'test_label_4': True, }
def test_custom_labels_sanity(): event = RunnerEventMock() trace = trace_factory.get_or_create_trace() trace.clear_events() trace.set_runner(event) trace.add_label('test_label', 'test_value') trace.add_label('test_label_2', 42) trace.add_label('test_label_3', 42.2) trace.add_label('test_label_invalid', {}) trace_metadata = trace.to_dict()['events'][0]['resource']['metadata'] assert trace_metadata.get('labels') is not None assert json.loads(trace_metadata['labels']) == { 'test_label': 'test_value', 'test_label_2': '42', 'test_label_3': '42.2', }