fn hook_mysqli_connect()

in src/plugin/plugin_mysqli.rs [88:139]


    fn hook_mysqli_connect(
        &self, class_name: Option<&str>, function_name: &str, style: ApiStyle,
    ) -> (Box<BeforeExecuteHook>, Box<AfterExecuteHook>) {
        let class_name = class_name.map(ToOwned::to_owned);
        let function_name = function_name.to_owned();
        (
            Box::new(move |request_id, execute_data| {
                // Sometimes the connection is failed. Therefore, first assemble the peer from
                // the parameters to prevent assembly failure in the after hook.
                let peer = get_peer_by_parameters(execute_data, style);

                let span = create_mysqli_exit_span(
                    request_id,
                    class_name.as_deref(),
                    &function_name,
                    &peer,
                    style,
                )?;

                Ok(Box::new(span))
            }),
            Box::new(move |_, span, execute_data, return_value| {
                let mut span = span.downcast::<Span>().unwrap();

                // Reset the peer here, it should be more precise.
                if let Some(b) = return_value.as_bool() {
                    if !b {
                        span.span_object_mut().is_error = true;
                    }
                }
                if let Some(this) = return_value.as_mut_z_obj() {
                    if let Some(peer) = get_peer_by_this(this) {
                        span.span_object_mut().peer = peer;
                    }
                } else {
                    match style.get_this_mut(execute_data) {
                        Ok(this) => {
                            if let Some(peer) = get_peer_by_this(this) {
                                span.span_object_mut().peer = peer;
                            }
                        }
                        Err(err) => {
                            error!(?err, "reset peer failed");
                        }
                    }
                }

                log_exception(&mut *span);
                Ok(())
            }),
        )
    }