MCPcopy Create free account
hub / github.com/apache/skywalking-php / hook_mysqli_connect

Method hook_mysqli_connect

src/plugin/plugin_mysqli.rs:88–139  ·  view source on GitHub ↗
(
        &self, class_name: Option<&str>, function_name: &str, style: ApiStyle,
    )

Source from the content-addressed store, hash-verified

86
87impl MySQLImprovedPlugin {
88 fn hook_mysqli_connect(
89 &self, class_name: Option<&str>, function_name: &str, style: ApiStyle,
90 ) -> (Box<BeforeExecuteHook>, Box<AfterExecuteHook>) {
91 let class_name = class_name.map(ToOwned::to_owned);
92 let function_name = function_name.to_owned();
93 (
94 Box::new(move |request_id, execute_data| {
95 // Sometimes the connection is failed. Therefore, first assemble the peer from
96 // the parameters to prevent assembly failure in the after hook.
97 let peer = get_peer_by_parameters(execute_data, style);
98
99 let span = create_mysqli_exit_span(
100 request_id,
101 class_name.as_deref(),
102 &function_name,
103 &peer,
104 style,
105 )?;
106
107 Ok(Box::new(span))
108 }),
109 Box::new(move |_, span, execute_data, return_value| {
110 let mut span = span.downcast::<Span>().unwrap();
111
112 // Reset the peer here, it should be more precise.
113 if let Some(b) = return_value.as_bool() {
114 if !b {
115 span.span_object_mut().is_error = true;
116 }
117 }
118 if let Some(this) = return_value.as_mut_z_obj() {
119 if let Some(peer) = get_peer_by_this(this) {
120 span.span_object_mut().peer = peer;
121 }
122 } else {
123 match style.get_this_mut(execute_data) {
124 Ok(this) => {
125 if let Some(peer) = get_peer_by_this(this) {
126 span.span_object_mut().peer = peer;
127 }
128 }
129 Err(err) => {
130 error!(?err, "reset peer failed");
131 }
132 }
133 }
134
135 log_exception(&mut *span);
136 Ok(())
137 }),
138 )
139 }
140
141 fn hook_mysqli_methods(
142 &self, class_name: Option<&str>, function_name: &str, style: ApiStyle,

Callers 1

hookMethod · 0.80

Calls 5

get_peer_by_parametersFunction · 0.85
create_mysqli_exit_spanFunction · 0.85
get_peer_by_thisFunction · 0.85
log_exceptionFunction · 0.85
get_this_mutMethod · 0.80

Tested by

no test coverage detected