Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit a5ea367

Browse files
committed
Fix bugs
1 parent c170039 commit a5ea367

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/sky_execute.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void sky_execute_ex(zend_execute_data *execute_data) {
3939

4040
// swoole
4141
bool swoole = false;
42+
bool afterExec = true;
4243
zval *sw_response;
4344
if (SKY_IS_SWOOLE(function_name) || SKY_IS_HYPERF(class_name, function_name)) {
4445
uint32_t arg_count = ZEND_CALL_NUM_ARGS(execute_data);
@@ -73,13 +74,17 @@ void sky_execute_ex(zend_execute_data *execute_data) {
7374
} else if ((SKY_STRCMP(class_name, "Hyperf\\Guzzle\\CoroutineHandler") ||
7475
SKY_STRCMP(class_name, "Hyperf\\Guzzle\\PoolHandler")) &&
7576
SKY_STRCMP(function_name, "__invoke")) {
77+
afterExec = false;
7678
span = sky_plugin_hyperf_guzzle(execute_data, class_name, function_name);
7779
}
7880
}
7981

82+
8083
if (span != nullptr) {
81-
ori_execute_ex(execute_data);
82-
span->setEndTIme();
84+
if (afterExec) {
85+
ori_execute_ex(execute_data);
86+
span->setEndTIme();
87+
}
8388
} else {
8489
ori_execute_ex(execute_data);
8590
}

src/sky_plugin_hyperf_guzzle.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#include "sky_plugin_hyperf_guzzle.h"
1616
#include "php_skywalking.h"
1717
#include "segment.h"
18+
#include "sky_utils.h"
19+
20+
extern void (*ori_execute_ex)(zend_execute_data *execute_data);
1821

1922
Span *sky_plugin_hyperf_guzzle(zend_execute_data *execute_data, const std::string &class_name, const std::string &function_name) {
2023

@@ -55,11 +58,15 @@ Span *sky_plugin_hyperf_guzzle(zend_execute_data *execute_data, const std::strin
5558
std::string header = segment->createHeader(span);
5659
zval name, value;
5760
ZVAL_STRING(&name, "sw8");
58-
ZVAL_STRING(&value, header.c_str());
59-
zend_call_method(request, Z_OBJCE_P(request), nullptr, ZEND_STRL("withheader"), nullptr, 2, &name, &value);
60-
zval_dtor(&name);
61-
zval_dtor(&value);
61+
array_init(&value);
62+
add_index_string(&value, 0, header.c_str());
6263

64+
zval *headers = sky_read_property(request, "headers", 0);
65+
zval *headerNames = sky_read_property(request, "headerNames", 0);
66+
add_assoc_zval_ex(headers, ZEND_STRL("sw8"), &value);
67+
add_assoc_zval_ex(headerNames, ZEND_STRL("sw8"), &name);
68+
ori_execute_ex(execute_data);
69+
span->setEndTIme();
6370
return span;
6471
}
6572
}

0 commit comments

Comments
 (0)