From ff0af4e854ce085cc4754a7d872d45cba61e80b0 Mon Sep 17 00:00:00 2001 From: Peter Giacomo Lombardo Date: Wed, 29 Apr 2020 10:31:29 +0200 Subject: [PATCH 1/2] Add try block to protect against import failes from sub packages --- instana/singletons.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/instana/singletons.py b/instana/singletons.py index 531c90d8..cd9051c4 100644 --- a/instana/singletons.py +++ b/instana/singletons.py @@ -3,6 +3,7 @@ import opentracing from .agent import StandardAgent, AWSLambdaAgent +from .log import logger from .tracer import InstanaTracer from .recorder import StandardRecorder, AWSLambdaRecorder @@ -36,8 +37,11 @@ def set_agent(new_agent): tracer = InstanaTracer(recorder=span_recorder) if sys.version_info >= (3, 4): - from opentracing.scope_managers.asyncio import AsyncioScopeManager - async_tracer = InstanaTracer(scope_manager=AsyncioScopeManager(), recorder=span_recorder) + try: + from opentracing.scope_managers.asyncio import AsyncioScopeManager + async_tracer = InstanaTracer(scope_manager=AsyncioScopeManager(), recorder=span_recorder) + except Exception as e: + logger.debug("Error setting up async_tracer:", exc_info=True) # Mock the tornado tracer until tornado is detected and instrumented first From 484e5e42ee9a61726044c477af3e126be1cc9d7a Mon Sep 17 00:00:00 2001 From: Peter Giacomo Lombardo Date: Wed, 29 Apr 2020 10:44:07 +0200 Subject: [PATCH 2/2] Linter fixes --- instana/singletons.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/instana/singletons.py b/instana/singletons.py index cd9051c4..9a7c1348 100644 --- a/instana/singletons.py +++ b/instana/singletons.py @@ -19,15 +19,23 @@ span_recorder = StandardRecorder() -# Retrieve the globally configured agent def get_agent(): + """ + Retrieve the globally configured agent + @return: The Instana Agent singleton + """ global agent return agent -# Set the global agent for the Instana package. This is used for the -# test suite only currently. def set_agent(new_agent): + """ + Set the global agent for the Instana package. This is used for the + test suite only currently. + + @param new_agent: agent to replace current singleton + @return: None + """ global agent agent = new_agent @@ -40,7 +48,7 @@ def set_agent(new_agent): try: from opentracing.scope_managers.asyncio import AsyncioScopeManager async_tracer = InstanaTracer(scope_manager=AsyncioScopeManager(), recorder=span_recorder) - except Exception as e: + except Exception: logger.debug("Error setting up async_tracer:", exc_info=True) @@ -58,14 +66,21 @@ def setup_tornado_tracer(): opentracing.tracer = tracer -# Retrieve the globally configured tracer def get_tracer(): + """ + Retrieve the globally configured tracer + @return: Tracer + """ global tracer return tracer -# Set the global tracer for the Instana package. This is used for the -# test suite only currently. def set_tracer(new_tracer): + """ + Set the global tracer for the Instana package. This is used for the + test suite only currently. + @param new_tracer: The new tracer to replace the singleton + @return: None + """ global tracer tracer = new_tracer