diff --git a/php_skywalking.h b/php_skywalking.h index 3d5248023b4b74e0634208a286f12d82f1c02ef2..c5c38e9689d373b3bebc7220d05b6a8b295c8d55 100644 --- a/php_skywalking.h +++ b/php_skywalking.h @@ -136,6 +136,7 @@ static char *generate_sw3(zend_long span_id, char *peer_host, char *operation_na static char *generate_sw6(zend_long span_id, char *peer_host, char *operation_name); static void generate_context(); static char *get_page_request_uri(); +static char *get_page_request_peer(); static void write_log( char *text); static void request_init(); static void zval_b64_encode(zval *out, char *in); diff --git a/skywalking.c b/skywalking.c index eed17bbf897213d2c5defa6e079668a8b934f795..9dc360338f80126b9e0573a04459b1e5b8226c17 100644 --- a/skywalking.c +++ b/skywalking.c @@ -518,6 +518,9 @@ static void generate_context() { zval *carrier = NULL; ContextCarrier *contextCarrier = NULL; + //http info +// zval *http_method = NULL; + zend_bool jit_initialization = PG(auto_globals_jit); if (jit_initialization) { @@ -526,6 +529,12 @@ static void generate_context() { zend_string_release(server_str); } carrier = zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_SERVER")); + +// http_method = zend_hash_str_find(Z_ARRVAL_P(carrier), "REQUEST_METHOD", sizeof("REQUEST_METHOD") - 1); +// if (http_method != NULL) { +// add_assoc_string(&SKYWALKING_G(context), "method", Z_STRVAL_P(http_method)); +// } + if (SKYWALKING_G(header_version) == 2) { zval *sw6; sw6 = zend_hash_str_find(Z_ARRVAL_P(carrier), "HTTP_SW6", sizeof("HTTP_SW6") - 1); @@ -661,6 +670,35 @@ static char *get_page_request_uri() { return uris; } +static char *get_page_request_peer() { + zval *carrier = NULL; + zval *request_host = NULL; + zval *request_port = NULL; + + char *peer = NULL; + size_t peer_l = 0; + + zend_bool jit_initialization = PG(auto_globals_jit); + + if (jit_initialization) { + zend_string *server_str = zend_string_init("_SERVER", sizeof("_SERVER") - 1, 0); + zend_is_auto_global(server_str); + zend_string_release(server_str); + } + carrier = zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_SERVER")); + + request_host = zend_hash_str_find(Z_ARRVAL_P(carrier), "SERVER_ADDR", sizeof("SERVER_ADDR") - 1); + request_port = zend_hash_str_find(Z_ARRVAL_P(carrier), "SERVER_PORT", sizeof("SERVER_PORT") - 1); + + if (request_host != NULL && request_port != NULL) { + peer_l = snprintf(NULL, 0, "%s:%s", Z_STRVAL_P(request_host), Z_STRVAL_P(request_port)); + peer = emalloc(peer_l + 1); + snprintf(peer, peer_l + 1, "%s:%s", Z_STRVAL_P(request_host), Z_STRVAL_P(request_port)); + } + + return peer; +} + /** * ip @@ -721,7 +759,10 @@ static void request_init() { add_assoc_long(&traceSegmentObject, "isSizeLimited", 0); zval temp; + char *peer = NULL; + array_init(&temp); + peer = get_page_request_peer(); add_assoc_long(&temp, "spanId", 0); add_assoc_long(&temp, "parentSpanId", -1); @@ -730,11 +771,21 @@ static void request_init() { efree(l_millisecond); add_assoc_long(&temp, "startTime", millisecond); add_assoc_string(&temp, "operationName", get_page_request_uri()); - add_assoc_string(&temp, "peer", ""); + add_assoc_string(&temp, "peer", (peer == NULL) ? "" : peer); add_assoc_long(&temp, "spanType", 0); add_assoc_long(&temp, "spanLayer", 3); add_assoc_long(&temp, "componentId", COMPONENT_HTTPCLIENT); + if (peer != NULL) { + efree(peer); + } + +// zval *method = NULL; +// method = zend_hash_str_find(Z_ARRVAL(SKYWALKING_G(context)), "method", sizeof("method") - 1); +// if (method != NULL) { +// add_assoc_string(&temp, "method", Z_STRVAL_P(method)); +// } + zval *isChild = zend_hash_str_find(Z_ARRVAL_P(&SKYWALKING_G(context)), "isChild", sizeof("isChild") - 1); // refs zval refs; diff --git a/src/report/report_client.cpp b/src/report/report_client.cpp index 9522abe898e87c1d28161b5f0f1ebf9827bd021d..dc4f7e91a9c8be4f135e6f474c0324e8a7b32298 100644 --- a/src/report/report_client.cpp +++ b/src/report/report_client.cpp @@ -252,9 +252,6 @@ int main(int argc, char **argv) { spanObject->set_endtime(spans[i]["endTime"]); spanObject->set_operationname(spans[i]["operationName"]); std::string peer(spans[i]["peer"].get()); - if(!peer.empty()) { - spanObject->set_peer(peer); - } int spanType = spans[i]["spanType"].get(); if (spanType == 0) { @@ -265,6 +262,10 @@ int main(int argc, char **argv) { spanObject->set_spantype(SpanType::Exit); } + if(spanType == 1 && !peer.empty()) { + spanObject->set_peer(peer); + } + int spanLayer = spans[i]["spanLayer"].get(); if (spanLayer == 3) { spanObject->set_spanlayer(SpanLayer::Http);