From 71bc0fd7df795f15193f3d6547f06b445bca05f9 Mon Sep 17 00:00:00 2001 From: "liu.mingyi" <27064129+eeliu@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:03:42 +0800 Subject: [PATCH] fix bug in flask --- common/src/test_common.cc | 7 ++++--- plugins/PY/pinpointPy/Flask/PinPointMiddleWare.py | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/common/src/test_common.cc b/common/src/test_common.cc index 874e2475d..b6bf9b660 100644 --- a/common/src/test_common.cc +++ b/common/src/test_common.cc @@ -7,7 +7,7 @@ using namespace testing; std::string ouputMsg; -void cc_log_error_cb(char* msg) { ouputMsg += msg; } +void cc_log_error_cb(const char* msg) { ouputMsg = msg; } TEST(common, uid_all_in_one) { @@ -21,8 +21,7 @@ TEST(common, uid_all_in_one) { } TEST(common, start_end_trace) { - pinpoint_set_agent("tcp:127.0.0.1:9999", 7000, -1, 7000); - + register_span_handler(cc_log_error_cb); NodeID id = pinpoint_start_trace(E_ROOT_NODE); mark_current_trace_status(id, E_OFFLINE); EXPECT_EQ(pinpoint_trace_is_root(id), 1); @@ -46,6 +45,8 @@ TEST(common, start_end_trace) { mark_current_trace_status(1024, E_TRACE_BLOCK); catch_error(-1024, "sdfasfas", "fsafdsfasd", 234); catch_error(0, "sdfasfas", "fsafdsfasd", 234); + EXPECT_TRUE(ouputMsg.find("ERR") != std::string::npos); + // pp_trace("%s", ouputMsg.c_str()); } TEST(common, context_check) { diff --git a/plugins/PY/pinpointPy/Flask/PinPointMiddleWare.py b/plugins/PY/pinpointPy/Flask/PinPointMiddleWare.py index 4c253c955..6a75f80b8 100644 --- a/plugins/PY/pinpointPy/Flask/PinPointMiddleWare.py +++ b/plugins/PY/pinpointPy/Flask/PinPointMiddleWare.py @@ -18,7 +18,7 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- from pinpointPy.Defines import PP_HTTP_STATUS_CODE, PP_URL_TEMPLATED -from pinpointPy.pinpoint import add_trace_header_v2, add_trace_header +from pinpointPy.pinpoint import add_trace_header_v2, add_trace_header, mark_as_error from pinpointPy.Flask.FlaskPlugins import BaseFlaskPlugins from flask import request import sys @@ -43,6 +43,10 @@ def mark_status_code(response): if response: add_trace_header_v2(PP_HTTP_STATUS_CODE, str(response.status), trace_id) + # fix bug in https://oss.navercorp.com/pinpoint/pinpoint_c_agent/issues/570 + if response.status >= 400: + mark_as_error( + f'status_code:{response.status}', 'FastAPIRequestPlugin', 0, trace_id) return response @BaseFlaskPlugins("Flask Web App")