From 025bded2786b16ef80c06a1d6da6d0361078e11f Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Tue, 2 Apr 2024 12:03:00 +0200 Subject: [PATCH 1/4] Fixes for OpenTelemetry tracing --- python/setup.cfg | 2 +- python/src/etos_api/__init__.py | 9 +++++++++ python/src/etos_api/routers/etos/router.py | 3 ++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/python/setup.cfg b/python/setup.cfg index 9adfd61..9725bd0 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -24,7 +24,7 @@ package_dir = # DON'T CHANGE THE FOLLOWING LINE! IT WILL BE UPDATED BY PYSCAFFOLD! setup_requires = pyscaffold>=3.2a0,<3.3a0 install_requires = - etos_lib==4.0.0 + #etos_lib==4.0.0 etcd3gw~=2.3 pyscaffold~=4.4 uvicorn~=0.22 diff --git a/python/src/etos_api/__init__.py b/python/src/etos_api/__init__.py index c25581c..9d79315 100644 --- a/python/src/etos_api/__init__.py +++ b/python/src/etos_api/__init__.py @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """ETOS API module.""" +import logging import os from importlib.metadata import PackageNotFoundError, version @@ -43,6 +44,14 @@ ENVIRONMENT = "development" if DEV else "production" setup_logging("ETOS API", VERSION, ENVIRONMENT) +LOGGER = logging.getLogger(__name__) + +# Setting OTEL_COLLECTOR_HOST will override the default OTEL collector endpoint. +# This is needed when using the centralized cluster-level OTEL collector instead of sidecar collector. +if os.getenv("OTEL_COLLECTOR_HOST"): + os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = os.getenv("OTEL_COLLECTOR_HOST") + LOGGER.info("Using OTEL collector: %s", os.getenv("OTEL_COLLECTOR_HOST")) + if os.getenv("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"): PROVIDER = TracerProvider( resource=Resource.create( diff --git a/python/src/etos_api/routers/etos/router.py b/python/src/etos_api/routers/etos/router.py index 021d3ed..a037116 100644 --- a/python/src/etos_api/routers/etos/router.py +++ b/python/src/etos_api/routers/etos/router.py @@ -23,6 +23,7 @@ from fastapi import APIRouter, HTTPException from kubernetes import client from opentelemetry import trace +from opentelemetry.trace import Span from etos_api.library.environment import Configuration, configure_testrun from etos_api.library.utilities import sync_to_async @@ -53,7 +54,7 @@ async def validate_suite(test_suite_url: str) -> None: ) from exception -async def _start(etos: StartEtosRequest, span: "Span") -> dict: +async def _start(etos: StartEtosRequest, span: Span) -> dict: """Start ETOS execution. :param etos: ETOS pydantic model. From 25067b66d8cbb2a6f831da87b1ae8f8d0adfc288 Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Tue, 2 Apr 2024 12:03:00 +0200 Subject: [PATCH 2/4] Fixes for OpenTelemetry tracing --- Dockerfile | 1 + python/setup.cfg | 2 +- python/src/etos_api/__init__.py | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 23f12c9..916a808 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ ARG TZ ENV TZ=$TZ COPY --from=build /src/python/dist/*.whl /tmp +COPY --from=build /src/python/dist2/*.whl /tmp # hadolint ignore=DL3013 # hadolint ignore=DL3008 diff --git a/python/setup.cfg b/python/setup.cfg index 9725bd0..ab4152f 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -36,7 +36,7 @@ install_requires = sse-starlette~=1.6 opentelemetry-api~=1.21 opentelemetry-exporter-otlp~=1.21 - opentelemetry-instrumentation-fastapi==0.44b0 + opentelemetry-instrumentation-fastapi==0.45b0 opentelemetry-sdk~=1.21 jsontas~=1.4 packageurl-python~=0.11 diff --git a/python/src/etos_api/__init__.py b/python/src/etos_api/__init__.py index 9d79315..067509c 100644 --- a/python/src/etos_api/__init__.py +++ b/python/src/etos_api/__init__.py @@ -48,9 +48,15 @@ # Setting OTEL_COLLECTOR_HOST will override the default OTEL collector endpoint. # This is needed when using the centralized cluster-level OTEL collector instead of sidecar collector. +<<<<<<< HEAD if os.getenv("OTEL_COLLECTOR_HOST"): os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = os.getenv("OTEL_COLLECTOR_HOST") LOGGER.info("Using OTEL collector: %s", os.getenv("OTEL_COLLECTOR_HOST")) +======= +# if os.getenv("OTEL_COLLECTOR_HOST"): +# os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = os.getenv("OTEL_COLLECTOR_HOST") +# LOGGER.info("Using OTEL collector: %s", os.getenv("OTEL_COLLECTOR_HOST")) +>>>>>>> 5d5fd1d (Fixes for OpenTelemetry tracing) if os.getenv("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"): PROVIDER = TracerProvider( From 26f3a18977bc431524299ab368dcdd2fdafd86f4 Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Wed, 17 Apr 2024 08:00:47 +0200 Subject: [PATCH 3/4] additional fixes for OpenTelemetry tracing --- Dockerfile | 1 - python/src/etos_api/__init__.py | 15 --------------- 2 files changed, 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 916a808..23f12c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,6 @@ ARG TZ ENV TZ=$TZ COPY --from=build /src/python/dist/*.whl /tmp -COPY --from=build /src/python/dist2/*.whl /tmp # hadolint ignore=DL3013 # hadolint ignore=DL3008 diff --git a/python/src/etos_api/__init__.py b/python/src/etos_api/__init__.py index 067509c..c25581c 100644 --- a/python/src/etos_api/__init__.py +++ b/python/src/etos_api/__init__.py @@ -14,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. """ETOS API module.""" -import logging import os from importlib.metadata import PackageNotFoundError, version @@ -44,20 +43,6 @@ ENVIRONMENT = "development" if DEV else "production" setup_logging("ETOS API", VERSION, ENVIRONMENT) -LOGGER = logging.getLogger(__name__) - -# Setting OTEL_COLLECTOR_HOST will override the default OTEL collector endpoint. -# This is needed when using the centralized cluster-level OTEL collector instead of sidecar collector. -<<<<<<< HEAD -if os.getenv("OTEL_COLLECTOR_HOST"): - os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = os.getenv("OTEL_COLLECTOR_HOST") - LOGGER.info("Using OTEL collector: %s", os.getenv("OTEL_COLLECTOR_HOST")) -======= -# if os.getenv("OTEL_COLLECTOR_HOST"): -# os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = os.getenv("OTEL_COLLECTOR_HOST") -# LOGGER.info("Using OTEL collector: %s", os.getenv("OTEL_COLLECTOR_HOST")) ->>>>>>> 5d5fd1d (Fixes for OpenTelemetry tracing) - if os.getenv("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"): PROVIDER = TracerProvider( resource=Resource.create( From 9a3846a7dc78606916d902374c3f374a775c037b Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Fri, 19 Apr 2024 13:18:38 +0200 Subject: [PATCH 4/4] additional fixes for OpenTelemetry tracing --- python/requirements.txt | 4 ++-- python/setup.cfg | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/requirements.txt b/python/requirements.txt index b6fe455..d2fd046 100644 --- a/python/requirements.txt +++ b/python/requirements.txt @@ -12,7 +12,7 @@ # pip install -r requirements.txt # Remember to also add them in setup.cfg but unpinned. -etos_lib==4.0.0 +etos_lib==4.1.1 etcd3gw~=2.3 pyscaffold~=4.4 uvicorn~=0.22 @@ -24,7 +24,7 @@ kubernetes~=26.1 sse-starlette~=1.6 opentelemetry-api~=1.21 opentelemetry-exporter-otlp~=1.21 -opentelemetry-instrumentation-fastapi==0.44b0 +opentelemetry-instrumentation-fastapi==0.45b0 opentelemetry-sdk~=1.21 jsontas~=1.4 packageurl-python~=0.11 diff --git a/python/setup.cfg b/python/setup.cfg index ab4152f..c5c0462 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -24,7 +24,7 @@ package_dir = # DON'T CHANGE THE FOLLOWING LINE! IT WILL BE UPDATED BY PYSCAFFOLD! setup_requires = pyscaffold>=3.2a0,<3.3a0 install_requires = - #etos_lib==4.0.0 + etos_lib==4.1.1 etcd3gw~=2.3 pyscaffold~=4.4 uvicorn~=0.22