def pytest_bdd_before_step(request, feature, scenario, step, step_func): if tracer is None: return context = tracer.get_call_context() span = tracer.start_span(step.type, resource=step.name, span_type=step.type, child_of=context,) setattr(step_func, "__dd_span__", span)
def home_page(): parent_id = int(tracer.get_call_context().get_current_root_span().trace_id) app.logger.info(parent_id) tracer.set_tags({'parent_span': parent_id}) return render_template('index.html', image_url=dog_image(), dog_fact=dog_fact() )
def dog_image(): # randomly fail somewhere in here if random.randrange(0, 10) == 9: app.logger.error('We really should fix this at some point.') abort(500, 'Huh, something randomly failed here.') dog_image = requests.get(DOG_IMAGE_SERVICE).json() image_url = dog_image.get('message') app.logger.info('Returned image: %s' % image_url) # set the breed at the root span to create a facet on breed = extract_breed(image_url) root_span = tracer.get_call_context().get_current_root_span() root_span.set_tag('breed', breed) # find out how big the image is size = requests.get(image_url, stream=True).headers['Content-length'] app.logger.info("File size of image %s" % size) # let's grade the image, maybe we should add this to a span somwhere? quality = image_quality(size) app.logger.info("Image quality is %s" % quality) # TODO: we should add the quality as a tag here # root_span.set_tag('tag_name', tag_value) return image_url
def drop(cls, span: Span): tracer.get_call_context().sampling_priority = USER_REJECT span.set_tag(cls.EAGERLY_DROP_TRACE_KEY, True)