20
20
import typing
21
21
from enum import Enum
22
22
23
+ from opentelemetry .configuration import Configuration
23
24
from opentelemetry .context import attach , detach , set_value
24
- from opentelemetry .sdk .trace import sampling
25
25
from opentelemetry .util import time_ns
26
26
27
27
from .. import Span , SpanProcessor
@@ -113,10 +113,30 @@ class BatchExportSpanProcessor(SpanProcessor):
113
113
def __init__ (
114
114
self ,
115
115
span_exporter : SpanExporter ,
116
- max_queue_size : int = 2048 ,
117
- schedule_delay_millis : float = 5000 ,
118
- max_export_batch_size : int = 512 ,
116
+ max_queue_size : int = None ,
117
+ schedule_delay_millis : float = None ,
118
+ max_export_batch_size : int = None ,
119
+ export_timeout_millis : float = None ,
119
120
):
121
+
122
+ if max_queue_size is None :
123
+ max_queue_size = Configuration ().get ("BSP_MAX_QUEUE_SIZE" , 2048 )
124
+
125
+ if schedule_delay_millis is None :
126
+ schedule_delay_millis = Configuration ().get (
127
+ "BSP_SCHEDULE_DELAY_MILLIS" , 5000
128
+ )
129
+
130
+ if max_export_batch_size is None :
131
+ max_export_batch_size = Configuration ().get (
132
+ "BSP_MAX_EXPORT_BATCH_SIZE" , 512
133
+ )
134
+
135
+ if export_timeout_millis is None :
136
+ export_timeout_millis = Configuration ().get (
137
+ "BSP_EXPORT_TIMEOUT_MILLIS" , 30000
138
+ )
139
+
120
140
if max_queue_size <= 0 :
121
141
raise ValueError ("max_queue_size must be a positive integer." )
122
142
@@ -143,6 +163,7 @@ def __init__(
143
163
self .schedule_delay_millis = schedule_delay_millis
144
164
self .max_export_batch_size = max_export_batch_size
145
165
self .max_queue_size = max_queue_size
166
+ self .export_timeout_millis = export_timeout_millis
146
167
self .done = False
147
168
# flag that indicates that spans are being dropped
148
169
self ._spans_dropped = False
@@ -306,7 +327,11 @@ def _drain_queue(self):
306
327
while self .queue :
307
328
self ._export_batch ()
308
329
309
- def force_flush (self , timeout_millis : int = 30000 ) -> bool :
330
+ def force_flush (self , timeout_millis : int = None ) -> bool :
331
+
332
+ if timeout_millis is None :
333
+ timeout_millis = self .export_timeout_millis
334
+
310
335
if self .done :
311
336
logger .warning ("Already shutdown, ignoring call to force_flush()." )
312
337
return True
0 commit comments