From 2c7bde64cf802c5183207c5040b9f9bce65b19ca Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Mon, 3 Jun 2024 12:34:41 +0200 Subject: [PATCH 1/9] Add OpenTelemetry trace id to logstash entries --- Dockerfile | 2 ++ projects/etos_suite_runner/requirements.txt | 4 ++-- projects/etos_suite_runner/setup.cfg | 4 ++-- .../src/etos_suite_runner/esr.py | 14 ++++++++++---- .../src/etos_suite_runner/lib/runner.py | 5 ++++- .../src/etos_suite_runner/lib/suite.py | 19 ++++++++++++++----- 6 files changed, 34 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index ad30cd7..7d1227c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,8 @@ COPY --from=build /src/projects/etos_suite_runner/dist/*.whl /tmp # hadolint ignore=DL3013 RUN pip install --no-cache-dir /tmp/*.whl && groupadd -r etos && useradd -r -m -s /bin/false -g etos etos +RUN pip list + USER etos LABEL org.opencontainers.image.source=https://github.com/eiffel-community/etos-suite-runner diff --git a/projects/etos_suite_runner/requirements.txt b/projects/etos_suite_runner/requirements.txt index 1c02a7b..c806d2f 100644 --- a/projects/etos_suite_runner/requirements.txt +++ b/projects/etos_suite_runner/requirements.txt @@ -18,8 +18,8 @@ PyScaffold==3.2.3 packageurl-python~=0.11 cryptography>=42.0.4,<43.0.0 -etos_lib==4.2.0 -etos_environment_provider~=4.2 +etos_lib==4.3.0 +#etos_environment_provider~=4.2 opentelemetry-api~=1.21 opentelemetry-exporter-otlp~=1.21 opentelemetry-sdk~=1.21 diff --git a/projects/etos_suite_runner/setup.cfg b/projects/etos_suite_runner/setup.cfg index 8ce7775..5835000 100644 --- a/projects/etos_suite_runner/setup.cfg +++ b/projects/etos_suite_runner/setup.cfg @@ -28,8 +28,8 @@ install_requires = PyScaffold==3.2.3 packageurl-python~=0.11 cryptography>=42.0.4,<43.0.0 - etos_lib==4.2.0 - etos_environment_provider~=4.2 + etos_lib==4.3.0 + #etos_environment_provider~=4.2 opentelemetry-api~=1.21 opentelemetry-exporter-otlp~=1.21 opentelemetry-sdk~=1.21 diff --git a/projects/etos_suite_runner/src/etos_suite_runner/esr.py b/projects/etos_suite_runner/src/etos_suite_runner/esr.py index 543dd40..c15f96e 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/esr.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/esr.py @@ -29,6 +29,7 @@ from etos_lib.logging.logger import FORMAT_CONFIG from jsontas.jsontas import JsonTas import opentelemetry +from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator from .lib.esr_parameters import ESRParameters from .lib.exceptions import EnvironmentProviderException @@ -52,6 +53,7 @@ def __init__(self) -> None: """Initialize ESR by creating a rabbitmq publisher.""" self.logger = logging.getLogger("ESR") self.otel_tracer = opentelemetry.trace.get_tracer(__name__) + opentelemetry.context.attach(get_current_context()) self.etos = ETOS("ETOS Suite Runner", os.getenv("SOURCE_HOST"), "ETOS Suite Runner") signal.signal(signal.SIGTERM, self.graceful_exit) self.params = ESRParameters(self.etos) @@ -64,21 +66,23 @@ def __init__(self) -> None: int(os.getenv("ESR_WAIT_FOR_ENVIRONMENT_TIMEOUT")), ) - def _request_environment(self, ids: list[str]) -> None: + def _request_environment(self, ids: list[str], otel_context_carrier: dict) -> None: """Request an environment from the environment provider. :param ids: Generated suite runner IDs used to correlate environments and the suite runners. + :param otel_context_carrier: a dict carrying current OpenTelemetry context. """ span_name = "request_environment" - suite_context = get_current_context() + suite_context = TraceContextTextMapPropagator().extract(carrier=otel_context_carrier) + opentelemetry.context.attach(suite_context) with self.otel_tracer.start_as_current_span( span_name, context=suite_context, kind=opentelemetry.trace.SpanKind.CLIENT, ): try: - provider = EnvironmentProvider(self.params.tercc.meta.event_id, ids, copy=False) + provider = EnvironmentProvider(self.params.tercc.meta.event_id, ids) result = provider.run() except Exception as exc: self.params.set_status("FAILURE", "Failed to run environment provider") @@ -144,8 +148,10 @@ def run_suites(self, triggered: EiffelActivityTriggeredEvent) -> list[str]: self.logger.info("Number of test suites to run: %d", len(ids), extra={"user_log": True}) try: self.logger.info("Get test environment.") + carrier = {} + TraceContextTextMapPropagator().inject(carrier) threading.Thread( - target=self._request_environment, args=(ids.copy(),), daemon=True + target=self._request_environment, args=(ids.copy(), carrier,), daemon=True ).start() self.etos.events.send_activity_started(triggered, {"CONTEXT": context}) diff --git a/projects/etos_suite_runner/src/etos_suite_runner/lib/runner.py b/projects/etos_suite_runner/src/etos_suite_runner/lib/runner.py index 7624aaa..be52a72 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/lib/runner.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/lib/runner.py @@ -21,6 +21,7 @@ from etos_lib.logging.logger import FORMAT_CONFIG from jsontas.jsontas import JsonTas import opentelemetry +from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator from .exceptions import EnvironmentProviderException from .otel_tracing import get_current_context, OpenTelemetryBase @@ -70,8 +71,10 @@ def _release_environment(self): def start_suites_and_wait(self): """Get environments and start all test suites.""" try: + otel_context_carrier = {} + TraceContextTextMapPropagator().inject(otel_context_carrier) test_suites = [ - TestSuite(self.etos, self.params, suite, otel_context=self.otel_suite_context) + TestSuite(self.etos, self.params, suite, otel_context_carrier=otel_context_carrier) for suite in self.params.test_suite ] with ThreadPool() as pool: diff --git a/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py b/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py index 9a3284a..693bf42 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py @@ -28,6 +28,7 @@ from etos_lib.opentelemetry.semconv import Attributes as SemConvAttributes from jsontas.jsontas import JsonTas import opentelemetry +from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator from .esr_parameters import ESRParameters from .exceptions import EnvironmentProviderException @@ -98,17 +99,20 @@ def outcome(self) -> dict: return self.test_suite_finished.get("data", {}).get("testSuiteOutcome", {}) return {} - def start(self, identifier: str, otel_context: opentelemetry.context.context.Context) -> None: + def start(self, identifier: str, otel_context_carrier: dict) -> None: """Start ETR for this sub suite. :param identifier: An identifier for logs in this sub suite. + :otel_context_carrier: a dict propagating OpenTelemetry context from the parent thread. """ # OpenTelemetry context needs to be explicitly given here when creating this new span. # This is because the subsuite is running in a separate thread. + otel_context = TraceContextTextMapPropagator().extract(carrier=otel_context_carrier) + opentelemetry.context.attach(otel_context) span_name = "execute_testrunner" with self.otel_tracer.start_as_current_span( span_name, - context=otel_context, + #context=otel_context, kind=opentelemetry.trace.SpanKind.CLIENT, ) as span: span.set_attribute(SemConvAttributes.SUBSUITE_ID, identifier) @@ -189,7 +193,7 @@ def __init__( etos: ETOS, params: ESRParameters, suite: dict, - otel_context: opentelemetry.context.context.Context = None, + otel_context_carrier: dict = {}, ) -> None: """Initialize a TestSuite instance.""" self.etos = etos @@ -198,7 +202,10 @@ def __init__( self.logger = logging.getLogger(f"TestSuite - {self.suite.get('name')}") self.logger.addFilter(DuplicateFilter(self.logger)) self.sub_suites = [] - self.otel_context = otel_context + self.otel_context_carrier = otel_context_carrier + self.otel_context = TraceContextTextMapPropagator().extract(carrier=self.otel_context_carrier) + opentelemetry.context.attach(self.otel_context) + TraceContextTextMapPropagator().inject(self.otel_context_carrier) @property def sub_suite_environments(self) -> Iterator[dict]: @@ -331,6 +338,8 @@ def _send_test_suite_started(self) -> EiffelTestSuiteStartedEvent: def start(self) -> None: """Send test suite started, trigger and wait for all sub suites to start.""" + otel_context = TraceContextTextMapPropagator().extract(carrier=self.otel_context_carrier) + opentelemetry.context.attach(otel_context) self._announce("Starting tests", f"Starting up sub suites for '{self.suite.get('name')}'") self.test_suite_started = self._send_test_suite_started() @@ -365,7 +374,7 @@ def start(self) -> None: self.sub_suites.append(sub_suite) thread = threading.Thread( target=sub_suite.start, - args=(self.params.tercc.meta.event_id, self.otel_context), + args=(self.params.tercc.meta.event_id, self.otel_context_carrier), ) threads.append(thread) thread.start() From a6023370c33580bb96ef54c42f9cf6970257e941 Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Mon, 3 Jun 2024 13:05:16 +0200 Subject: [PATCH 2/9] code review changes --- Dockerfile | 2 -- projects/etos_suite_runner/requirements.txt | 2 +- projects/etos_suite_runner/setup.cfg | 2 +- projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py | 1 - 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7d1227c..ad30cd7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,6 @@ COPY --from=build /src/projects/etos_suite_runner/dist/*.whl /tmp # hadolint ignore=DL3013 RUN pip install --no-cache-dir /tmp/*.whl && groupadd -r etos && useradd -r -m -s /bin/false -g etos etos -RUN pip list - USER etos LABEL org.opencontainers.image.source=https://github.com/eiffel-community/etos-suite-runner diff --git a/projects/etos_suite_runner/requirements.txt b/projects/etos_suite_runner/requirements.txt index c806d2f..c7b113f 100644 --- a/projects/etos_suite_runner/requirements.txt +++ b/projects/etos_suite_runner/requirements.txt @@ -19,7 +19,7 @@ PyScaffold==3.2.3 packageurl-python~=0.11 cryptography>=42.0.4,<43.0.0 etos_lib==4.3.0 -#etos_environment_provider~=4.2 +etos_environment_provider~=4.3 opentelemetry-api~=1.21 opentelemetry-exporter-otlp~=1.21 opentelemetry-sdk~=1.21 diff --git a/projects/etos_suite_runner/setup.cfg b/projects/etos_suite_runner/setup.cfg index 5835000..15bc0c5 100644 --- a/projects/etos_suite_runner/setup.cfg +++ b/projects/etos_suite_runner/setup.cfg @@ -29,7 +29,7 @@ install_requires = packageurl-python~=0.11 cryptography>=42.0.4,<43.0.0 etos_lib==4.3.0 - #etos_environment_provider~=4.2 + etos_environment_provider~=4.3 opentelemetry-api~=1.21 opentelemetry-exporter-otlp~=1.21 opentelemetry-sdk~=1.21 diff --git a/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py b/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py index 693bf42..030b5d7 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py @@ -112,7 +112,6 @@ def start(self, identifier: str, otel_context_carrier: dict) -> None: span_name = "execute_testrunner" with self.otel_tracer.start_as_current_span( span_name, - #context=otel_context, kind=opentelemetry.trace.SpanKind.CLIENT, ) as span: span.set_attribute(SemConvAttributes.SUBSUITE_ID, identifier) From 7bba46f559c3564721879653b4a9c15092d9fff6 Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Mon, 3 Jun 2024 13:17:07 +0200 Subject: [PATCH 3/9] Code review changes --- projects/etos_suite_runner/src/etos_suite_runner/esr.py | 7 ++++++- .../etos_suite_runner/src/etos_suite_runner/lib/suite.py | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/projects/etos_suite_runner/src/etos_suite_runner/esr.py b/projects/etos_suite_runner/src/etos_suite_runner/esr.py index c15f96e..5890cc9 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/esr.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/esr.py @@ -151,7 +151,12 @@ def run_suites(self, triggered: EiffelActivityTriggeredEvent) -> list[str]: carrier = {} TraceContextTextMapPropagator().inject(carrier) threading.Thread( - target=self._request_environment, args=(ids.copy(), carrier,), daemon=True + target=self._request_environment, + args=( + ids.copy(), + carrier, + ), + daemon=True, ).start() self.etos.events.send_activity_started(triggered, {"CONTEXT": context}) diff --git a/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py b/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py index 030b5d7..f62c0fe 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py @@ -192,6 +192,7 @@ def __init__( etos: ETOS, params: ESRParameters, suite: dict, + # pylint: disable=dangerous-default-value otel_context_carrier: dict = {}, ) -> None: """Initialize a TestSuite instance.""" @@ -202,7 +203,9 @@ def __init__( self.logger.addFilter(DuplicateFilter(self.logger)) self.sub_suites = [] self.otel_context_carrier = otel_context_carrier - self.otel_context = TraceContextTextMapPropagator().extract(carrier=self.otel_context_carrier) + self.otel_context = TraceContextTextMapPropagator().extract( + carrier=self.otel_context_carrier + ) opentelemetry.context.attach(self.otel_context) TraceContextTextMapPropagator().inject(self.otel_context_carrier) From 2140d6bd7f565509d5ac0a29fa3e472be4945446 Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Fri, 7 Jun 2024 10:10:18 +0200 Subject: [PATCH 4/9] Code review changes --- projects/etos_suite_runner/setup.cfg | 4 +- .../src/etos_suite_runner/esr.py | 39 +++++++++++---- .../src/etos_suite_runner/lib/suite.py | 47 ++++++++++++++----- 3 files changed, 69 insertions(+), 21 deletions(-) diff --git a/projects/etos_suite_runner/setup.cfg b/projects/etos_suite_runner/setup.cfg index 15bc0c5..5a0f874 100644 --- a/projects/etos_suite_runner/setup.cfg +++ b/projects/etos_suite_runner/setup.cfg @@ -28,8 +28,8 @@ install_requires = PyScaffold==3.2.3 packageurl-python~=0.11 cryptography>=42.0.4,<43.0.0 - etos_lib==4.3.0 - etos_environment_provider~=4.3 + #etos_lib==4.3.0 + #etos_environment_provider~=4.3 opentelemetry-api~=1.21 opentelemetry-exporter-otlp~=1.21 opentelemetry-sdk~=1.21 diff --git a/projects/etos_suite_runner/src/etos_suite_runner/esr.py b/projects/etos_suite_runner/src/etos_suite_runner/esr.py index 5890cc9..799147c 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/esr.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/esr.py @@ -23,6 +23,8 @@ from uuid import uuid4 from eiffellib.events import EiffelActivityTriggeredEvent +import opentelemetry.context +import opentelemetry.context.context from environment_provider.environment_provider import EnvironmentProvider from environment_provider.environment import release_full_environment from etos_lib import ETOS @@ -53,7 +55,8 @@ def __init__(self) -> None: """Initialize ESR by creating a rabbitmq publisher.""" self.logger = logging.getLogger("ESR") self.otel_tracer = opentelemetry.trace.get_tracer(__name__) - opentelemetry.context.attach(get_current_context()) + self.otel_context = get_current_context() + self.otel_context_token = opentelemetry.context.attach(self.otel_context) self.etos = ETOS("ETOS Suite Runner", os.getenv("SOURCE_HOST"), "ETOS Suite Runner") signal.signal(signal.SIGTERM, self.graceful_exit) self.params = ESRParameters(self.etos) @@ -66,19 +69,23 @@ def __init__(self) -> None: int(os.getenv("ESR_WAIT_FOR_ENVIRONMENT_TIMEOUT")), ) - def _request_environment(self, ids: list[str], otel_context_carrier: dict) -> None: + self.otel_context = None + self.otel_context_token = None + + def __del__(self): + """Destructor.""" + if self.otel_context_token is not None: + opentelemetry.context.detach(self.otel_context_token) + + def __request_environment(self, ids: list[str]) -> None: """Request an environment from the environment provider. :param ids: Generated suite runner IDs used to correlate environments and the suite runners. - :param otel_context_carrier: a dict carrying current OpenTelemetry context. """ span_name = "request_environment" - suite_context = TraceContextTextMapPropagator().extract(carrier=otel_context_carrier) - opentelemetry.context.attach(suite_context) with self.otel_tracer.start_as_current_span( span_name, - context=suite_context, kind=opentelemetry.trace.SpanKind.CLIENT, ): try: @@ -107,6 +114,23 @@ def _request_environment(self, ids: list[str], otel_context_carrier: dict) -> No extra={"user_log": True}, ) + def _request_environment(self, ids: list[str], otel_context_carrier: dict) -> None: + """Request an environment from the environment provider (OpenTelemetry wrapper). + + :param ids: Generated suite runner IDs used to correlate environments and the suite + runners. + :param otel_context_carrier: a dict carrying current OpenTelemetry context. + """ + # OpenTelemetry contexts aren't propagated to threads automatically. + # For this reason otel_context needs to be restantiated due to + # this method running in a separate thread. + otel_context = TraceContextTextMapPropagator().extract(carrier=otel_context_carrier) + otel_context_token = opentelemetry.context.attach(otel_context) + try: + self.__request_environment(ids, otel_context) + finally: + opentelemetry.context.detach(otel_context_token) + def _release_environment(self) -> None: """Release an environment from the environment provider.""" # TODO: We should remove jsontas as a requirement for this function. @@ -114,10 +138,9 @@ def _release_environment(self) -> None: # jsontas is not required. jsontas = JsonTas() span_name = "release_full_environment" - suite_context = get_current_context() with self.otel_tracer.start_as_current_span( span_name, - context=suite_context, + context=self.otel_context, kind=opentelemetry.trace.SpanKind.CLIENT, ): status, message = release_full_environment( diff --git a/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py b/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py index f62c0fe..a5f051f 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py @@ -99,16 +99,12 @@ def outcome(self) -> dict: return self.test_suite_finished.get("data", {}).get("testSuiteOutcome", {}) return {} - def start(self, identifier: str, otel_context_carrier: dict) -> None: + + def _start(self, identifier: str) -> None: """Start ETR for this sub suite. :param identifier: An identifier for logs in this sub suite. - :otel_context_carrier: a dict propagating OpenTelemetry context from the parent thread. """ - # OpenTelemetry context needs to be explicitly given here when creating this new span. - # This is because the subsuite is running in a separate thread. - otel_context = TraceContextTextMapPropagator().extract(carrier=otel_context_carrier) - opentelemetry.context.attach(otel_context) span_name = "execute_testrunner" with self.otel_tracer.start_as_current_span( span_name, @@ -142,6 +138,21 @@ def start(self, identifier: str, otel_context_carrier: dict) -> None: finally: self.release(identifier) + def start(self, identifier: str, otel_context_carrier: dict) -> None: + """Start ETR for this sub suite (OpenTelemetry wrapper method). + + :param identifier: An identifier for logs in this sub suite. + :otel_context_carrier: a dict propagating OpenTelemetry context from the parent thread. + """ + # OpenTelemetry context needs to be explicitly given here when creating this new span. + # This is because the subsuite is running in a separate thread. + otel_context = TraceContextTextMapPropagator().extract(carrier=otel_context_carrier) + otel_context_token = opentelemetry.context.attach(otel_context) + try: + self._start(identifier) + finally: + opentelemetry.context.detach(otel_context_token) + def release(self, testrun_id) -> None: """Release this sub suite.""" # TODO: This whole method is now a bit of a hack that needs to be cleaned up. @@ -202,13 +213,18 @@ def __init__( self.logger = logging.getLogger(f"TestSuite - {self.suite.get('name')}") self.logger.addFilter(DuplicateFilter(self.logger)) self.sub_suites = [] + self.otel_context_carrier = otel_context_carrier self.otel_context = TraceContextTextMapPropagator().extract( carrier=self.otel_context_carrier ) - opentelemetry.context.attach(self.otel_context) + self.otel_context_token = opentelemetry.context.attach(self.otel_context) TraceContextTextMapPropagator().inject(self.otel_context_carrier) + def __del__(self): + """Destructor.""" + opentelemetry.context.detach(self.otel_context_token) + @property def sub_suite_environments(self) -> Iterator[dict]: """All sub suite environments from the environment provider. @@ -337,11 +353,9 @@ def _send_test_suite_started(self) -> EiffelTestSuiteStartedEvent: "TERC": self.params.tercc.meta.event_id, } return self.etos.events.send(test_suite_started, links, data) - - def start(self) -> None: + + def _start(self): """Send test suite started, trigger and wait for all sub suites to start.""" - otel_context = TraceContextTextMapPropagator().extract(carrier=self.otel_context_carrier) - opentelemetry.context.attach(otel_context) self._announce("Starting tests", f"Starting up sub suites for '{self.suite.get('name')}'") self.test_suite_started = self._send_test_suite_started() @@ -405,6 +419,17 @@ def start(self) -> None: extra={"user_log": True}, ) + def start(self) -> None: + """OpenTelemetry wrapper method for _start().""" + # OpenTelemetry contexts aren't automatically propagated to threads. + # For this reason OpenTelemetry context needs to be reinstantiated here. + otel_context = TraceContextTextMapPropagator().extract(carrier=self.otel_context_carrier) + otel_context_token = opentelemetry.context.attach(otel_context) + try: + self._start() + finally: + opentelemetry.context.detach(otel_context_token) + def release_all(self) -> None: """Release all, unreleased, sub suites.""" self.logger.info("Releasing all sub suite environments") From 0e8e5bdad11f56cf3d86ac98572ca4a391212c4d Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Fri, 7 Jun 2024 10:38:16 +0200 Subject: [PATCH 5/9] Code review changes --- projects/etos_suite_runner/src/etos_suite_runner/esr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/etos_suite_runner/src/etos_suite_runner/esr.py b/projects/etos_suite_runner/src/etos_suite_runner/esr.py index 799147c..bab7f2f 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/esr.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/esr.py @@ -127,7 +127,7 @@ def _request_environment(self, ids: list[str], otel_context_carrier: dict) -> No otel_context = TraceContextTextMapPropagator().extract(carrier=otel_context_carrier) otel_context_token = opentelemetry.context.attach(otel_context) try: - self.__request_environment(ids, otel_context) + self.__request_environment(ids) finally: opentelemetry.context.detach(otel_context_token) From 8db671880b426170c7e9bc34176bf4559868e684 Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Fri, 7 Jun 2024 10:48:34 +0200 Subject: [PATCH 6/9] Code review changes --- projects/etos_suite_runner/setup.cfg | 4 ++-- .../etos_suite_runner/src/etos_suite_runner/esr.py | 2 -- .../src/etos_suite_runner/lib/suite.py | 10 ++++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/projects/etos_suite_runner/setup.cfg b/projects/etos_suite_runner/setup.cfg index 5a0f874..15bc0c5 100644 --- a/projects/etos_suite_runner/setup.cfg +++ b/projects/etos_suite_runner/setup.cfg @@ -28,8 +28,8 @@ install_requires = PyScaffold==3.2.3 packageurl-python~=0.11 cryptography>=42.0.4,<43.0.0 - #etos_lib==4.3.0 - #etos_environment_provider~=4.3 + etos_lib==4.3.0 + etos_environment_provider~=4.3 opentelemetry-api~=1.21 opentelemetry-exporter-otlp~=1.21 opentelemetry-sdk~=1.21 diff --git a/projects/etos_suite_runner/src/etos_suite_runner/esr.py b/projects/etos_suite_runner/src/etos_suite_runner/esr.py index bab7f2f..9fdbe21 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/esr.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/esr.py @@ -23,8 +23,6 @@ from uuid import uuid4 from eiffellib.events import EiffelActivityTriggeredEvent -import opentelemetry.context -import opentelemetry.context.context from environment_provider.environment_provider import EnvironmentProvider from environment_provider.environment import release_full_environment from etos_lib import ETOS diff --git a/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py b/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py index a5f051f..c27036d 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py @@ -99,7 +99,6 @@ def outcome(self) -> dict: return self.test_suite_finished.get("data", {}).get("testSuiteOutcome", {}) return {} - def _start(self, identifier: str) -> None: """Start ETR for this sub suite. @@ -213,7 +212,7 @@ def __init__( self.logger = logging.getLogger(f"TestSuite - {self.suite.get('name')}") self.logger.addFilter(DuplicateFilter(self.logger)) self.sub_suites = [] - + self.otel_context_carrier = otel_context_carrier self.otel_context = TraceContextTextMapPropagator().extract( carrier=self.otel_context_carrier @@ -353,7 +352,7 @@ def _send_test_suite_started(self) -> EiffelTestSuiteStartedEvent: "TERC": self.params.tercc.meta.event_id, } return self.etos.events.send(test_suite_started, links, data) - + def _start(self): """Send test suite started, trigger and wait for all sub suites to start.""" self._announce("Starting tests", f"Starting up sub suites for '{self.suite.get('name')}'") @@ -420,7 +419,10 @@ def _start(self): ) def start(self) -> None: - """OpenTelemetry wrapper method for _start().""" + """Send test suite started, trigger and wait for all sub suites to start. + + This is an OpenTelemetry wrapper method for _start(). + """ # OpenTelemetry contexts aren't automatically propagated to threads. # For this reason OpenTelemetry context needs to be reinstantiated here. otel_context = TraceContextTextMapPropagator().extract(carrier=self.otel_context_carrier) From d5ff7fe7666fca36d2580b35016cf13491d05d71 Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Fri, 7 Jun 2024 14:58:23 +0200 Subject: [PATCH 7/9] Code review changes --- projects/etos_suite_runner/setup.cfg | 4 ++-- projects/etos_suite_runner/src/etos_suite_runner/esr.py | 5 +---- .../etos_suite_runner/src/etos_suite_runner/lib/suite.py | 8 +++++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/projects/etos_suite_runner/setup.cfg b/projects/etos_suite_runner/setup.cfg index 15bc0c5..30f9c78 100644 --- a/projects/etos_suite_runner/setup.cfg +++ b/projects/etos_suite_runner/setup.cfg @@ -28,8 +28,8 @@ install_requires = PyScaffold==3.2.3 packageurl-python~=0.11 cryptography>=42.0.4,<43.0.0 - etos_lib==4.3.0 - etos_environment_provider~=4.3 + #etos_lib==4.3.1 + #etos_environment_provider~=4.3 opentelemetry-api~=1.21 opentelemetry-exporter-otlp~=1.21 opentelemetry-sdk~=1.21 diff --git a/projects/etos_suite_runner/src/etos_suite_runner/esr.py b/projects/etos_suite_runner/src/etos_suite_runner/esr.py index 9fdbe21..4c004f4 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/esr.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/esr.py @@ -67,9 +67,6 @@ def __init__(self) -> None: int(os.getenv("ESR_WAIT_FOR_ENVIRONMENT_TIMEOUT")), ) - self.otel_context = None - self.otel_context_token = None - def __del__(self): """Destructor.""" if self.otel_context_token is not None: @@ -120,7 +117,7 @@ def _request_environment(self, ids: list[str], otel_context_carrier: dict) -> No :param otel_context_carrier: a dict carrying current OpenTelemetry context. """ # OpenTelemetry contexts aren't propagated to threads automatically. - # For this reason otel_context needs to be restantiated due to + # For this reason otel_context needs to be reinstantiated due to # this method running in a separate thread. otel_context = TraceContextTextMapPropagator().extract(carrier=otel_context_carrier) otel_context_token = opentelemetry.context.attach(otel_context) diff --git a/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py b/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py index c27036d..452b29b 100644 --- a/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py +++ b/projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py @@ -18,7 +18,7 @@ import logging import threading import time -from typing import Iterator +from typing import Iterator, Union from eiffellib.events import EiffelTestSuiteStartedEvent from environment_provider.lib.registry import ProviderRegistry @@ -202,8 +202,7 @@ def __init__( etos: ETOS, params: ESRParameters, suite: dict, - # pylint: disable=dangerous-default-value - otel_context_carrier: dict = {}, + otel_context_carrier: Union[dict, None] = None, ) -> None: """Initialize a TestSuite instance.""" self.etos = etos @@ -213,6 +212,9 @@ def __init__( self.logger.addFilter(DuplicateFilter(self.logger)) self.sub_suites = [] + if otel_context_carrier is None: + otel_context_carrier = {} + self.otel_context_carrier = otel_context_carrier self.otel_context = TraceContextTextMapPropagator().extract( carrier=self.otel_context_carrier From 6c06b710c3c0df32417068212ebaf34e33e2cda7 Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Mon, 10 Jun 2024 11:22:14 +0200 Subject: [PATCH 8/9] Code review changes --- projects/etos_suite_runner/requirements.txt | 4 ++-- projects/etos_suite_runner/setup.cfg | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/etos_suite_runner/requirements.txt b/projects/etos_suite_runner/requirements.txt index c7b113f..b048a8f 100644 --- a/projects/etos_suite_runner/requirements.txt +++ b/projects/etos_suite_runner/requirements.txt @@ -18,8 +18,8 @@ PyScaffold==3.2.3 packageurl-python~=0.11 cryptography>=42.0.4,<43.0.0 -etos_lib==4.3.0 -etos_environment_provider~=4.3 +etos_lib==4.3.1 +etos_environment_provider~=4.4 opentelemetry-api~=1.21 opentelemetry-exporter-otlp~=1.21 opentelemetry-sdk~=1.21 diff --git a/projects/etos_suite_runner/setup.cfg b/projects/etos_suite_runner/setup.cfg index 30f9c78..478d389 100644 --- a/projects/etos_suite_runner/setup.cfg +++ b/projects/etos_suite_runner/setup.cfg @@ -28,8 +28,8 @@ install_requires = PyScaffold==3.2.3 packageurl-python~=0.11 cryptography>=42.0.4,<43.0.0 - #etos_lib==4.3.1 - #etos_environment_provider~=4.3 + etos_lib==4.3.1 + etos_environment_provider~=4.4 opentelemetry-api~=1.21 opentelemetry-exporter-otlp~=1.21 opentelemetry-sdk~=1.21 From 0d760133eab2b15a96992d5d96a20149c4a3bccb Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Mon, 10 Jun 2024 11:24:49 +0200 Subject: [PATCH 9/9] Code review changes --- projects/etos_suite_runner/requirements.txt | 2 +- projects/etos_suite_runner/setup.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/etos_suite_runner/requirements.txt b/projects/etos_suite_runner/requirements.txt index b048a8f..9986e8d 100644 --- a/projects/etos_suite_runner/requirements.txt +++ b/projects/etos_suite_runner/requirements.txt @@ -19,7 +19,7 @@ PyScaffold==3.2.3 packageurl-python~=0.11 cryptography>=42.0.4,<43.0.0 etos_lib==4.3.1 -etos_environment_provider~=4.4 +etos_environment_provider==4.4.1 opentelemetry-api~=1.21 opentelemetry-exporter-otlp~=1.21 opentelemetry-sdk~=1.21 diff --git a/projects/etos_suite_runner/setup.cfg b/projects/etos_suite_runner/setup.cfg index 478d389..a8a31f9 100644 --- a/projects/etos_suite_runner/setup.cfg +++ b/projects/etos_suite_runner/setup.cfg @@ -29,7 +29,7 @@ install_requires = packageurl-python~=0.11 cryptography>=42.0.4,<43.0.0 etos_lib==4.3.1 - etos_environment_provider~=4.4 + etos_environment_provider==4.4.1 opentelemetry-api~=1.21 opentelemetry-exporter-otlp~=1.21 opentelemetry-sdk~=1.21