Skip to content

Commit 71975c9

Browse files
committed
fix python 3.12 threading issue in the tests by cleaning up otel components in _reset_mocks
1 parent 82a6fc9 commit 71975c9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/patches/test_instrumentation_patch.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,19 @@ def _reset_mocks(self):
960960
for method_patch in self.method_patches.values():
961961
method_patch.reset_mock()
962962

963+
# Clean up OpenTelemetry components
964+
try:
965+
from opentelemetry import metrics
966+
from opentelemetry.sdk.metrics import MeterProvider
967+
968+
# Force shutdown of any active metric readers
969+
meter_provider = metrics.get_meter_provider()
970+
if hasattr(meter_provider, "shutdown") and isinstance(meter_provider, MeterProvider):
971+
meter_provider.shutdown()
972+
except Exception:
973+
# Ignore cleanup errors
974+
pass
975+
963976

964977
def _do_extract_kinesis_attributes() -> Dict[str, str]:
965978
service_name: str = "kinesis"

0 commit comments

Comments
 (0)