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_baggage_items(self): """Test Baggage Items.""" # Create parentCtx with baggage items tracer = WavefrontTracer(ConsoleReporter(), self.application_tags) baggage_item = {'foo': 'bar', 'user': '******'} parent_ctx = WavefrontSpanContext(trace_id=uuid.uuid1(), span_id=uuid.uuid1(), baggage=baggage_item, decision=True) span = tracer.start_span('test_op', child_of=parent_ctx) self.assertEqual('bar', span.get_baggage_item('foo')) self.assertEqual('name', span.get_baggage_item('user')) # Parent and Follows baggage_item = {'tracer': 'id', 'db.name': 'name'} follows_ctx = WavefrontSpanContext(trace_id=uuid.uuid1(), span_id=uuid.uuid1(), baggage=baggage_item, decision=True) span = tracer.start_span('test_op', references=[ opentracing.child_of(parent_ctx), opentracing.child_of(follows_ctx) ]) self.assertEqual('bar', span.get_baggage_item('foo')) self.assertEqual('name', span.get_baggage_item('user')) self.assertEqual('id', span.get_baggage_item('tracer')) self.assertEqual('name', span.get_baggage_item('db.name')) # Validate root span span = tracer.start_span('test_op') self.assertIsNotNone(span.context.baggage) self.assertTrue(not bool(span.context.baggage))
def test_forced_sampling(self): """Test span with forced sampling.""" tracer = WavefrontTracer(ConsoleReporter(), self.application_tags, samplers=[ConstantSampler(False)]) span = tracer.start_span('test_op') self.assertIsNotNone(span) self.assertIsNotNone(span.context) self.assertIsNotNone(span.context.get_sampling_decision()) self.assertFalse(span.context.get_sampling_decision()) span.set_tag(opentracing.ext.tags.SAMPLING_PRIORITY, 1) self.assertIsNotNone(span.context.get_sampling_decision()) self.assertTrue(span.context.get_sampling_decision()) span = tracer.start_span('test_op') self.assertIsNotNone(span) self.assertIsNotNone(span.context) self.assertIsNotNone(span.context.get_sampling_decision()) self.assertFalse(span.context.get_sampling_decision()) span.set_tag(opentracing.ext.tags.ERROR, True) self.assertIsNotNone(span.context.get_sampling_decision()) self.assertTrue(span.context.get_sampling_decision()) span = tracer.start_span('test_op') self.assertIsNotNone(span) self.assertIsNotNone(span.context) self.assertIsNotNone(span.context.get_sampling_decision()) self.assertFalse(span.context.get_sampling_decision()) span.set_tag("debug", True) self.assertIsNotNone(span.context.get_sampling_decision()) self.assertTrue(span.context.get_sampling_decision()) span = tracer.start_span('test_op') self.assertIsNotNone(span) self.assertIsNotNone(span.context) self.assertIsNotNone(span.context.get_sampling_decision()) self.assertFalse(span.context.get_sampling_decision()) span.set_tag("debug", "true") self.assertIsNotNone(span.context.get_sampling_decision()) self.assertTrue(span.context.get_sampling_decision())
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_root_sampling(self): """Test root span with sampling.""" tracer = WavefrontTracer(ConsoleReporter(), self.application_tags, samplers=[ConstantSampler(False)]) span = tracer.start_span('test_op') self.assertIsNotNone(span) self.assertIsNotNone(span.context) self.assertEqual(0, len(span.get_parents())) self.assertEqual(0, len(span.get_follows())) self.assertIsNotNone(span.context.get_sampling_decision()) self.assertFalse(span.context.get_sampling_decision()) tracer = WavefrontTracer(ConsoleReporter(), self.application_tags, samplers=[ConstantSampler(True)]) span = tracer.start_span('test_op') self.assertIsNotNone(span) self.assertIsNotNone(span.context) self.assertEqual(0, len(span.get_parents())) self.assertEqual(0, len(span.get_follows())) self.assertIsNotNone(span.context.get_sampling_decision()) self.assertTrue(span.context.get_sampling_decision())
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_inject_extract(self): """Test Inject / Extract.""" tracer = WavefrontTracer(ConsoleReporter(), self.application_tags) span = tracer.start_span('test_op') self.assertIsNotNone(span) span.set_baggage_item("customer", "test_customer") span.set_baggage_item("request_type", "mobile") carrier = {} tracer.inject(span.context, Format.TEXT_MAP, carrier) span.finish() ctx = tracer.extract(Format.TEXT_MAP, carrier) self.assertEqual("test_customer", ctx.get_baggage_item("customer")) self.assertEqual("mobile", ctx.get_baggage_item("request_type"))
def test_negative_child_sampling(self): """Test child span with positive sampling.""" tracer = WavefrontTracer(ConsoleReporter(), self.application_tags, samplers=[ConstantSampler(True)]) parent_ctx = WavefrontSpanContext(trace_id=uuid.uuid1(), span_id=uuid.uuid1(), decision=False) span = tracer.start_span('test_op', child_of=parent_ctx) self.assertTrue(tracer.sample(span.operation_name, span.trace_id, 0)) self.assertIsNotNone(span) self.assertEqual(parent_ctx.trace_id, span.trace_id) self.assertTrue(span.context.is_sampled()) self.assertIsNotNone(span.context.get_sampling_decision()) self.assertFalse(span.context.get_sampling_decision())
def test_inject_extract(self): """Test Inject / Extract.""" tracer = WavefrontTracer(ConsoleReporter(), self.application_tags, samplers=[ConstantSampler(True)]) span = tracer.start_span('test_op') self.assertIsNotNone(span) span.set_baggage_item('customer', 'test_customer') span.set_baggage_item('request_type', 'mobile') carrier = {} tracer.inject(span.context, opentracing.propagation.Format.TEXT_MAP, carrier) span.finish() ctx = tracer.extract(opentracing.propagation.Format.TEXT_MAP, carrier) self.assertTrue(ctx.is_sampled()) self.assertTrue(ctx.get_sampling_decision()) self.assertEqual('test_customer', ctx.get_baggage_item('customer')) self.assertEqual('mobile', ctx.get_baggage_item('request_type'))
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_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()
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()
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() # Create span3 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 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() # Create span4 follows from span3. span4 = tracer.start_span(operation_name="span4", references=follows_from(span3.context), tags=[("span4_key", "span4_val")]) time.sleep(2) span4.finish()
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, tags=global_tags) # get random number and sleep for that duration before finishing span2 time.sleep(getRandomNumber()) span2.finish() # get random number and sleep for that duration before finishing span3 time.sleep(getRandomNumber()) span3.finish()
tracer = WavefrontTracer(reporter=composite_reporter, application_tags=application_tag) 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(0.1) # Create span2, span3 child of span1. span2 = tracer.start_span(operation_name='span2', references=opentracing.child_of(span1.context), tags=[('span2_key', 'span2_val')]) span2.log_kv({'foo': 'bar'}) span3 = tracer.start_span(operation_name='span3', child_of=span1, tags=[('span3_key', 'span3_val')]) time.sleep(0.2) span2.finish() time.sleep(0.1) span3.finish() # Create span4 follows from span3. span4 = tracer.start_span(operation_name='span4', references=opentracing.follows_from(span3.context), tags=[('span4_key', 'span4_val')]) time.sleep(0.2)