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

Method hook_predis_execute_command

src/plugin/plugin_predis.rs:181–267  ·  view source on GitHub ↗
(
        &self, class_name: &str, _function_name: &str,
    )

Source from the content-addressed store, hash-verified

179
180impl PredisPlugin {
181 fn hook_predis_execute_command(
182 &self, class_name: &str, _function_name: &str,
183 ) -> (Box<BeforeExecuteHook>, Box<AfterExecuteHook>) {
184 let class_name = class_name.to_owned();
185 (
186 Box::new(move |request_id, execute_data| {
187 validate_num_args(execute_data, 1)?;
188
189 let function_name = execute_data
190 .get_parameter(0)
191 .as_z_str()
192 .and_then(|s| s.to_str().ok())
193 .unwrap_or("")
194 .to_string();
195
196 let cmd = function_name.to_uppercase();
197
198 if !REDIS_ALL_COMMANDS.contains(&*cmd) {
199 return Ok(Box::new(()));
200 }
201
202 let this = get_this_mut(execute_data)?;
203 let handle = this.handle();
204 let connection = this.call("getConnection", [])?;
205
206 let peer = Self::get_peer(connection)?;
207
208 let op = if REDIS_READ_COMMANDS.contains(&*cmd) {
209 Some("read")
210 } else if REDIS_WRITE_COMMANDS.contains(&*cmd) {
211 Some("write")
212 } else {
213 None
214 };
215
216 let key = op
217 .and_then(|_| execute_data.get_parameter(1).as_z_arr())
218 .and_then(|params| params.get(0))
219 .and_then(|key| key.as_z_str())
220 .and_then(|s| s.to_str().ok());
221
222 debug!(handle, cmd, key, op, "call redis command");
223
224 let mut span =
225 RequestContext::try_with_global_ctx(request_id, |ctx| {
226 Ok(ctx.create_exit_span(
227 &format!("{}->{}", class_name, &function_name,),
228 &peer,
229 ))
230 })?;
231
232 let span_object = span.span_object_mut();
233 span_object.set_span_layer(SpanLayer::Cache);
234 span_object.component_id = COMPONENT_PHP_PREDIS_ID;
235 span_object.add_tag(TAG_CACHE_TYPE, "redis");
236 span_object.add_tag(TAG_CACHE_CMD, cmd);
237 if let Some(op) = op {
238 span_object.add_tag(TAG_CACHE_OP, op);

Callers 1

hookMethod · 0.80

Calls 5

validate_num_argsFunction · 0.85
get_this_mutFunction · 0.85
log_exceptionFunction · 0.85
get_peerFunction · 0.70
create_exit_spanMethod · 0.45

Tested by

no test coverage detected