fn hook_mysqli_methods()

in src/plugin/plugin_mysqli.rs [141:181]


    fn hook_mysqli_methods(
        &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| {
                let this = style.get_this_mut(execute_data)?;
                let handle = this.handle();

                debug!(handle, class_name, function_name, "call mysqli method");

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

                if execute_data.num_args() >= 1 {
                    if let Some(statement) = execute_data.get_parameter(0).as_z_str() {
                        span.add_tag("db.statement", statement.to_str()?);
                    }
                }

                Ok(Box::new(span) as _)
            }),
            Box::new(move |_, span, _, return_value| {
                let mut span = span.downcast::<Span>().unwrap();
                if let Some(b) = return_value.as_bool() {
                    if !b {
                        span.span_object_mut().is_error = true;
                    }
                }
                log_exception(&mut *span);
                Ok(())
            }),
        )
    }