@@ -285,6 +285,7 @@ def __init__(self, application, enabled=None, source=None):
285285        self .tracestate  =  "" 
286286        self ._priority  =  None 
287287        self ._sampled  =  None 
288+         # Remote parent sampled is set from the W3C parent header or the Newrelic header if no W3C parent header is present. 
288289        self ._remote_parent_sampled  =  None 
289290
290291        self ._distributed_trace_state  =  0 
@@ -1020,18 +1021,36 @@ def sampling_algo_compute_sampled_and_priority(self, priority, sampled):
10201021                priority  +=  1 
10211022        return  priority , sampled 
10221023
1023-     def  _compute_sampled_and_priority (self , priority , sampled , remote_parent_sampled_path , remote_parent_sampled_setting , remote_parent_not_sampled_path , remote_parent_not_sampled_setting ):
1024+     def  _compute_sampled_and_priority (
1025+         self ,
1026+         priority ,
1027+         sampled ,
1028+         remote_parent_sampled_path ,
1029+         remote_parent_sampled_setting ,
1030+         remote_parent_not_sampled_path ,
1031+         remote_parent_not_sampled_setting ,
1032+     ):
10241033        if  self ._remote_parent_sampled  is  None :
10251034            config  =  "default"   # Use sampling algo. 
10261035            _logger .debug ("Sampling decision made based on no remote parent sampling decision present." )
10271036        elif  self ._remote_parent_sampled :
10281037            setting_path  =  remote_parent_sampled_path 
10291038            config  =  remote_parent_sampled_setting 
1030-             _logger .debug ("Sampling decision made based on remote_parent_sampled=%s and %s=%s." , self ._remote_parent_sampled , setting_path , config )
1039+             _logger .debug (
1040+                 "Sampling decision made based on remote_parent_sampled=%s and %s=%s." ,
1041+                 self ._remote_parent_sampled ,
1042+                 setting_path ,
1043+                 config ,
1044+             )
10311045        else :  # self._remote_parent_sampled is False. 
10321046            setting_path  =  remote_parent_not_sampled_path 
10331047            config  =  remote_parent_not_sampled_setting 
1034-             _logger .debug ("Sampling decision made based on remote_parent_sampled=%s and %s=%s." , self ._remote_parent_sampled , setting_path , config )
1048+             _logger .debug (
1049+                 "Sampling decision made based on remote_parent_sampled=%s and %s=%s." ,
1050+                 self ._remote_parent_sampled ,
1051+                 setting_path ,
1052+                 config ,
1053+             )
10351054        if  config  ==  "always_on" :
10361055            sampled  =  True 
10371056            priority  =  2.0 
@@ -1042,7 +1061,9 @@ def _compute_sampled_and_priority(self, priority, sampled, remote_parent_sampled
10421061            if  config  not  in   ("default" , "adaptive" ):
10431062                _logger .warning ("%s=%s is not a recognized value. Using 'default' instead." , setting_path , config )
10441063
1045-             _logger .debug ("Let adaptive sampler algorithm decide based on sampled=%s and priority=%s." , sampled , priority )
1064+             _logger .debug (
1065+                 "Let adaptive sampler algorithm decide based on sampled=%s and priority=%s." , sampled , priority 
1066+             )
10461067            priority , sampled  =  self .sampling_algo_compute_sampled_and_priority (priority , sampled )
10471068        return  priority , sampled 
10481069
@@ -1055,14 +1076,18 @@ def _make_sampling_decision(self):
10551076        sampled  =  self ._sampled 
10561077        # Compute sampling decision for full granularity. 
10571078        if  self .settings .distributed_tracing .sampler .full_granularity .enabled :
1058-             _logger .debug ("Full granularity tracing is enabled. Asking if full granularity wants to sample. priority=%s, sampled=%s" , priority , sampled )
1079+             _logger .debug (
1080+                 "Full granularity tracing is enabled. Asking if full granularity wants to sample. priority=%s, sampled=%s" ,
1081+                 priority ,
1082+                 sampled ,
1083+             )
10591084            computed_priority , computed_sampled  =  self ._compute_sampled_and_priority (
10601085                priority ,
10611086                sampled ,
1062-                 remote_parent_sampled_path   =   "distributed_tracing.sampler.full_granularity.remote_parent_sampled" ,
1063-                 remote_parent_sampled_setting   =   self .settings .distributed_tracing .sampler .full_granularity .remote_parent_sampled ,
1064-                 remote_parent_not_sampled_path   =   "distributed_tracing.sampler.full_granularity.remote_parent_not_sampled" ,
1065-                 remote_parent_not_sampled_setting   =   self .settings .distributed_tracing .sampler .full_granularity .remote_parent_not_sampled ,
1087+                 remote_parent_sampled_path = "distributed_tracing.sampler.full_granularity.remote_parent_sampled" ,
1088+                 remote_parent_sampled_setting = self .settings .distributed_tracing .sampler .full_granularity .remote_parent_sampled ,
1089+                 remote_parent_not_sampled_path = "distributed_tracing.sampler.full_granularity.remote_parent_not_sampled" ,
1090+                 remote_parent_not_sampled_setting = self .settings .distributed_tracing .sampler .full_granularity .remote_parent_not_sampled ,
10661091            )
10671092            _logger .debug ("Full granularity sampling decision was %s with priority=%s." , sampled , priority )
10681093            if  computed_sampled  or  not  self .settings .distributed_tracing .sampler .partial_granularity .enabled :
@@ -1077,12 +1102,14 @@ def _make_sampling_decision(self):
10771102            self ._priority , self ._sampled  =  self ._compute_sampled_and_priority (
10781103                priority ,
10791104                sampled ,
1080-                 remote_parent_sampled_path  =  "distributed_tracing.sampler.partial_granularity.remote_parent_sampled" ,
1081-                 remote_parent_sampled_setting  =  self .settings .distributed_tracing .sampler .partial_granularity .remote_parent_sampled ,
1082-                 remote_parent_not_sampled_path  =  "distributed_tracing.sampler.partial_granularity.remote_parent_not_sampled" ,
1083-                 remote_parent_not_sampled_setting  =  self .settings .distributed_tracing .sampler .partial_granularity .remote_parent_not_sampled ,
1105+                 remote_parent_sampled_path = "distributed_tracing.sampler.partial_granularity.remote_parent_sampled" ,
1106+                 remote_parent_sampled_setting = self .settings .distributed_tracing .sampler .partial_granularity .remote_parent_sampled ,
1107+                 remote_parent_not_sampled_path = "distributed_tracing.sampler.partial_granularity.remote_parent_not_sampled" ,
1108+                 remote_parent_not_sampled_setting = self .settings .distributed_tracing .sampler .partial_granularity .remote_parent_not_sampled ,
1109+             )
1110+             _logger .debug (
1111+                 "Partial granularity sampling decision was %s with priority=%s." , self ._sampled , self ._priority 
10841112            )
1085-             _logger .debug ("Partial granularity sampling decision was %s with priority=%s." , self ._sampled , self ._priority )
10861113            self ._sampling_decision_made  =  True 
10871114            if  self ._sampled :
10881115                self .partial_granularity_sampled  =  True 
0 commit comments