"""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
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,
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:
--- /dev/null
+"""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)