From 327ab5124c52a83c640214a4689b5643c5d3f171 Mon Sep 17 00:00:00 2001 From: xiongyao Date: Wed, 30 Apr 2025 17:04:12 +0800 Subject: [PATCH] optimize: keep use ext_logging.py request_id to log && rm intrude code to origin response --- api/app_factory.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/api/app_factory.py b/api/app_factory.py index 92665c62d9..9a077a34b2 100644 --- a/api/app_factory.py +++ b/api/app_factory.py @@ -1,4 +1,3 @@ -import json import logging import time @@ -7,7 +6,6 @@ from flask import request from configs import dify_config from contexts.wrapper import RecyclableContextVar from dify_app import DifyApp -from extensions.ext_logging import get_request_id # ---------------------------- @@ -27,21 +25,17 @@ def create_flask_app_with_configs() -> DifyApp: # add an unique identifier to each request RecyclableContextVar.increment_thread_recycles() - # log request data info - request_id = get_request_id() - try: if ( request.method.lower() == "post" and "application/json" in request.headers.get("content-type", "").lower() ): logging.info( - f"[before request]|request_id: {request_id}," - f" method: {request.method}, url: {request.url}, request_data: {request.get_json()}" + f"[before request]| method: " + f"{request.method}, url: {request.url}, request_data: {request.get_json()}" ) - else: - logging.info(f"[before request]|request_id: {request_id}, method: {request.method}, url: {request.url}") + logging.info(f"[before request]| method: {request.method}, url: {request.url}") except Exception as e: logging.info(f"before_request handler err {e}") @@ -50,10 +44,7 @@ def create_flask_app_with_configs() -> DifyApp: def add_extra_info(resp): obj = resp.get_json() if obj is not None and isinstance(obj, dict): - request_id = get_request_id() - obj["request_id"] = request_id - resp.set_data(json.dumps(obj)) - logging.info(f"[finish request]|request_id: {request_id}, response: {obj}") + logging.info(f"[finish request]|response: {obj}") return resp return dify_app