You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2022/10/19 01:31:57 UTC
[skywalking-php] branch master updated: Take care of PDO false and DSN tailing semicolons. (#22)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-php.git
The following commit(s) were added to refs/heads/master by this push:
new 05a34e1 Take care of PDO false and DSN tailing semicolons. (#22)
05a34e1 is described below
commit 05a34e192ba78f2f62f96402c6dc469865c748ec
Author: phanalpha <ph...@hotmail.com>
AuthorDate: Wed Oct 19 09:31:52 2022 +0800
Take care of PDO false and DSN tailing semicolons. (#22)
---
config.m4 | 19 +++++++-----
src/plugin/plugin_pdo.rs | 20 +++++++++----
tests/data/expected_context.yaml | 63 ++++++++++++++++++++++++++++++++++++++++
tests/php/fpm/pdo.php | 8 +++++
4 files changed, 97 insertions(+), 13 deletions(-)
diff --git a/config.m4 b/config.m4
index eecf076..056b5a4 100644
--- a/config.m4
+++ b/config.m4
@@ -49,15 +49,18 @@ if test "$PHP_SKYWALKING_AGENT" != "no"; then
CARGO_MODE_DIR="debug"
fi
- echo -e "./modules/skywalking_agent.so:\n\
-\tPHP_CONFIG=$PHP_PHP_CONFIG cargo build $CARGO_MODE_FLAGS\n\
-\tif [[ -f ./target/$CARGO_MODE_DIR/libskywalking_agent.dylib ]] ; then \
-cp ./target/$CARGO_MODE_DIR/libskywalking_agent.dylib ./modules/skywalking_agent.so ; fi\n\
-\tif [[ -f ./target/$CARGO_MODE_DIR/libskywalking_agent.so ]] ; then \
-cp ./target/$CARGO_MODE_DIR/libskywalking_agent.so ./modules/skywalking_agent.so ; fi\n\
-" > Makefile.objects
+ cat >>Makefile.objects<< EOF
+all: cargo_build
- PHP_MODULES="./modules/skywalking_agent.so"
+cargo_build:
+ PHP_CONFIG=$PHP_PHP_CONFIG cargo build $CARGO_MODE_FLAGS
+ if [[ -f ./target/$CARGO_MODE_DIR/libskywalking_agent.dylib ]] ; then \\
+ cp ./target/$CARGO_MODE_DIR/libskywalking_agent.dylib ./modules/skywalking_agent.so ; fi
+ if [[ -f ./target/$CARGO_MODE_DIR/libskywalking_agent.so ]] ; then \\
+ cp ./target/$CARGO_MODE_DIR/libskywalking_agent.so ./modules/skywalking_agent.so ; fi
+
+.PHONY: cargo_build
+EOF
AC_CONFIG_LINKS([ \
.rustfmt.toml:.rustfmt.toml \
diff --git a/src/plugin/plugin_pdo.rs b/src/plugin/plugin_pdo.rs
index ad6eb85..cc43906 100644
--- a/src/plugin/plugin_pdo.rs
+++ b/src/plugin/plugin_pdo.rs
@@ -206,18 +206,24 @@ fn after_hook(
}
fn after_hook_when_false(this: &mut ZObj, span: &mut Span) -> anyhow::Result<()> {
- span.with_span_object_mut(|span| {
- span.is_error = true;
- });
-
let info = this.call("errorInfo", [])?;
let info = info.as_z_arr().context("errorInfo isn't array")?;
let state = get_error_info_item(info, 0)?.expect_z_str()?.to_str()?;
- let code = &get_error_info_item(info, 1)?.expect_long()?.to_string();
+ let code = {
+ let code = get_error_info_item(info, 1)?;
+ // PDOStatement::fetch
+ // In all cases, false is returned on failure or if there are no more rows.
+ if code.get_type_info().is_null() {
+ return Ok(());
+ }
+
+ &code.expect_long()?.to_string()
+ };
let error = get_error_info_item(info, 2)?.expect_z_str()?.to_str()?;
span.with_span_object_mut(|span| {
+ span.is_error = true;
span.add_log([("SQLSTATE", state), ("Error Code", code), ("Error", error)]);
});
@@ -288,6 +294,10 @@ impl FromStr for Dsn {
let ss = data_source.split(';');
for s in ss {
+ if s.is_empty() {
+ continue;
+ }
+
let mut kv = s.splitn(2, '=');
let k = kv.next().context("unknown key")?;
let v = kv.next().context("unknown value")?;
diff --git a/tests/data/expected_context.yaml b/tests/data/expected_context.yaml
index 2a6fc70..31910be 100644
--- a/tests/data/expected_context.yaml
+++ b/tests/data/expected_context.yaml
@@ -327,6 +327,69 @@ segmentItems:
key: db.statement,
value: "SELECT * FROM `mysql`.`user` WHERE `User` = :user",
}
+ - operationName: PDO->prepare
+ parentSpanId: 0
+ spanId: 5
+ spanLayer: Database
+ startTime: gt 0
+ endTime: gt 0
+ componentId: 8003
+ isError: false
+ spanType: Exit
+ peer: 127.0.0.1:3306
+ skipAnalysis: false
+ tags:
+ - { key: db.type, value: mysql }
+ - {
+ key: db.data_source,
+ value: "dbname=skywalking;host=127.0.0.1:3306;",
+ }
+ - {
+ key: db.statement,
+ value: "SELECT * FROM `mysql`.`user` WHERE `User` = :user",
+ }
+ - operationName: PDOStatement->execute
+ parentSpanId: 0
+ spanId: 6
+ spanLayer: Database
+ startTime: gt 0
+ endTime: gt 0
+ componentId: 8003
+ isError: false
+ spanType: Exit
+ peer: 127.0.0.1:3306
+ skipAnalysis: false
+ tags:
+ - { key: db.type, value: mysql }
+ - {
+ key: db.data_source,
+ value: "dbname=skywalking;host=127.0.0.1:3306;",
+ }
+ - {
+ key: db.statement,
+ value: "SELECT * FROM `mysql`.`user` WHERE `User` = :user",
+ }
+ - operationName: PDOStatement->fetchAll
+ parentSpanId: 0
+ spanId: 7
+ spanLayer: Database
+ startTime: gt 0
+ endTime: gt 0
+ componentId: 8003
+ isError: false
+ spanType: Exit
+ peer: 127.0.0.1:3306
+ skipAnalysis: false
+ tags:
+ - { key: db.type, value: mysql }
+ - {
+ key: db.data_source,
+ value: "dbname=skywalking;host=127.0.0.1:3306;",
+ }
+ - {
+ key: db.statement,
+ value: "SELECT * FROM `mysql`.`user` WHERE `User` = :user",
+ }
- operationName: GET:/pdo.php
parentSpanId: -1
spanId: 0
diff --git a/tests/php/fpm/pdo.php b/tests/php/fpm/pdo.php
index f35172c..d73d5c4 100644
--- a/tests/php/fpm/pdo.php
+++ b/tests/php/fpm/pdo.php
@@ -33,4 +33,12 @@ require_once dirname(__DIR__) . "/vendor/autoload.php";
Assert::same(count($rs), 2);
}
+{
+ $pdo = new PDO("mysql:dbname=skywalking;host=127.0.0.1:3306;", "root", "password");
+ $sth = $pdo->prepare("SELECT * FROM `mysql`.`user` WHERE `User` = :user", [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
+ $sth->execute(['user' => 'anon']);
+ $rs = $sth->fetchAll();
+ Assert::same(count($rs), 0);
+}
+
echo "ok";