From 2351d9ba034c4edc2d3f374c8ab8bbe4cca0030b Mon Sep 17 00:00:00 2001 From: Sorin Munteanu Date: Wed, 1 Feb 2023 13:28:54 -0500 Subject: [PATCH 1/5] refactor code to accomodate Nuitka compilation to C++ code --- .../src/opentelemetry/context/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/context/__init__.py b/opentelemetry-api/src/opentelemetry/context/__init__.py index 306f0937d53..cc4161530a2 100644 --- a/opentelemetry-api/src/opentelemetry/context/__init__.py +++ b/opentelemetry-api/src/opentelemetry/context/__init__.py @@ -55,11 +55,14 @@ def wrapper( # type: ignore[misc] OTEL_PYTHON_CONTEXT, default_context ) # type: str try: - _RUNTIME_CONTEXT = next( - iter_entry_points( - "opentelemetry_context", configured_context + for entry_point in iter_entry_points("opentelemetry_context"): + if entry_point.name==configured_context: + _RUNTIME_CONTEXT = entry_point.load()() + break + if _RUNTIME_CONTEXT is None: + logger.error( + "Failed to load context (no such entry point): %s", configured_context ) - ).load()() except Exception: # pylint: disable=broad-except logger.error( "Failed to load context: %s", configured_context From 1b1daa7795d604146256eab2455123a3dec2561f Mon Sep 17 00:00:00 2001 From: Sorin Munteanu Date: Thu, 23 Feb 2023 14:54:34 -0500 Subject: [PATCH 2/5] refactor propagators' initialization to accommodate Nuitka compilation to C++ code --- .../src/opentelemetry/propagate/__init__.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/propagate/__init__.py b/opentelemetry-api/src/opentelemetry/propagate/__init__.py index a39d8a44d1f..ded55e46970 100644 --- a/opentelemetry-api/src/opentelemetry/propagate/__init__.py +++ b/opentelemetry-api/src/opentelemetry/propagate/__init__.py @@ -132,11 +132,12 @@ def inject( for propagator in environ_propagators.split(","): propagator = propagator.strip() try: - propagators.append( # type: ignore - next( # type: ignore - iter_entry_points("opentelemetry_propagator", propagator) - ).load()() - ) + for entry in iter_entry_points("opentelemetry_propagator"): + if entry.name==propagator: + propagators.append( # type: ignore + entry.load()() + ) + break except Exception: # pylint: disable=broad-except logger.exception( "Failed to load configured propagator `%s`", propagator From 5f6a3f10ba698ae97070d20ca76a5f2e4c7cfada Mon Sep 17 00:00:00 2001 From: Sorin Munteanu Date: Mon, 27 Feb 2023 15:07:20 -0500 Subject: [PATCH 3/5] merge main branch --- opentelemetry-api/src/opentelemetry/context/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/opentelemetry-api/src/opentelemetry/context/__init__.py b/opentelemetry-api/src/opentelemetry/context/__init__.py index 2632132de96..3e85b64fe48 100644 --- a/opentelemetry-api/src/opentelemetry/context/__init__.py +++ b/opentelemetry-api/src/opentelemetry/context/__init__.py @@ -64,6 +64,7 @@ def wrapper( # type: ignore[misc] name=configured_context, ) ) + ).load()() except Exception: # pylint: disable=broad-except logger.exception( From e4f8301a6fdbcb83f28256e01a6b679f76152c74 Mon Sep 17 00:00:00 2001 From: Sorin Munteanu Date: Mon, 27 Feb 2023 16:04:04 -0500 Subject: [PATCH 4/5] refactor Python code to accommodate correct Nuitka compilation --- .../src/opentelemetry/propagate/__init__.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/propagate/__init__.py b/opentelemetry-api/src/opentelemetry/propagate/__init__.py index 56f217f282d..181428ff3e6 100644 --- a/opentelemetry-api/src/opentelemetry/propagate/__init__.py +++ b/opentelemetry-api/src/opentelemetry/propagate/__init__.py @@ -133,17 +133,12 @@ def inject( propagator = propagator.strip() try: - - propagators.append( # type: ignore - next( # type: ignore - iter( # type: ignore - entry_points( # type: ignore - group="opentelemetry_propagator", - name=propagator, - ) + for entry in entry_points(group="opentelemetry_propagator"): + if entry.name==propagator: + propagators.append( # type: ignore + entry.load()() ) - ).load()() - ) + break except Exception: # pylint: disable=broad-except logger.exception( From d3cdda9d4e1d63d30fb6e131e206404206c6d0fe Mon Sep 17 00:00:00 2001 From: Sorin Munteanu Date: Mon, 27 Feb 2023 16:21:15 -0500 Subject: [PATCH 5/5] refactor Python code to accommodate correct Nuitka compilation --- .../src/opentelemetry/context/__init__.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/context/__init__.py b/opentelemetry-api/src/opentelemetry/context/__init__.py index 3e85b64fe48..9f27a2be737 100644 --- a/opentelemetry-api/src/opentelemetry/context/__init__.py +++ b/opentelemetry-api/src/opentelemetry/context/__init__.py @@ -57,14 +57,14 @@ def wrapper( # type: ignore[misc] ) # type: str try: - _RUNTIME_CONTEXT = next( # type: ignore - iter( # type: ignore - entry_points( # type: ignore - group="opentelemetry_context", - name=configured_context, - ) + for entry_point in entry_points(group="opentelemetry_context"): + if entry_point.name==configured_context: + _RUNTIME_CONTEXT = entry_point.load()() + break + if _RUNTIME_CONTEXT is None: + logger.exception( + "Failed to load context (no such entry point): %s", configured_context ) - ).load()() except Exception: # pylint: disable=broad-except logger.exception(