From 84be9fd318aebe92b0fb4f30735970191cb405c1 Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Thu, 18 May 2023 10:18:17 +0100 Subject: [PATCH] Include float container info in trace, if present --- ai_web_common/flask_ai/tracing.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/ai_web_common/flask_ai/tracing.py b/ai_web_common/flask_ai/tracing.py index 7ce636a..1765403 100644 --- a/ai_web_common/flask_ai/tracing.py +++ b/ai_web_common/flask_ai/tracing.py @@ -6,7 +6,8 @@ from opentelemetry import trace from opentelemetry.exporter.zipkin.json import ZipkinExporter from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor -from opentelemetry.sdk.resources import SERVICE_NAME, HOST_NAME, Resource +from opentelemetry.sdk.resources import Resource, \ + SERVICE_NAME, HOST_NAME, CONTAINER_NAME, CONTAINER_IMAGE_NAME, CONTAINER_IMAGE_TAG tracing_config_file = os.getenv('TRACING_CONFIG', '/etc/tracing/client.conf') @@ -21,10 +22,24 @@ def setup_tracing(service_name): if 'report_url' not in config: return False - resource = Resource(attributes={ + default_resource_attributes = { SERVICE_NAME: service_name, HOST_NAME: socket.gethostname(), - }) + } + if os.getenv('FLOAT_SERVICE'): + default_resource_attributes['float.service'] = os.getenv('FLOAT_SERVICE') + if os.getenv('FLOAT_INSTANCE_NAME'): + default_resource_attributes['float.instance'] = os.getenv('FLOAT_INSTANCE_NAME') + if os.getenv('FLOAT_CONTAINER_NAME'): + default_resource_attributes[CONTAINER_NAME] = os.getenv('FLOAT_CONTAINER_NAME') + if os.getenv('FLOAT_CONTAINER_IMAGE'): + image_name, tag = os.getenv('FLOAT_CONTAINER_IMAGE'), 'latest' + if ':' in image_name: + image_name, tag = image_name.split(':', 1) + default_resource_attributes[CONTAINER_IMAGE_NAME] = image_name + default_resource_attributes[CONTAINER_IMAGE_TAG] = tag + + resource = Resource(attributes=default_resource_attributes) zipkin_exporter = ZipkinExporter(endpoint=config['report_url']) -- GitLab