def test_ignore_active_span(self): """Test Ignore Active Span.""" tracer = WavefrontTracer(ConsoleReporter(), self.application_tags) scope = tracer.start_active_span('test_op') active_span = scope.span # Span created with ignore_active_span=False by default. child_span = tracer.start_span( operation_name='child_op', ignore_active_span=False) active_trace_id = str(active_span.trace_id) child_trace_id = str(child_span.trace_id) self.assertEqual(active_trace_id, child_trace_id) child_span.finish() # Span created with ignore_active_span=True. child_span = tracer.start_span( operation_name='child_op', ignore_active_span=True) child_trace_id = str(child_span.trace_id) self.assertNotEqual(active_trace_id, child_trace_id) child_span.finish() scope.close() tracer.close()
def test_tags_with_components_defined(self): """Test Multi-valued Tags.""" tracer = WavefrontTracer(ConsoleReporter(), self.application_tags) span = tracer.start_span('test_op', tags={'component': 'my_component'}) self.assertIsNotNone(span) self.assertIsNotNone(span.get_tags()) self.assertIsNotNone(span.get_tags_as_list()) self.assertIsNotNone(span.get_tags_as_map()) self.assertEqual(6, len(span.get_tags_as_map())) self.assertEqual(['my_component'], span.get_tags_as_map().get('component')) span.finish() tracer.close()
def test_tags_as_dict(self): """Test Multi-valued Tags.""" tracer = WavefrontTracer(ConsoleReporter(), self.application_tags) span = tracer.start_span('test_op', tags={ 'key1': 'val1', 'application': 'new_app'}) self.assertIsNotNone(span) self.assertIsNotNone(span.get_tags()) self.assertIsNotNone(span.get_tags_as_list()) self.assertIsNotNone(span.get_tags_as_map()) self.assertEqual(7, len(span.get_tags_as_map())) self.assertTrue('new_app' in span.get_tags_as_map().get('application')) self.assertTrue('service' in span.get_tags_as_map().get('service')) self.assertTrue('us-west-1' in span.get_tags_as_map().get('cluster')) self.assertTrue('primary' in span.get_tags_as_map().get('shard')) self.assertTrue('custom_v' in span.get_tags_as_map().get('custom_k')) self.assertTrue('val1' in span.get_tags_as_map().get('key1')) span.finish() tracer.close()
def test_multi_valued_tags(self): """Test Multi-valued Tags.""" tracer = WavefrontTracer(ConsoleReporter(), self.application_tags) span = tracer.start_span("test_op", tags=[("key1", "val1"), ("key1", "val2")]) self.assertIsNotNone(span) self.assertIsNotNone(span.get_tags()) self.assertIsNotNone(span.get_tags_as_list()) self.assertIsNotNone(span.get_tags_as_map()) self.assertEqual(6, len(span.get_tags_as_map())) self.assertTrue("app" in span.get_tags_as_map().get("application")) self.assertTrue("service" in span.get_tags_as_map().get("service")) self.assertTrue("us-west-1" in span.get_tags_as_map().get("cluster")) self.assertTrue("primary" in span.get_tags_as_map().get("shard")) self.assertTrue("custom_v" in span.get_tags_as_map().get("custom_k")) self.assertTrue("val1" in span.get_tags_as_map().get("key1")) self.assertTrue("val2" in span.get_tags_as_map().get("key1")) span.finish() tracer.close()
def test_global_multi_valued_tags(self): """Test Global Multi-valued Tags.""" global_tags = [('key1', 'val1'), ('key1', 'val2')] tracer = WavefrontTracer(ConsoleReporter(), self.application_tags, global_tags) span = tracer.start_span(operation_name='test_op') self.assertIsNotNone(span) self.assertIsNotNone(span.get_tags()) self.assertIsNotNone(span.get_tags_as_list()) self.assertIsNotNone(span.get_tags_as_map()) self.assertEqual(7, len(span.get_tags_as_map())) self.assertTrue('app' in span.get_tags_as_map().get('application')) self.assertTrue('service' in span.get_tags_as_map().get('service')) self.assertTrue('us-west-1' in span.get_tags_as_map().get('cluster')) self.assertTrue('primary' in span.get_tags_as_map().get('shard')) self.assertTrue('custom_v' in span.get_tags_as_map().get('custom_k')) self.assertTrue('val1' in span.get_tags_as_map().get('key1')) self.assertTrue('val2' in span.get_tags_as_map().get('key1')) span.finish() tracer.close()
def test_error_span_duration_histogram(self, wf_sender): """Test duration histogram generated from error span.""" operation_name = 'dummy_op' source = 'wavefront_source' wf_sender = wf_sender() tracer = WavefrontTracer(WavefrontSpanReporter(wf_sender, source), self.application_tags, report_frequency_millis=500) with freezegun.freeze_time(datetime.datetime( year=1, month=1, day=1)) as frozen_datetime: span = tracer.start_active_span(operation_name=operation_name, tags=[('tenant', 'tenant1'), ('env', 'staging')]) span.span.set_tag(opentracing.ext.tags.ERROR, True) span.close() frozen_datetime.tick(delta=datetime.timedelta(seconds=61)) time.sleep(1) tracer.close() wf_sender.assert_has_calls([ mock.call.send_distribution( centroids=mock.ANY, histogram_granularities={'!M'}, name='tracing.derived.app.service.{}.duration.' 'micros'.format(operation_name), source=source, tags={ 'application': 'app', 'service': 'service', 'cluster': 'us-west-1', 'shard': 'primary', 'error': 'true', 'custom_k': 'custom_v', 'component': 'none', 'operationName': operation_name, 'span.kind': NULL_TAG_VAL }, timestamp=mock.ANY) ], any_order=True)
def test_global_tags(self): """Test Global Tags.""" global_tags = [('foo1', 'bar1'), ('foo2', 'bar2')] tracer = WavefrontTracer(ConsoleReporter(), self.application_tags, global_tags) span = tracer.start_span(operation_name='test_op', tags=[('foo3', 'bar3')]) self.assertIsNotNone(span) self.assertIsNotNone(span.get_tags()) self.assertIsNotNone(span.get_tags_as_list()) self.assertIsNotNone(span.get_tags_as_map()) self.assertEqual(9, len(span.get_tags())) self.assertTrue('app' in span.get_tags_as_map().get('application')) self.assertTrue('service' in span.get_tags_as_map().get('service')) self.assertTrue('us-west-1' in span.get_tags_as_map().get('cluster')) self.assertTrue('primary' in span.get_tags_as_map().get('shard')) self.assertTrue('custom_v' in span.get_tags_as_map().get('custom_k')) self.assertTrue('bar1' in span.get_tags_as_map().get('foo1')) self.assertTrue('bar2' in span.get_tags_as_map().get('foo2')) self.assertTrue('bar3' in span.get_tags_as_map().get('foo3')) span.finish() tracer.close()
def test_global_tags(self): """Test Global Tags.""" global_tags = [("foo1", "bar1"), ("foo2", "bar2")] tracer = WavefrontTracer(ConsoleReporter(), self.application_tags, global_tags) span = tracer.start_span(operation_name="test_op", tags=[("foo3", "bar3")]) self.assertIsNotNone(span) self.assertIsNotNone(span.get_tags()) self.assertIsNotNone(span.get_tags_as_list()) self.assertIsNotNone(span.get_tags_as_map()) self.assertEqual(8, len(span.get_tags())) self.assertTrue("app" in span.get_tags_as_map().get("application")) self.assertTrue("service" in span.get_tags_as_map().get("service")) self.assertTrue("us-west-1" in span.get_tags_as_map().get("cluster")) self.assertTrue("primary" in span.get_tags_as_map().get("shard")) self.assertTrue("custom_v" in span.get_tags_as_map().get("custom_k")) self.assertTrue("bar1" in span.get_tags_as_map().get("foo1")) self.assertTrue("bar2" in span.get_tags_as_map().get("foo2")) self.assertTrue("bar3" in span.get_tags_as_map().get("foo3")) span.finish() tracer.close()
span3 = tracer.start_span( operation_name='Google API calls', #child_of=span1, tags=global_tags) time.sleep(timeDelta) # en sec, accepte des floats span3.finish() # Create span4 span4 = tracer.start_span( operation_name='DBupdate', #child_of=span1, tags=global_tags) time.sleep(getRandomNumber()) span4.finish() # Create span5 span5 = tracer.start_span( operation_name='Rendering', #child_of=span1, tags=global_tags) time.sleep(getRandomNumber()) span5.finish() scope.close() # Close the tracer tracer.close()
def test_custom_red_metrics_tags(self, wf_sender): """Test custom RED metrics tags.""" operation_name = 'dummy_op' source = 'wavefront_source' wf_sender = wf_sender() tracer = WavefrontTracer(WavefrontSpanReporter(wf_sender, source), self.application_tags, samplers=[ConstantSampler(True)], report_frequency_millis=500, red_metrics_custom_tag_keys={'env', 'tenant'}) with freezegun.freeze_time(datetime.datetime( year=1, month=1, day=1)) as frozen_datetime: span = tracer.start_active_span(operation_name=operation_name, tags=[('tenant', 'tenant1'), ('env', 'staging')]) span.close() frozen_datetime.tick(delta=datetime.timedelta(seconds=61)) time.sleep(1) tracer.close() wf_sender.assert_has_calls([ mock.call.send_span(operation_name, mock.ANY, 0, source, mock.ANY, mock.ANY, [], [], [('tenant', 'tenant1'), ('env', 'staging'), ('application', 'app'), ('service', 'service'), ('cluster', 'us-west-1'), ('shard', 'primary'), ('custom_k', 'custom_v'), ('component', 'none')], span_logs=[]), mock.call.send_metric( name='tracing.derived.app.service.{}.invocation.' 'count'.format(operation_name), source=source, tags={ 'application': 'app', 'service': 'service', 'cluster': 'us-west-1', 'shard': 'primary', 'component': 'none', 'custom_k': 'custom_v', 'operationName': operation_name, 'tenant': 'tenant1', 'env': 'staging', 'span.kind': NULL_TAG_VAL }, timestamp=None, value=1), mock.call.send_metric( name='tracing.derived.app.service.{}.total_time.millis.' 'count'.format(operation_name), source=source, tags={ 'application': 'app', 'service': 'service', 'cluster': 'us-west-1', 'shard': 'primary', 'component': 'none', 'custom_k': 'custom_v', 'operationName': 'dummy_op', 'tenant': 'tenant1', 'env': 'staging', 'span.kind': NULL_TAG_VAL }, timestamp=None, value=mock.ANY), mock.call.send_metric( '~component.heartbeat', 1.0, mock.ANY, source, { 'application': 'app', 'cluster': 'us-west-1', 'service': 'service', 'shard': 'primary', 'custom_k': 'custom_v', 'component': 'wavefront-generated' }), mock.call.send_distribution( centroids=mock.ANY, histogram_granularities={'!M'}, name='tracing.derived.app.service.{}.duration.' 'micros'.format(operation_name), source=source, tags={ 'application': 'app', 'service': 'service', 'cluster': 'us-west-1', 'shard': 'primary', 'component': 'none', 'custom_k': 'custom_v', 'operationName': operation_name, 'tenant': 'tenant1', 'env': 'staging', 'span.kind': NULL_TAG_VAL }, timestamp=mock.ANY) ], any_order=True)