Skip to content

Commit 494a35a

Browse files
committed
Url issues fixes
1 parent b5b0fe5 commit 494a35a

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

middleware/options.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from middleware.detectors.detector import Detector, process_detector_input
1010
from typing import Union, List
1111
from middleware.version import __version__
12+
1213
# Environment Variable Names
1314
OTEL_SERVICE_VERSION = "OTEL_SERVICE_VERSION"
1415
DEBUG = "DEBUG"
@@ -266,10 +267,20 @@ def __init__(
266267
OTEL_EXPORTER_OTLP_ENDPOINT, os.environ.get(MW_TARGET, target)
267268
)
268269

269-
if "http" not in self.target:
270-
self.mw_agent_service = os.environ.get(MW_AGENT_SERVICE, mw_agent_service)
271-
if self.mw_agent_service is not None:
272-
self.target = f"http://{self.mw_agent_service}:{DEFAULT_PORT}"
270+
if "https" not in self.target:
271+
# Special case: Kubernetes Python auto-instrumentation
272+
if os.environ.get("MW_K8S_PYTHON_INSTRUMENTATION") == "true":
273+
# Only set the service name, don't modify self.target
274+
self.mw_agent_service = os.environ.get(
275+
MW_AGENT_SERVICE, mw_agent_service
276+
)
277+
else:
278+
# Default behavior
279+
self.mw_agent_service = os.environ.get(
280+
MW_AGENT_SERVICE, mw_agent_service
281+
)
282+
if self.mw_agent_service is not None:
283+
self.target = f"http://{self.mw_agent_service}:{DEFAULT_PORT}"
273284

274285
self.custom_resource_attributes = os.environ.get(
275286
MW_CUSTOM_RESOURCE_ATTRIBUTES, custom_resource_attributes
@@ -278,7 +289,7 @@ def __init__(
278289
self.otel_propagators = os.environ.get(
279290
OTEL_PROPAGATORS, os.environ.get(MW_PROPAGATORS, otel_propagators)
280291
)
281-
os.environ["OTEL_PROPAGATORS"] = self.otel_propagators
292+
os.environ["OTEL_PROPAGATORS"] = self.otel_propagators
282293
self.console_exporter = parse_bool(MW_CONSOLE_EXPORTER, console_exporter)
283294
self.debug_log_file = parse_bool(MW_DEBUG_LOG_FILE, debug_log_file)
284295
self.project_name = os.environ.get(MW_PROJECT_NAME, project_name)
@@ -287,6 +298,7 @@ def __init__(
287298
_health_check(options=self)
288299
_get_instrument_info(options=self)
289300

301+
290302
def parse_bool(
291303
environment_variable: str, default_value: bool, error_message: str = None
292304
) -> bool:
@@ -345,8 +357,9 @@ def parse_int(
345357
else:
346358
return default_value
347359

360+
348361
def _health_check(options: MWOptions):
349-
if options.target == "" or ("https" not in options.target) :
362+
if options.target == "" or ("https" not in options.target):
350363
try:
351364
response = requests.get(
352365
f"http://{options.mw_agent_service}:13133/healthcheck", timeout=5
@@ -356,7 +369,10 @@ def _health_check(options: MWOptions):
356369
"MW Agent Health Check is failing ...\nThis could be due to incorrect value of MW_AGENT_SERVICE\nIgnore the warning if you are using MW Agent older than 1.7.7 (You can confirm by running `mw-agent version`)"
357370
)
358371
except requests.exceptions.RequestException as e:
359-
_logger.warning(f"MW Agent Health Check is failing ...\nException while MW Agent Health Check:{e}")
372+
_logger.warning(
373+
f"MW Agent Health Check is failing ...\nException while MW Agent Health Check:{e}"
374+
)
375+
360376

361377
def _get_instrument_info(options: MWOptions):
362378
_logger.debug(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "middleware-io"
7-
version = "2.4.1rc23"
7+
version = "2.4.1rc24"
88
requires-python = ">=3.8"
99
description = "Middleware's APM tool enables Python developers to effortlessly monitor their applications, gathering distributed tracing, metrics, logs, and profiling data for valuable insights and performance optimization."
1010
authors = [{ name = "middleware-dev" }]

0 commit comments

Comments
 (0)