From a8e9420de4e8ab0ce8de97133726425d5627320c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20V=C3=AEjial=C4=83?= Date: Sat, 28 Jan 2023 15:12:19 +0200 Subject: [PATCH] fix git version fetching --- .dockerignore | 2 +- .drone.yml | 6 ++++++ Dockerfile | 1 + snoop/data/celery.py | 2 +- snoop/data/tracing.py | 16 ++++++++++++---- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/.dockerignore b/.dockerignore index 178b8284..78d1e0f1 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,4 @@ -.git +# .git .cache blobs snoop/localsettings.py diff --git a/.drone.yml b/.drone.yml index af7137bb..ec16c37f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -22,8 +22,14 @@ depends_on: concurrency: limit: 1 +clone: + depth: 5000 steps: +- name: fetch + image: alpine/git + commands: + - git fetch --tags - name: GH CR build base docker image image: plugins/docker diff --git a/Dockerfile b/Dockerfile index ddb66e1b..f552098b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,6 +32,7 @@ ADD Pipfile Pipfile.lock ./ RUN pipenv install --system --deploy --ignore-pipfile COPY . . +COPY .git . RUN chmod +x /opt/hoover/snoop/docker-entrypoint.sh ENV THREAD_COUNT 20 diff --git a/snoop/data/celery.py b/snoop/data/celery.py index 8c3b63b4..4e3c1f9a 100644 --- a/snoop/data/celery.py +++ b/snoop/data/celery.py @@ -9,7 +9,7 @@ from celery import Celery from celery.signals import worker_process_init -from hoover.search.tracing import init_tracing +from snoop.data.tracing import init_tracing os.environ.setdefault("DJANGO_SETTINGS_MODULE", "snoop.defaultsettings") diff --git a/snoop/data/tracing.py b/snoop/data/tracing.py index d6715313..21534b67 100644 --- a/snoop/data/tracing.py +++ b/snoop/data/tracing.py @@ -20,7 +20,7 @@ # from opentelemetry.instrumentation.celery import CeleryInstrumentor SERVICE_NAME = "hoover-snoop" -SERVICE_VERSION = subprocess.check_output("git describe --tags", shell=True).decode().strip() +SERVICE_VERSION = subprocess.check_output("git describe --tags --always", shell=True).decode().strip() log = logging.getLogger(__name__) @@ -76,9 +76,17 @@ def span(self, *args, **kwds): finally: if we_are_first: log.debug('destroying tracer for module %s...', self.name) - trace.get_tracer_provider().force_flush() - trace.get_tracer_provider().shutdown() - local.tracer = None + try: + trace.get_tracer_provider().force_flush() + trace.get_tracer_provider().shutdown() + # the ProxyTracerProvider we get when no tracing is configured + # doesn't have these methods. + except AttributeError: + pass + except Exception as e: + log.warning('tracer shutdown exception: ' + str(e)) + finally: + local.tracer = None def wrap_function(self): """Returns a function wrapper that has a telemetry span around the function.