Skip to content

Commit 683f6e1

Browse files
authored
Gracefull shutdown for OTEL tracer. (#1506)
1 parent ac5dd12 commit 683f6e1

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

custom_model_runner/datarobot_drum/drum/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def setup_tracer(runtime_parameters, options):
150150
command argumetns
151151
Returns
152152
-------
153-
None
153+
TracerProvider
154154
"""
155155
log = get_drum_logger("setup_tracer")
156156

@@ -186,6 +186,7 @@ def setup_tracer(runtime_parameters, options):
186186

187187
endpoint = main_endpoint or trace_endpoint
188188
log.info(f"Tracing is configured with endpoint: {endpoint}")
189+
return provider
189190

190191

191192
@contextmanager

custom_model_runner/datarobot_drum/drum/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ def signal_handler(sig, frame):
6868
if runtime.options and RunMode(runtime.options.subparser_name) == RunMode.SERVER:
6969
if runtime.cm_runner:
7070
runtime.cm_runner.terminate()
71+
# Let traceer offload accumulated spans before shutdown.
72+
if runtime.trace_provider is not None:
73+
runtime.trace_provider.shutdown()
7174

7275
os._exit(130)
7376

@@ -95,7 +98,8 @@ def signal_handler(sig, frame):
9598
options.max_workers = RuntimeParameters.get("CUSTOM_MODEL_WORKERS")
9699
runtime.options = options
97100

98-
setup_tracer(RuntimeParameters, options)
101+
runtime.trace_provider = setup_tracer(RuntimeParameters, options)
102+
99103
signal.signal(signal.SIGINT, signal_handler)
100104
signal.signal(signal.SIGTERM, signal_handler)
101105

custom_model_runner/datarobot_drum/drum/runtime.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(self):
3030
self.initialization_succeeded = False
3131
self.options = None
3232
self.cm_runner = None
33+
self.trace_provider = None
3334

3435
def __enter__(self):
3536
return self

0 commit comments

Comments
 (0)