Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WordPress AutoInstrument: Skip WP Core #1032

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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;
}

}