Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public function getWrappedCallback()
*/
public function __invoke()
{
if ( ! $this->shouldInstrument() ) {
/** @phpstan-assert callable(mixed ...): mixed $this->callback */
return call_user_func_array( $this->callback, func_get_args() );
}

/** @phpstan-assert callable(mixed ...): mixed $this->callback */
return AutoInstrumentationUtil::captureCurrentSpan(
$this->hookName . ' - ' . ($this->callbackGroupName ?? WordPressAutoInstrumentation::SPAN_NAME_PART_FOR_CORE) /* <- name */,
Expand All @@ -102,4 +107,18 @@ public function __invoke()
1 /* <- numberOfStackFramesToSkip - 1 because we don't want the current method (i.e., WordPressFilterCallbackWrapper->__invoke) to be kept */
);
}

private function shouldInstrument()
{
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
return true;
}

if ( null !== $this->callbackGroupName && WordPressAutoInstrumentation::SPAN_NAME_PART_FOR_CORE !== $this->callbackGroupName ) {
return true;
}

return false;
}

}