From 295fd855252ae4815c23f222683c39bad424f8fd Mon Sep 17 00:00:00 2001 From: Adil Hafeez Date: Wed, 13 Nov 2024 17:11:35 -0800 Subject: [PATCH] fix tracing --- arch/Dockerfile | 1 + arch/docker-compose.dev.yaml | 1 + arch/docker-compose.e2e.yaml | 1 + arch/docker-compose.yaml | 2 ++ arch/stream_traces.py | 17 ++++++++--------- arch/supervisord.conf | 2 +- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/arch/Dockerfile b/arch/Dockerfile index 4fc39c50..0d96713c 100644 --- a/arch/Dockerfile +++ b/arch/Dockerfile @@ -28,5 +28,6 @@ COPY arch/supervisord.conf /etc/supervisor/conf.d/supervisord.conf COPY arch/stream_traces.py . RUN pip install requests +RUN touch /var/log/envoy.log ENTRYPOINT ["supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] diff --git a/arch/docker-compose.dev.yaml b/arch/docker-compose.dev.yaml index 134f3853..e9f49696 100644 --- a/arch/docker-compose.dev.yaml +++ b/arch/docker-compose.dev.yaml @@ -21,3 +21,4 @@ services: environment: - OPENAI_API_KEY=${OPENAI_API_KEY:?error} - MISTRAL_API_KEY=${MISTRAL_API_KEY:?error} + - OTEL_TRACING_HTTP_ENDPOINT=http://host.docker.internal:4318/v1/traces diff --git a/arch/docker-compose.e2e.yaml b/arch/docker-compose.e2e.yaml index 42195962..208dc1e7 100644 --- a/arch/docker-compose.e2e.yaml +++ b/arch/docker-compose.e2e.yaml @@ -16,3 +16,4 @@ services: environment: - OPENAI_API_KEY=${OPENAI_API_KEY:?error} - MISTRAL_API_KEY=${MISTRAL_API_KEY:?error} + - OTEL_TRACING_HTTP_ENDPOINT=http://host.docker.internal:4318/v1/traces diff --git a/arch/docker-compose.yaml b/arch/docker-compose.yaml index 05d2c05f..373ae46d 100644 --- a/arch/docker-compose.yaml +++ b/arch/docker-compose.yaml @@ -13,6 +13,8 @@ services: - ~/archgw_logs:/var/log/ env_file: - env.list + environment: + - OTEL_TRACING_HTTP_ENDPOINT=http://host.docker.internal:4318/v1/traces extra_hosts: - "host.docker.internal:host-gateway" healthcheck: diff --git a/arch/stream_traces.py b/arch/stream_traces.py index 87e8a3a6..f3b166fd 100644 --- a/arch/stream_traces.py +++ b/arch/stream_traces.py @@ -1,4 +1,5 @@ import os +import sys import time import requests import logging @@ -29,12 +30,10 @@ def process_log_line(line): logging.error(f"Failed to send trace to otel-tracing: {e}") -with open(envoy_log_path, "r") as f: - while True: - line = f.readline() - if not line: - time.sleep(1) - continue - tokens = line.split("gateway: upstream_llm trace details: ") - if len(tokens) > 1: - process_log_line(tokens[1]) +for line in sys.stdin: + if not line: + time.sleep(1) + continue + tokens = line.split("gateway: upstream_llm trace details: ") + if len(tokens) > 1: + process_log_line(tokens[1]) diff --git a/arch/supervisord.conf b/arch/supervisord.conf index 38175c85..da659e65 100644 --- a/arch/supervisord.conf +++ b/arch/supervisord.conf @@ -2,7 +2,7 @@ nodaemon=true [program:trace_streamer] -command=python stream_traces.py +command=sh -c "tail -F /var/log/envoy.log | python stream_traces.py" autostart=true autorestart=false startretries=3