• Resolved TJ

    (@trijammer)


    I’m successfully getting errors logged in Sentry through the plugin, but when trying to use custom Structured Data as per the plugin docs this isn’t coming through with the error. It appears Sentry may have changed their approach to this as their docs use $scope->setContext instead of $scope->setExtra though this method doesn’t work in this plugin.

    I’d appreciate any pointers on getting this data to flow through to Sentry.

    Here’s an example of the code used:

    $e = new Exception('Test exception');
    if ( function_exists( 'wp_sentry_safe' ) ) {
    	wp_sentry_safe(function (\Sentry\State\HubInterface $client) use ($e) {
    		$client->withScope(function (\Sentry\State\Scope $scope) use ($client, $e) {
    			$scope->setExtra('test_label', 'test_data');
    			$client->captureException($e);
    		});
    	});
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter TJ

    (@trijammer)

    For anyone hitting the same issue, I’ve found a solution. Use $scope->setContext, ensuring the second parameter is an associative array. For example:

    $e = new Exception('Test exception');
    if ( function_exists( 'wp_sentry_safe' ) ) {
    	wp_sentry_safe(function (\Sentry\State\HubInterface $client) use ($e) {
    		$client->withScope(function (\Sentry\State\Scope $scope) use ($client, $e) {
    			$scope->setContext('test_label', [
            'test_label' => 'test_data'
          ]);
    			$client->captureException($e);
    		});
    	});
    }
    Plugin Author stayallive

    (@stayallive)

    That was quick with your own answer ??

    But yes, setExtra is deprecated but technically still available but they might have chosen to not show that anymore in the UI.

    I’ve updated the example to use setContext luckily the link to the Sentry docs was up-to-date ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using Structured Context via $scope->setExtra’ is closed to new replies.