diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dd15d78ba..c37749522 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -151,6 +151,7 @@ jobs: LOGGING_EXPORT_FORMAT: ${{ vars.LOGGING_EXPORT_FORMAT }} TRACING_SERVICE_NAME: ${{ vars.TRACING_SERVICE_NAME }} LOGGING_SERVICE_NAME: ${{ vars.LOGGING_SERVICE_NAME }} + SERVICE_INSTANCE_ID: ${{ github.head_ref || github.ref_name }} run: > poetry run pytest --durations=0 --cov-append --cov-report=term --cov-report=html:htmlcov --cov-report=xml:coverage.xml --cov=schematic/ -m "not (rule_benchmark or single_process_execution)" --reruns 4 -n 8 --ignore=tests/unit diff --git a/schematic/__init__.py b/schematic/__init__.py index 718feb6a3..d3035bc61 100644 --- a/schematic/__init__.py +++ b/schematic/__init__.py @@ -10,7 +10,12 @@ from opentelemetry.instrumentation.flask import FlaskInstrumentor from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler from opentelemetry.sdk._logs.export import BatchLogRecordProcessor -from opentelemetry.sdk.resources import DEPLOYMENT_ENVIRONMENT, SERVICE_NAME, Resource +from opentelemetry.sdk.resources import ( + DEPLOYMENT_ENVIRONMENT, + SERVICE_INSTANCE_ID, + SERVICE_NAME, + Resource, +) from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor, Span from opentelemetry.sdk.trace.sampling import ALWAYS_OFF @@ -91,10 +96,12 @@ def set_up_tracing(session: requests.Session) -> None: Synapse.enable_open_telemetry(True) tracing_service_name = os.environ.get("TRACING_SERVICE_NAME", "schematic-api") deployment_environment = os.environ.get("DEPLOYMENT_ENVIRONMENT", "") + service_instance_id = os.environ.get("SERVICE_INSTANCE_ID", "") trace.set_tracer_provider( TracerProvider( resource=Resource( attributes={ + SERVICE_INSTANCE_ID: service_instance_id, SERVICE_NAME: tracing_service_name, # TODO: Revisit this portion later on. As of 11/12/2024 when # deploying this to ECS or running within a docker container, @@ -122,9 +129,11 @@ def set_up_logging(session: requests.Session) -> None: logging_export = os.environ.get("LOGGING_EXPORT_FORMAT", None) logging_service_name = os.environ.get("LOGGING_SERVICE_NAME", "schematic-api") deployment_environment = os.environ.get("DEPLOYMENT_ENVIRONMENT", "") + service_instance_id = os.environ.get("SERVICE_INSTANCE_ID", "") if logging_export == "otlp": resource = Resource.create( { + SERVICE_INSTANCE_ID: service_instance_id, SERVICE_NAME: logging_service_name, DEPLOYMENT_ENVIRONMENT: deployment_environment, } diff --git a/tests/conftest.py b/tests/conftest.py index 2f9dd3047..d373e6ae6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -13,6 +13,7 @@ from dotenv import load_dotenv from flask.testing import FlaskClient from opentelemetry import trace +from opentelemetry.instrumentation.flask import FlaskInstrumentor from synapseclient.client import Synapse from schematic.configuration.configuration import CONFIG, Configuration @@ -42,6 +43,8 @@ TESTS_DIR = os.path.dirname(os.path.abspath(__file__)) DATA_DIR = os.path.join(TESTS_DIR, "data") +FlaskInstrumentor().uninstrument() + @pytest.fixture(scope="session") def dataset_id():