Skip to content

Commit 7d91e10

Browse files
authored
[RAPTOR-14624] monkey patch OTEL OpenAI async only if it is installed (#1657)
* [YOLO] monkey patch OTEL OpenAI async only if it is installed * set default worker type to sync
1 parent 28d4a2b commit 7d91e10

File tree

4 files changed

+38
-26
lines changed

4 files changed

+38
-26
lines changed

custom_model_runner/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
8+
#### [1.17.1] - 2025-09-12
9+
##### Fixed
10+
- Otel OpenAI async monkey patching for gunicorn
11+
- Set default gunicorn worker type to sync
12+
713
#### [1.17.0] - 2025-09-10
814
##### Changed
915
- Integrated Gunicorn web server

custom_model_runner/datarobot_drum/drum/description.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
This is proprietary source code of DataRobot, Inc. and its affiliates.
55
Released under the terms of DataRobot Tool and Utility Agreement.
66
"""
7-
version = "1.17.0"
7+
version = "1.17.1"
88
__version__ = version
99
project_name = "datarobot-drum"

custom_model_runner/datarobot_drum/drum/gunicorn/context.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -97,31 +97,37 @@ def start(self):
9797

9898
# fix RuntimeError: asyncio.run() cannot be called from a running event loop
9999
import asyncio
100-
import opentelemetry.instrumentation.openai.utils as otel_utils
101100

102-
def fixed_run_async(method):
103-
try:
104-
loop = asyncio.get_running_loop()
105-
except RuntimeError:
106-
loop = None
107-
108-
if loop and loop.is_running():
109-
110-
def handle_task_result(task):
111-
try:
112-
task.result() # retrieve exception if any
113-
except Exception as e:
114-
# Log or handle exceptions here if needed
115-
logger.error("OpenTelemetry async task error")
116-
117-
# Schedule the coroutine safely and add done callback to handle errors
118-
task = loop.create_task(method)
119-
task.add_done_callback(handle_task_result)
120-
else:
121-
asyncio.run(method)
122-
123-
# Apply monkey patch
124-
otel_utils.run_async = fixed_run_async
101+
try:
102+
import opentelemetry.instrumentation.openai.utils as otel_utils
103+
except ImportError:
104+
otel_utils = None
105+
106+
if otel_utils:
107+
108+
def fixed_run_async(method):
109+
try:
110+
loop = asyncio.get_running_loop()
111+
except RuntimeError:
112+
loop = None
113+
114+
if loop and loop.is_running():
115+
116+
def handle_task_result(task):
117+
try:
118+
task.result() # retrieve exception if any
119+
except Exception:
120+
# Log or handle exceptions here if needed
121+
logger.error("OpenTelemetry async task error")
122+
123+
# Schedule the coroutine safely and add done callback to handle errors
124+
task = loop.create_task(method)
125+
task.add_done_callback(handle_task_result)
126+
else:
127+
asyncio.run(method)
128+
129+
# Apply monkey patch
130+
otel_utils.run_async = fixed_run_async
125131

126132
from datarobot_drum.drum.main import main
127133

custom_model_runner/datarobot_drum/drum/gunicorn/gunicorn.conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
if 1 <= temp_worker_connections <= 10000:
4545
worker_connections = temp_worker_connections
4646

47-
worker_class = "gevent"
47+
worker_class = "sync"
4848
if RuntimeParameters.has("DRUM_GUNICORN_WORKER_CLASS"):
4949
temp_worker_class = str(RuntimeParameters.get("DRUM_GUNICORN_WORKER_CLASS")).lower()
5050
if temp_worker_class in {"sync", "gevent"}:

0 commit comments

Comments
 (0)