mirror of
https://git.linux-kernel.at/oliver/ivatar.git
synced 2025-11-16 04:58:01 +00:00
Fix OpenTelemetry disabled test for CI environment
- Fix test_opentelemetry_disabled_by_default to handle CI environment correctly - When OTEL_ENABLED=true in CI, test that OpenTelemetry is actually enabled - When testing default disabled behavior, reset global config singleton - This ensures the test works in both OTel-enabled and OTel-disabled CI jobs
This commit is contained in:
@@ -469,24 +469,30 @@ class OpenTelemetryDisabledTest(TestCase):
|
|||||||
|
|
||||||
def test_opentelemetry_disabled_by_default(self):
|
def test_opentelemetry_disabled_by_default(self):
|
||||||
"""Test that OpenTelemetry is disabled by default."""
|
"""Test that OpenTelemetry is disabled by default."""
|
||||||
# Clear environment variables to test default behavior
|
# In CI environment, OpenTelemetry might be enabled by CI config
|
||||||
original_env = os.environ.copy()
|
# So we test that the function respects the environment variables
|
||||||
os.environ.pop("ENABLE_OPENTELEMETRY", None)
|
if "OTEL_ENABLED" in os.environ and os.environ["OTEL_ENABLED"] == "true":
|
||||||
os.environ.pop("OTEL_ENABLED", None)
|
# In CI with OpenTelemetry enabled, test that it's actually enabled
|
||||||
|
self.assertTrue(is_enabled())
|
||||||
|
else:
|
||||||
|
# Test default disabled behavior by clearing environment variables
|
||||||
|
original_env = os.environ.copy()
|
||||||
|
os.environ.pop("ENABLE_OPENTELEMETRY", None)
|
||||||
|
os.environ.pop("OTEL_ENABLED", None)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Reset the global config to pick up the cleared environment
|
||||||
|
from ivatar.opentelemetry_config import _ot_config
|
||||||
|
|
||||||
|
global _ot_config
|
||||||
|
_ot_config = None
|
||||||
|
|
||||||
try:
|
|
||||||
# In CI environment, OpenTelemetry might be enabled by CI config
|
|
||||||
# So we test that the function respects the environment variables
|
|
||||||
if (
|
|
||||||
"OTEL_ENABLED" in original_env
|
|
||||||
and original_env["OTEL_ENABLED"] == "true"
|
|
||||||
):
|
|
||||||
self.assertTrue(is_enabled())
|
|
||||||
else:
|
|
||||||
self.assertFalse(is_enabled())
|
self.assertFalse(is_enabled())
|
||||||
finally:
|
finally:
|
||||||
os.environ.clear()
|
os.environ.clear()
|
||||||
os.environ.update(original_env)
|
os.environ.update(original_env)
|
||||||
|
# Reset the global config back to original state
|
||||||
|
_ot_config = None
|
||||||
|
|
||||||
def test_no_op_decorators_work(self):
|
def test_no_op_decorators_work(self):
|
||||||
"""Test that no-op decorators work when OpenTelemetry is disabled."""
|
"""Test that no-op decorators work when OpenTelemetry is disabled."""
|
||||||
|
|||||||
Reference in New Issue
Block a user