You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by jm...@apache.org on 2023/03/30 01:40:56 UTC
[skywalking-php] branch master updated: Make the `SKYWALKING_AGENT_ENABLE` work in the request hook as well. (#61)
This is an automated email from the ASF dual-hosted git repository.
jmjoy 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 5919df2 Make the `SKYWALKING_AGENT_ENABLE` work in the request hook as well. (#61)
5919df2 is described below
commit 5919df284398c4b0f05a707938b7f6aacb1447f7
Author: jmjoy <jm...@apache.org>
AuthorDate: Thu Mar 30 09:40:51 2023 +0800
Make the `SKYWALKING_AGENT_ENABLE` work in the request hook as well. (#61)
---
Cargo.lock | 2 +-
Cargo.toml | 2 +-
dist-material/LICENSE | 2 +-
src/module.rs | 35 ++++++++++++++++++++++-------------
src/request.rs | 8 +++++++-
5 files changed, 32 insertions(+), 17 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 334d88c..51b8329 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2027,7 +2027,7 @@ dependencies = [
[[package]]
name = "skywalking-php"
-version = "0.4.0"
+version = "0.5.0-dev"
dependencies = [
"anyhow",
"axum",
diff --git a/Cargo.toml b/Cargo.toml
index 8a79856..3e2c970 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -21,7 +21,7 @@ members = [
[package]
name = "skywalking-php"
-version = "0.4.0"
+version = "0.5.0-dev"
authors = ["Apache Software Foundation", "jmjoy <jm...@apache.org>", "Yanlong He <he...@apache.org>"]
description = "Apache SkyWalking PHP Agent."
edition = "2021"
diff --git a/dist-material/LICENSE b/dist-material/LICENSE
index 95f794b..c6b6b54 100644
--- a/dist-material/LICENSE
+++ b/dist-material/LICENSE
@@ -224,7 +224,7 @@ The text of each license is the standard Apache 2.0 license.
https://crates.io/crates/prost-types/0.11.6 0.11.6 Apache-2.0
https://crates.io/crates/scripts/0.0.0 0.0.0 Apache-2.0
https://crates.io/crates/skywalking/0.6.0 0.6.0 Apache-2.0
- https://crates.io/crates/skywalking-php/0.4.0 0.4.0 Apache-2.0
+ https://crates.io/crates/skywalking-php/0.5.0-dev 0.5.0-dev Apache-2.0
https://crates.io/crates/sync_wrapper/0.1.1 0.1.1 Apache-2.0
========================================================================
diff --git a/src/module.rs b/src/module.rs
index 1848c35..4480d17 100644
--- a/src/module.rs
+++ b/src/module.rs
@@ -186,7 +186,13 @@ pub fn init() {
register_execute_functions();
}
-pub fn shutdown() {}
+pub fn shutdown() {
+ if !is_enable() {
+ return;
+ }
+
+ info!("Shutdowning skywalking agent");
+}
fn try_init_logger() -> anyhow::Result<()> {
let log_level = ini_get::<Option<&CStr>>(SKYWALKING_AGENT_LOG_LEVEL)
@@ -233,20 +239,23 @@ fn get_module_registry() -> &'static ZArr {
unsafe { ZArr::from_ptr(&sys::module_registry) }
}
-fn is_enable() -> bool {
- if !ini_get::<bool>(SKYWALKING_AGENT_ENABLE) {
- return false;
- }
+pub fn is_enable() -> bool {
+ static IS_ENABLE: Lazy<bool> = Lazy::new(|| {
+ if !ini_get::<bool>(SKYWALKING_AGENT_ENABLE) {
+ return false;
+ }
- let sapi = get_sapi_module_name().to_bytes();
+ let sapi = get_sapi_module_name().to_bytes();
- if sapi == b"fpm-fcgi" {
- return true;
- }
+ if sapi == b"fpm-fcgi" {
+ return true;
+ }
- if sapi == b"cli" && get_module_registry().exists("swoole") {
- return true;
- }
+ if sapi == b"cli" && get_module_registry().exists("swoole") {
+ return true;
+ }
- false
+ false
+ });
+ *IS_ENABLE
}
diff --git a/src/request.rs b/src/request.rs
index f7231fe..6a7a4e6 100644
--- a/src/request.rs
+++ b/src/request.rs
@@ -16,7 +16,7 @@
use crate::{
component::COMPONENT_PHP_ID,
context::RequestContext,
- module::SKYWALKING_VERSION,
+ module::{is_enable, SKYWALKING_VERSION},
util::{catch_unwind_result, get_sapi_module_name, z_val_to_string},
};
use anyhow::{anyhow, Context};
@@ -34,6 +34,9 @@ use tracing::{error, instrument, trace, warn};
#[instrument(skip_all)]
pub fn init() {
+ if !is_enable() {
+ return;
+ }
if get_sapi_module_name().to_bytes() == b"fpm-fcgi" {
if let Err(err) = catch_unwind_result(request_init_for_fpm) {
error!(mode = "fpm", ?err, "request init failed");
@@ -43,6 +46,9 @@ pub fn init() {
#[instrument(skip_all)]
pub fn shutdown() {
+ if !is_enable() {
+ return;
+ }
if get_sapi_module_name().to_bytes() == b"fpm-fcgi" {
if let Err(err) = catch_unwind_result(request_shutdown_for_fpm) {
error!(mode = "fpm", ?err, "request shutdown failed");