diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml new file mode 100644 index 00000000..fceaabde --- /dev/null +++ b/.github/workflows/sonarqube.yml @@ -0,0 +1,27 @@ +name: Build +on: + push: + branches: + - master # or the name of your main branch + pull_request: + types: [opened, synchronize, reopened] +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: sonarsource/sonarqube-scan-action@master + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + # If you wish to fail your job when the Quality Gate is red, uncomment the + # following lines. This would typically be used to fail a deployment. + # We do not recommend to use this in a pull request. Prefer using pull request + # decoration instead. + # - uses: sonarsource/sonarqube-quality-gate-action@master + # timeout-minutes: 5 + # env: + # SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file diff --git a/instana/instrumentation/django/middleware.py b/instana/instrumentation/django/middleware.py index 21b5a5c4..37a52bdc 100644 --- a/instana/instrumentation/django/middleware.py +++ b/instana/instrumentation/django/middleware.py @@ -84,7 +84,7 @@ def process_response(self, request, response): if request.iscope is not None: request.iscope.close() request.iscope = None - return response + return response def process_exception(self, request, exception): from django.http.response import Http404 diff --git a/instana/instrumentation/flask/common.py b/instana/instrumentation/flask/common.py index c3413e31..a21aa473 100644 --- a/instana/instrumentation/flask/common.py +++ b/instana/instrumentation/flask/common.py @@ -74,5 +74,5 @@ def handle_user_exception_with_instana(wrapped, instance, argv, kwargs): flask.g.scope = None except: logger.debug("handle_user_exception_with_instana:", exc_info=True) - finally: - return response + + return response diff --git a/instana/instrumentation/flask/vanilla.py b/instana/instrumentation/flask/vanilla.py index 9cd4f2c8..a4a47956 100644 --- a/instana/instrumentation/flask/vanilla.py +++ b/instana/instrumentation/flask/vanilla.py @@ -51,8 +51,8 @@ def before_request_with_instana(*argv, **kwargs): span.set_tag("http.path_tpl", path_tpl) except: logger.debug("Flask before_request", exc_info=True) - finally: - return None + + return None def after_request_with_instana(response): @@ -78,7 +78,7 @@ def after_request_with_instana(response): if scope is not None: scope.close() flask.g.scope = None - return response + return response def teardown_request_with_instana(*argv, **kwargs): diff --git a/instana/instrumentation/grpcio.py b/instana/instrumentation/grpcio.py index 1c65abcd..f6d3c439 100644 --- a/instana/instrumentation/grpcio.py +++ b/instana/instrumentation/grpcio.py @@ -42,8 +42,7 @@ def collect_tags(span, instance, argv, kwargs): span.set_tag('rpc.port', parts[1]) except: logger.debug("grpc.collect_tags non-fatal error", exc_info=True) - finally: - return span + return span @wrapt.patch_function_wrapper('grpc._channel', '_UnaryUnaryMultiCallable.with_call') diff --git a/instana/instrumentation/logging.py b/instana/instrumentation/logging.py index 9b1ff7a0..58ffcefa 100644 --- a/instana/instrumentation/logging.py +++ b/instana/instrumentation/logging.py @@ -47,8 +47,8 @@ def log_with_instana(wrapped, instance, argv, kwargs): scope.span.mark_as_errored() except Exception: logger.debug('log_with_instana:', exc_info=True) - finally: - return wrapped(*argv, **kwargs) + + return wrapped(*argv, **kwargs) logger.debug('Instrumenting logging') diff --git a/instana/instrumentation/pep0249.py b/instana/instrumentation/pep0249.py index c9d8cb3a..d00814b8 100644 --- a/instana/instrumentation/pep0249.py +++ b/instana/instrumentation/pep0249.py @@ -35,8 +35,7 @@ def _collect_kvs(self, span, sql): span.set_tag('port', self._connect_params[1]['port']) except Exception as e: logger.debug(e) - finally: - return span + return span def execute(self, sql, params=None): active_tracer = get_active_tracer() diff --git a/instana/instrumentation/redis.py b/instana/instrumentation/redis.py index 5623a3f1..7eeea3ef 100644 --- a/instana/instrumentation/redis.py +++ b/instana/instrumentation/redis.py @@ -32,8 +32,8 @@ def collect_tags(span, instance, args, kwargs): except: logger.debug("redis.collect_tags non-fatal error", exc_info=True) - finally: - return span + + return span def execute_command_with_instana(wrapped, instance, args, kwargs): diff --git a/instana/instrumentation/sqlalchemy.py b/instana/instrumentation/sqlalchemy.py index 5618ebe4..7b6f795e 100644 --- a/instana/instrumentation/sqlalchemy.py +++ b/instana/instrumentation/sqlalchemy.py @@ -38,8 +38,7 @@ def receive_before_cursor_execute(**kw): scope.span.set_tag('sqlalchemy.url', url_regexp.sub('//', url)) except Exception as e: logger.debug(e) - finally: - return + return @event.listens_for(Engine, 'after_cursor_execute', named=True) diff --git a/instana/util/traceutils.py b/instana/util/traceutils.py index 8d6567cf..ba572395 100644 --- a/instana/util/traceutils.py +++ b/instana/util/traceutils.py @@ -27,5 +27,6 @@ def get_active_tracer(): else: return None except Exception: - logger.debug("error while getting active tracer: ", exc_info=True) + # Do not try to log this with instana, as there is no active tracer and there will be an infinite loop at least + # for PY2 return None diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000..5e189de5 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,7 @@ +sonar.projectKey=Python-Tracer +sonar.projectName=Python Tracer +sonar.sourceEncoding=utf-8 +sonar.sources=. +sonar.exclusions=tests/**/*, example/**/* +sonar.tests=. +sonar.test.inclusions=tests/**/*