async def test_create_task(tracer): # the helper should create a new Task that has the Context attached async def future_work(): child_span = tracer.trace("child_task") return child_span root_span = tracer.trace("main_task") # schedule future work and wait for a result task = helpers.create_task(future_work()) result = await task assert result.name == "child_task" assert root_span.trace_id == result.trace_id assert root_span.span_id == result.parent_id
async def main_page(request): redis_list = get_list(request) if request.method == "POST": statsd.increment("guestbook.post") form = await request.post() headers = { 'x-datadog-trace-id': str(tracer.current_span().trace_id), 'x-datadog-parent-id': str(tracer.current_span().span_id), } task_img = helpers.create_task(getdoggo(headers)) task_text = helpers.create_task(makelolz(form["entry"], headers)) img = await task_img text = await task_text entry = "<img src=\"{}\" /><span>{}</span>".format(img, text) app.redis.lpush(redis_list, entry) return web.HTTPFound("/") else: statsd.increment("guestbook.view") entries = app.redis.lrange(redis_list, 0, -1) return {"entries": entries}
def test_create_task(self): # the helper should create a new Task that has the Context attached @asyncio.coroutine def future_work(): # the ctx is available in this task ctx = self.tracer.get_call_context() eq_(0, len(ctx._trace)) child_span = self.tracer.trace('child_task') return child_span root_span = self.tracer.trace('main_task') # schedule future work and wait for a result task = helpers.create_task(future_work()) result = yield from task eq_(root_span.trace_id, result.trace_id) eq_(root_span.span_id, result.parent_id)
def test_create_task(self): # the helper should create a new Task that has the Context attached @asyncio.coroutine def future_work(): # the ctx is available in this task ctx = self.tracer.get_call_context() eq_(0, len(ctx._trace)) child_span = self.tracer.trace('child_task') return child_span root_span = self.tracer.trace('main_task') # schedule future work and wait for a result task = helpers.create_task(future_work()) result = yield from task eq_(root_span.trace_id, result.trace_id) eq_(root_span.span_id, result.parent_id)