code: def calculate_sampling_decision(trace_header, recorder, sampling_req):
      
      if trace_header.sampled is not None and trace_header.sampled != '?':
          return trace_header.sampled
      elif not recorder.sampling:
          return 1
      else:
          decision = recorder.sampler.should_trace(sampling_req)
      return decision if decision else 0
docs: Return 1 or the matched rule name if should sample and 0 if should not.
      The sampling decision coming from ``trace_header`` always has
      the highest precedence. If the ``trace_header`` doesn't contain
      sampling decision then it checks if sampling is enabled or not
      in the recorder. If not enbaled it returns 1. Otherwise it uses user
      defined sampling rules to decide.