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_active_span(self): """Test Active Span.""" tracer = WavefrontTracer(ConsoleReporter(), self.application_tags) span = tracer.start_span('test_op_1') self.assertIsNotNone(span) span.finish() scope = tracer.start_active_span('test_op_2', finish_on_close=True) self.assertIsNotNone(scope) self.assertIsNotNone(scope.span) scope.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)
tracing_port=30000) proxy_reporter = WavefrontSpanReporter(client=proxy_client, source=myhost) # CompositeReporter takes a list of other reporters and invokes them one by one # Use ConsoleReporter to output span data to console #composite_reporter = CompositeReporter(proxy_reporter, ConsoleReporter()) #composite_reporter = CompositeReporter(ConsoleReporter()) composite_reporter = CompositeReporter(proxy_reporter) tracer = WavefrontTracer(reporter=composite_reporter, application_tags=application_tag) # Create span1, return a newly started and activated Scope. scope = tracer.start_active_span(operation_name='journeyRequest', tags=global_tags, ignore_active_span=True, finish_on_close=True) span1 = scope.span time.sleep(getRandomNumber()) span1.finish() # Create span2, child of span1 span2 = tracer.start_span( operation_name='ParseRequest', #references=opentracing.child_of(span1.context), tags=global_tags) # waiting for timeDelta in order to reproduce the Google API call duration time.sleep(getRandomNumber()) span2.finish()
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)
proxy_reporter = WavefrontSpanReporter(client=proxy_client, source=myhost) # CompositeReporter takes a list of other reporters and invokes them one by one # Use ConsoleReporter to output span data to console #composite_reporter = CompositeReporter(proxy_reporter, ConsoleReporter()) #composite_reporter = CompositeReporter(ConsoleReporter()) composite_reporter = CompositeReporter(proxy_reporter) tracer = WavefrontTracer(reporter=composite_reporter, application_tags=application_tag) # Create span1, return a newly started and activated Scope. global_tags = [('Showroom', 'France')] scope = tracer.start_active_span(operation_name='Google API calls', tags=global_tags, ignore_active_span=True, finish_on_close=True) span1 = scope.span # waiting for timeDelta in order to reproduce the Google API call duration time.sleep(timeDelta) # en sec, accepte des floats # Create span2, child of span1 span2 = tracer.start_span(operation_name='Ingest data', references=opentracing.child_of(span1.context), tags=global_tags) span2.log_kv({'foo': 'bar'}) # Create span3, child of span1 span3 = tracer.start_span(operation_name='Analyze', child_of=span1,
metrics_port=2878) proxy_reporter = WavefrontSpanReporter(proxy_client) # Create Composite reporter. # Use ConsoleReporter to output span data to console. composite_reporter = CompositeReporter(proxy_reporter, direct_reporter, ConsoleReporter()) # Create Tracer with Composite Reporter. tracer = WavefrontTracer(reporter=composite_reporter) global_tags = [("global_key", "global_val")] # Create span1, return a newly started and activated Scope. scope = tracer.start_active_span(operation_name="span1", tags=global_tags, ignore_active_span=True, finish_on_close=True) span1 = scope.span time.sleep(1) # Create span2, span3 child of span1. span2 = tracer.start_span(operation_name="span2", references=child_of(span1.context), tags=[("span2_key", "span2_val")]) span3 = tracer.start_span(operation_name="span3", child_of=span1, tags=[("span3_key", "span3_val")]) time.sleep(2) span2.finish() time.sleep(1) span3.finish()