Skip to content

Commit 1de3315

Browse files
author
kilingzhang
committed
记录POST传参
1 parent 74e2833 commit 1de3315

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

include/utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ std::string find_server_string(const char *key, size_t len);
9898

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

101+
zval *get_post_zval();
102+
101103
/**
102104
*
103105
* @return

src/core.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,15 @@ void start_tracer(std::string traceparent, std::string tracebaggage, opentelemet
274274
std::string request_remote_ip = find_server_string("REMOTE_ADDR", sizeof("REMOTE_ADDR") - 1);
275275

276276
set_string_attribute(span->add_attributes(), "http.method", request_method);
277+
278+
//记录POST传参数
279+
if (is_equal(request_method, "POST")) {
280+
zval *post = get_post_zval();
281+
if (post) {
282+
set_string_attribute(span->add_attributes(), "http.params", opentelemetry_json_encode(post));
283+
}
284+
}
285+
277286
set_string_attribute(span->add_attributes(), "http.host", request_http_host);
278287
set_string_attribute(span->add_attributes(), "http.target", request_uri);
279288
set_string_attribute(span->add_attributes(), "http.client_ip", request_remote_ip);

src/utils.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,16 @@ zval *find_server_zval(const char *key, size_t len) {
231231
return server_value;
232232
}
233233

234+
zval *get_post_zval() {
235+
zend_bool jit_initialization = PG(auto_globals_jit);
236+
if (jit_initialization) {
237+
zend_string *str = zend_string_init("_POST", sizeof("_POST") - 1, 0);
238+
zend_is_auto_global(str);
239+
zend_string_release(str);
240+
}
241+
return zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_POST"));
242+
}
243+
234244
boost::uuids::uuid generate_span_id() {
235245
return boost::uuids::random_generator()();
236246
}

0 commit comments

Comments
 (0)