Skip to content

Commit

Permalink
记录POST传参
Browse files Browse the repository at this point in the history
  • Loading branch information
kilingzhang committed Dec 22, 2021
1 parent 74e2833 commit 1de3315
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ std::string find_server_string(const char *key, size_t len);

zval *find_server_zval(const char *key, size_t len);

zval *get_post_zval();

/**
*
* @return
Expand Down
9 changes: 9 additions & 0 deletions src/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,15 @@ void start_tracer(std::string traceparent, std::string tracebaggage, opentelemet
std::string request_remote_ip = find_server_string("REMOTE_ADDR", sizeof("REMOTE_ADDR") - 1);

set_string_attribute(span->add_attributes(), "http.method", request_method);

//记录POST传参数
if (is_equal(request_method, "POST")) {
zval *post = get_post_zval();
if (post) {
set_string_attribute(span->add_attributes(), "http.params", opentelemetry_json_encode(post));
}
}

set_string_attribute(span->add_attributes(), "http.host", request_http_host);
set_string_attribute(span->add_attributes(), "http.target", request_uri);
set_string_attribute(span->add_attributes(), "http.client_ip", request_remote_ip);
Expand Down
10 changes: 10 additions & 0 deletions src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ zval *find_server_zval(const char *key, size_t len) {
return server_value;
}

zval *get_post_zval() {
zend_bool jit_initialization = PG(auto_globals_jit);
if (jit_initialization) {
zend_string *str = zend_string_init("_POST", sizeof("_POST") - 1, 0);
zend_is_auto_global(str);
zend_string_release(str);
}
return zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_POST"));
}

boost::uuids::uuid generate_span_id() {
return boost::uuids::random_generator()();
}
Expand Down

0 comments on commit 1de3315

Please sign in to comment.