Skip to content

Commit

Permalink
fix bug in flask
Browse files Browse the repository at this point in the history
  • Loading branch information
eeliu committed Mar 26, 2024
1 parent 0466210 commit 71bc0fd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 4 additions & 3 deletions common/src/test_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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);
Expand All @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion plugins/PY/pinpointPy/Flask/PinPointMiddleWare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down

0 comments on commit 71bc0fd

Please sign in to comment.