@@ -57,7 +57,7 @@ def configure(self, sampling=None, plugins=None,
5757 context_missing = None , sampling_rules = None ,
5858 daemon_address = None , service = None ,
5959 context = None , emitter = None ,
60- dynamic_naming = None ):
60+ dynamic_naming = None , streaming_threshold = None ):
6161 """Configure global X-Ray recorder.
6262
6363 Configure needs to run before patching thrid party libraries
@@ -90,6 +90,9 @@ def configure(self, sampling=None, plugins=None,
9090 :param dynamic_naming: a string that defines a pattern that host names
9191 should match. Alternatively you can pass a module which
9292 overrides ``DefaultDynamicNaming`` module.
93+ :param streaming_threshold: If breaks within a single segment it will
94+ start streaming out children subsegments. By default it is the
95+ maximum number of subsegments within a segment.
9396
9497 Environment variables AWS_XRAY_DAEMON_ADDRESS, AWS_XRAY_CONTEXT_MISSING
9598 and AWS_XRAY_TRACING_NAME respectively overrides arguments
@@ -111,6 +114,8 @@ def configure(self, sampling=None, plugins=None,
111114 self .context .context_missing = os .getenv (CONTEXT_MISSING_KEY , context_missing )
112115 if dynamic_naming :
113116 self .dynamic_naming = dynamic_naming
117+ if streaming_threshold :
118+ self .streaming_threshold = streaming_threshold
114119
115120 plugin_modules = None
116121 if plugins :
@@ -259,7 +264,7 @@ def stream_subsegments(self):
259264 if not segment or not segment .sampled :
260265 return
261266
262- if segment .get_total_subsegments_size () <= self ._max_subsegments :
267+ if segment .get_total_subsegments_size () <= self .streaming_threshold :
263268 return
264269
265270 # find all subsegments that has no open child subsegments and
@@ -326,6 +331,10 @@ def record_subsegment(self, wrapped, instance, args, kwargs, name,
326331 stack = traceback .extract_stack (limit = self ._max_trace_back )
327332 raise
328333 finally :
334+ # No-op if subsegment is `None` due to `LOG_ERROR`.
335+ if subsegment is None :
336+ return
337+
329338 end_time = time .time ()
330339 if callable (meta_processor ):
331340 meta_processor (
@@ -440,3 +449,11 @@ def emitter(self):
440449 @emitter .setter
441450 def emitter (self , value ):
442451 self ._emitter = value
452+
453+ @property
454+ def streaming_threshold (self ):
455+ return self ._max_subsegments
456+
457+ @streaming_threshold .setter
458+ def streaming_threshold (self , value ):
459+ self ._max_subsegments = value
0 commit comments