Skip to content

Commit 1fd2959

Browse files
authored
Simplify OTEL configuration. (#1469)
1 parent 44933a0 commit 1fd2959

File tree

2 files changed

+22
-46
lines changed

2 files changed

+22
-46
lines changed

custom_model_runner/datarobot_drum/drum/common.py

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -135,66 +135,43 @@ def make_otel_endpoint(datarobot_endpoint):
135135
return result
136136

137137

138-
def setup_tracer(runtime_parameters, options):
139-
"""Setups OTEL tracer if not configured externally.
140-
141-
It is possible to provied OTEL compliant OTEL_EXPORTER_OTLP_ENDPOINT
142-
or OTEL_EXPORTER_OTLP_TRACES_ENDPOINT and override trace collector
143-
to anydd
138+
def setup_tracer(runtime_parameters):
139+
"""Setups OTEL tracer.
144140
141+
OTEL is configured by OTEL_EXPORTER_OTLP_ENDPOINT and
142+
OTEL_EXPORTER_OTLP_HEADERS env vars set by DR.
145143
146144
Parameters
147145
----------
148146
runtime_parameters: Type[RuntimeParameters] class handles runtime parameters for custom modes
149147
used to check if OTEL configuration from user.
150-
options: argparse.Namespace: object obtained from argparser filled with user supplied
151-
command argumetns
152148
Returns
153149
-------
154150
None
155151
"""
156-
if os.environ.get("OTEL_EXPORTER_OTLP_ENDPOINT") or os.environ.get(
157-
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"
158-
):
159-
# OTEL configured externaly via env vars
160-
resource = Resource.create()
161-
else:
162-
gpu_predictor = getattr(options, "gpu_predictor", None)
163-
164-
# if explicitly asked enable/disable otel
165-
if runtime_parameters.has("OTEL_SDK_ENABLED"):
166-
enable_otel = runtime_parameters.get("OTEL_SDK_ENABLED")
167-
# if not expliciety specified, enable otel by default for gpu models
168-
elif gpu_predictor:
169-
enable_otel = True
170-
else:
171-
enable_otel = False
172-
# if deployment_id is not found, most likely this is custom model
173-
# testing
174-
deployment_id = os.environ.get("MLOPS_DEPLOYMENT_ID", os.environ.get("DEPLOYMENT_ID"))
175-
if not enable_otel or not deployment_id:
176-
return
177-
178-
resource = Resource.create(
179-
{
180-
"datarobot.deployment_id": deployment_id,
181-
}
182-
)
183-
key = os.environ.get("DATAROBOT_API_TOKEN")
184-
datarobot_endpoint = os.environ.get("DATAROBOT_ENDPOINT")
185-
if not key or not datarobot_endpoint:
186-
return
152+
log = get_drum_logger("setup_tracer")
187153

188-
endpoint = make_otel_endpoint(datarobot_endpoint)
189-
h = f"X-DataRobot-Api-Key={key},X-DataRobot-Entity-Id=deployment-{deployment_id}"
190-
os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = endpoint
191-
os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = h
154+
# Can be used to disable OTEL reporting from env var parameters
155+
# https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/
156+
if runtime_parameters.has("OTEL_SDK_DISABLED") and os.environ.get("OTEL_SDK_DISABLED"):
157+
log.info("Tracing explictly disabled")
158+
return
192159

160+
main_endpoint = os.environ.get("OTEL_EXPORTER_OTLP_ENDPOINT")
161+
trace_endpoint = os.environ.get("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT")
162+
if not main_endpoint and not trace_endpoint:
163+
log.info("Tracing is not configured")
164+
return
165+
166+
resource = Resource.create()
193167
otlp_exporter = OTLPSpanExporter()
194168
provider = TracerProvider(resource=resource)
195169
provider.add_span_processor(BatchSpanProcessor(otlp_exporter))
196170
trace.set_tracer_provider(provider)
197171

172+
endpoint = main_endpoint or trace_endpoint
173+
log.info(f"Tracing is configured with endpoint: {endpoint}")
174+
198175

199176
@contextmanager
200177
def otel_context(tracer, span_name, carrier):

custom_model_runner/datarobot_drum/drum/main.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ def signal_handler(sig, frame):
9090
options = arg_parser.parse_args()
9191
CMRunnerArgsRegistry.verify_options(options)
9292
_setup_required_environment_variables(options)
93-
# Env vars may setup OTEL configuration, lets setup
94-
# tracer after all env vars updated
9593

96-
setup_tracer(RuntimeParameters, options)
94+
setup_tracer(RuntimeParameters)
95+
9796
if RuntimeParameters.has("CUSTOM_MODEL_WORKERS"):
9897
options.max_workers = RuntimeParameters.get("CUSTOM_MODEL_WORKERS")
9998
runtime.options = options

0 commit comments

Comments
 (0)