提交 75270060 编写于 作者: w60514603's avatar w60514603

支持mysqli扩展的监控;./configure --enable-mysqli=yes来启用对mysqli的监控支持

上级 79a72ee7
PHP_ARG_ENABLE(skywalking, whether to enable skywalking support,
[ --enable-skywalking Enable skywalking support])
PHP_ARG_ENABLE(mysqli, whether to enable mysqli support,
[ --enable-mysqli Enable mysqli support], no, no)
if test "$PHP_SKYWALKING" != "no"; then
PHP_NEW_EXTENSION(skywalking, \
skywalking.c \
......@@ -8,3 +11,7 @@ if test "$PHP_SKYWALKING" != "no"; then
encode.c \
, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
fi
if test "$PHP_MYSQLI" != "no"; then
AC_DEFINE(SKYWALKING_ENABLED_MYSQLI, 1, [Enable skywalking support])
fi
......@@ -249,6 +249,10 @@ ZEND_API void sky_execute_internal(zend_execute_data *execute_data, zval *return
zf->common.scope->name) : NULL;
const char *function_name = zf->common.function_name == NULL ? NULL : ZSTR_VAL(zf->common.function_name);
#ifdef SKYWALKING_ENABLED_MYSQLI
int is_mysqli_function = 0;
#endif
char *operationName = NULL;
char *component = NULL;
if (class_name != NULL) {
......@@ -274,7 +278,33 @@ ZEND_API void sky_execute_internal(zend_execute_data *execute_data, zval *return
strcat(operationName, function_name);
}
}
#ifdef SKYWALKING_ENABLED_MYSQLI
if (strcmp(class_name, "mysqli") == 0) {
if (strcmp(function_name, "query") == 0) {
component = (char *) emalloc(strlen("mysqli") + 1);
strcpy(component, "mysqli");
operationName = (char *) emalloc(strlen(class_name) + strlen(function_name) + 3);
strcpy(operationName, class_name);
strcat(operationName, "->");
strcat(operationName, function_name);
}
}
#endif
} else if (function_name != NULL) {
#ifdef SKYWALKING_ENABLED_MYSQLI
if (strcmp(function_name, "mysqli_query") == 0) {
class_name = "mysqli";
function_name = "query";
component = (char *) emalloc(strlen(class_name) + 1);
strcpy(component, class_name);
operationName = (char *) emalloc(strlen(class_name) + strlen(function_name) + 3);
strcpy(operationName, class_name);
strcat(operationName, "->");
strcat(operationName, function_name);
is_mysqli_function = 1;
}
#endif
}
if (operationName != NULL) {
......@@ -324,8 +354,27 @@ ZEND_API void sky_execute_internal(zend_execute_data *execute_data, zval *return
add_assoc_string(&tags, "db.data_source", (char *) stmt->dbh->data_source);
}
}
} else if (function_name != NULL) {
#ifdef SKYWALKING_ENABLED_MYSQLI
if (strcmp(class_name, "mysqli") == 0 && strcmp(function_name, "query") == 0) {
add_assoc_string(&tags, "db.type", "mysqli");
// params
uint32_t arg_count = ZEND_CALL_NUM_ARGS(execute_data);
if (arg_count) {
zval *p = is_mysqli_function ? ZEND_CALL_ARG(execute_data, 2) : ZEND_CALL_ARG(execute_data, 1);
//db.statement
switch (Z_TYPE_P(p)) {
case IS_STRING:
add_assoc_string(&tags, "db.statement", Z_STRVAL_P(p));
break;
}
}
}
#endif
}
zval temp;
zval *spans = NULL;
zval *span_id = NULL;
......@@ -1304,9 +1353,11 @@ PHP_MINIT_FUNCTION (skywalking) {
return SUCCESS;
}
// 用户自定义函数执行器(php脚本定义的类、函数)
ori_execute_ex = zend_execute_ex;
zend_execute_ex = sky_execute_ex;
// 内部函数执行器(c语言定义的类、函数)
ori_execute_internal = zend_execute_internal;
zend_execute_internal = sky_execute_internal;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册