From 198e0209b7f00b0f221597bb4f7a2ae85dce109b Mon Sep 17 00:00:00 2001 From: Fiete Ostkamp Date: Sun, 8 Feb 2026 11:27:11 +0100 Subject: [PATCH] Override otel error tags for expected 404 Not Found responses Issue-ID: INT-2347 Change-Id: Ic19e9f5000599731e2f543616c174e806689a03c Signed-off-by: Fiete Ostkamp --- src/onaptests/steps/cloud/cloud_region_create.py | 6 ++++-- src/onaptests/utils/tracing.py | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/onaptests/utils/tracing.py diff --git a/src/onaptests/steps/cloud/cloud_region_create.py b/src/onaptests/steps/cloud/cloud_region_create.py index afed216..1c92a05 100644 --- a/src/onaptests/steps/cloud/cloud_region_create.py +++ b/src/onaptests/steps/cloud/cloud_region_create.py @@ -1,8 +1,10 @@ """A&AI cloud region creation module.""" + from onapsdk.aai.cloud_infrastructure import CloudRegion from onapsdk.configuration import settings from onapsdk.exceptions import ResourceNotFound +from ...utils.tracing import otel_expect_not_found from ..base import BaseStep @@ -44,6 +46,7 @@ class CloudRegionCreateStep(BaseStep): cloud_region_id=settings.CLOUD_REGION_ID, ) except ResourceNotFound: + otel_expect_not_found() CloudRegion.create( cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER, cloud_region_id=settings.CLOUD_REGION_ID, @@ -52,12 +55,11 @@ class CloudRegionCreateStep(BaseStep): cloud_type=settings.CLOUD_REGION_TYPE, cloud_region_version=settings.CLOUD_REGION_VERSION, owner_defined_type=settings.CLOUD_OWNER_DEFINED_TYPE, - complex_name=settings.COMPLEX_PHYSICAL_LOCATION_ID + complex_name=settings.COMPLEX_PHYSICAL_LOCATION_ID, ) @BaseStep.store_state(cleanup=True) def cleanup(self) -> None: - """Cleanup created cloud region.""" self._logger.info("Clean the cloud region") try: diff --git a/src/onaptests/utils/tracing.py b/src/onaptests/utils/tracing.py new file mode 100644 index 0000000..54c8c9a --- /dev/null +++ b/src/onaptests/utils/tracing.py @@ -0,0 +1,24 @@ +"""OpenTelemetry tracing utilities.""" + +from opentelemetry import trace + + +def otel_expect_not_found() -> None: + """Mark the current span to indicate that a 404/ResourceNotFound is expected. + + This prevents OpenTelemetry from automatically marking the span as an error + when a ResourceNotFound exception (404 HTTP status) occurs in contexts where + this is the expected behavior (e.g., checking if a resource exists before creating it). + + Example: + try: + resource = SomeResource.get_by_id(resource_id) + except ResourceNotFound: + expect_not_found() + # Create the resource since it doesn't exist + resource = SomeResource.create(...) + """ + current_span = trace.get_current_span() + if current_span and current_span.is_recording(): + current_span.set_attribute("error", False) + current_span.set_attribute("expected_404", True) -- 2.16.6