code: def _apply_tracing(self, handler, attributes):
          
          operation_name = self._get_operation_name(handler)
          headers = handler.request.headers
          request = handler.request
  
          # start new span from trace info
          try:
              span_ctx = self._tracer.extract(opentracing.Format.HTTP_HEADERS,
                                              headers)
              scope = self._tracer.start_active_span(operation_name,
                                                     child_of=span_ctx)
          except (opentracing.InvalidCarrierException,
                  opentracing.SpanContextCorruptedException):
              scope = self._tracer.start_active_span(operation_name)
  
          # add span to current spans
          setattr(request, SCOPE_ATTR, scope)
  
          # log any traced attributes
          scope.span.set_tag(tags.COMPONENT, 'tornado')
          scope.span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_SERVER)
          scope.span.set_tag(tags.HTTP_METHOD, request.method)
          scope.span.set_tag(tags.HTTP_URL, request.uri)
  
          for attr in attributes:
              if hasattr(request, attr):
                  payload = str(getattr(request, attr))
                  if payload:
                      scope.span.set_tag(attr, payload)
  
          # invoke the start span callback, if any
          self._call_start_span_cb(scope.span, request)
  
          return scope
docs: Helper function to avoid rewriting for middleware and decorator.
          Returns a new span from the request with logged attributes and
          correct operation name from the func.