From 067aa4ed7e5bc924a249f27d3199f9a6b73329e9 Mon Sep 17 00:00:00 2001 From: dimitraparaskevopoulou Date: Thu, 23 Sep 2021 09:58:53 +0200 Subject: [PATCH 01/10] adding sonarqube integration --- .github/workflows/sonarqube.yml | 27 +++++++++++++++++++++++++++ sonar-project.properties | 7 +++++++ 2 files changed, 34 insertions(+) create mode 100644 .github/workflows/sonarqube.yml create mode 100644 sonar-project.properties diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml new file mode 100644 index 00000000..17ad53b6 --- /dev/null +++ b/.github/workflows/sonarqube.yml @@ -0,0 +1,27 @@ +name: Build +on: + push: + branches: + - sonarqube_integration # 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/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000..9a845802 --- /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/* +sonar.tests=. +sonar.test.inclusions=tests/* \ No newline at end of file From eb2cfa66156dd36bdd17a6ad5acba2d13680fb03 Mon Sep 17 00:00:00 2001 From: dimitraparaskevopoulou Date: Thu, 23 Sep 2021 10:00:32 +0200 Subject: [PATCH 02/10] adding sonarqube integration --- .github/workflows/sonarqube.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index 17ad53b6..fceaabde 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -2,7 +2,7 @@ name: Build on: push: branches: - - sonarqube_integration # or the name of your main branch + - master # or the name of your main branch pull_request: types: [opened, synchronize, reopened] jobs: From 876c5a7e731cbf0a1dccc3b07312240f427d92f3 Mon Sep 17 00:00:00 2001 From: dimitraparaskevopoulou Date: Thu, 23 Sep 2021 10:10:09 +0200 Subject: [PATCH 03/10] excluding the tests --- .github/workflows/sonarqube.yml | 2 +- sonar-project.properties | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index fceaabde..17ad53b6 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -2,7 +2,7 @@ name: Build on: push: branches: - - master # or the name of your main branch + - sonarqube_integration # or the name of your main branch pull_request: types: [opened, synchronize, reopened] jobs: diff --git a/sonar-project.properties b/sonar-project.properties index 9a845802..9f2b7651 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,6 +2,6 @@ sonar.projectKey=Python-Tracer sonar.projectName=Python Tracer sonar.sourceEncoding=utf-8 sonar.sources=. -sonar.exclusions=tests/* +sonar.exclusions=tests/**/* sonar.tests=. -sonar.test.inclusions=tests/* \ No newline at end of file +sonar.test.inclusions=tests/**/* \ No newline at end of file From 7e888113e2953377e0fb508bfa2cfd32e1360179 Mon Sep 17 00:00:00 2001 From: dimitraparaskevopoulou Date: Thu, 23 Sep 2021 10:16:58 +0200 Subject: [PATCH 04/10] specify the directories to analyze --- sonar-project.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonar-project.properties b/sonar-project.properties index 9f2b7651..fb08c8e2 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,7 +1,7 @@ sonar.projectKey=Python-Tracer sonar.projectName=Python Tracer sonar.sourceEncoding=utf-8 -sonar.sources=. -sonar.exclusions=tests/**/* +sonar.sources=instana/**/* +sonar.exclusions=tests/**/*, example/**/* sonar.tests=. sonar.test.inclusions=tests/**/* \ No newline at end of file From 11e821d1609bb3caac3436c88517f304b8aca516 Mon Sep 17 00:00:00 2001 From: dimitraparaskevopoulou Date: Thu, 23 Sep 2021 10:49:59 +0200 Subject: [PATCH 05/10] specify the directories to analyze --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index fb08c8e2..1fe93502 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,6 +2,6 @@ sonar.projectKey=Python-Tracer sonar.projectName=Python Tracer sonar.sourceEncoding=utf-8 sonar.sources=instana/**/* -sonar.exclusions=tests/**/*, example/**/* +sonar.exclusions=example/**/* sonar.tests=. sonar.test.inclusions=tests/**/* \ No newline at end of file From 5061421824aa9b3ceb79a9afd635cdbbb5656728 Mon Sep 17 00:00:00 2001 From: dimitraparaskevopoulou Date: Thu, 23 Sep 2021 10:59:10 +0200 Subject: [PATCH 06/10] add new line in the end --- sonar-project.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonar-project.properties b/sonar-project.properties index 1fe93502..849a9bef 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,6 +2,6 @@ sonar.projectKey=Python-Tracer sonar.projectName=Python Tracer sonar.sourceEncoding=utf-8 sonar.sources=instana/**/* -sonar.exclusions=example/**/* +sonar.exclusions=tests/**/*, example/**/* sonar.tests=. -sonar.test.inclusions=tests/**/* \ No newline at end of file +sonar.test.inclusions=tests/**/* From c5aa1e0fafb37351a459d1000f10014e9f754586 Mon Sep 17 00:00:00 2001 From: dimitraparaskevopoulou Date: Thu, 23 Sep 2021 11:01:13 +0200 Subject: [PATCH 07/10] add new line in the end --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index 849a9bef..5e189de5 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,7 +1,7 @@ sonar.projectKey=Python-Tracer sonar.projectName=Python Tracer sonar.sourceEncoding=utf-8 -sonar.sources=instana/**/* +sonar.sources=. sonar.exclusions=tests/**/*, example/**/* sonar.tests=. sonar.test.inclusions=tests/**/* From f611bebf18632a2759a465663bbf5821019f9a09 Mon Sep 17 00:00:00 2001 From: dimitraparaskevopoulou Date: Thu, 23 Sep 2021 11:28:20 +0200 Subject: [PATCH 08/10] fixing Sonarqube Reliability bugs --- instana/instrumentation/django/middleware.py | 2 +- instana/instrumentation/flask/common.py | 4 ++-- instana/instrumentation/flask/vanilla.py | 6 +++--- instana/instrumentation/grpcio.py | 3 +-- instana/instrumentation/logging.py | 4 ++-- instana/instrumentation/pep0249.py | 3 +-- instana/instrumentation/redis.py | 4 ++-- instana/instrumentation/sqlalchemy.py | 3 +-- 8 files changed, 13 insertions(+), 16 deletions(-) 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) From 3385a8d525007334291e0512a3fd12b7526d69ad Mon Sep 17 00:00:00 2001 From: dimitraparaskevopoulou Date: Thu, 23 Sep 2021 11:51:14 +0200 Subject: [PATCH 09/10] switch the workflow to pull from master branch --- .github/workflows/sonarqube.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index 17ad53b6..fceaabde 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -2,7 +2,7 @@ name: Build on: push: branches: - - sonarqube_integration # or the name of your main branch + - master # or the name of your main branch pull_request: types: [opened, synchronize, reopened] jobs: From bd0297661e04830123bf4a39cbde905f17b2d9dc Mon Sep 17 00:00:00 2001 From: dimitraparaskevopoulou Date: Thu, 23 Sep 2021 15:41:15 +0200 Subject: [PATCH 10/10] remove log message which was causing an infinite loop when debug is on in PY2 --- instana/util/traceutils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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