Title: Using Structured Context via $scope-&gt;setExtra
Last modified: September 12, 2023

---

# Using Structured Context via $scope->setExtra

 *  Resolved [TJ](https://wordpress.org/support/users/trijammer/)
 * (@trijammer)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/using-structured-context-via-scope-setextra/)
 * I’m successfully getting errors logged in Sentry through the plugin, but when
   trying to use custom Structured Data [as per the plugin docs](https://github.com/stayallive/wp-sentry/tree/0a94932ca94b03f168fdbc138b1dede963381d5f#capturing-handled-exceptions)
   this isn’t coming through with the error. It appears Sentry may have changed 
   their approach to this as [their docs](https://docs.sentry.io/platforms/php/enriching-events/context/#structured-context)
   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:
 *     ```wp-block-code
       $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](https://wordpress.org/support/users/trijammer/)
 * (@trijammer)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/using-structured-context-via-scope-setextra/#post-17043057)
 * For anyone hitting the same issue, I’ve found a solution. Use `$scope->setContext`,
   ensuring the second parameter is an associative array. For example:
 *     ```wp-block-code
       $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](https://wordpress.org/support/users/stayallive/)
 * (@stayallive)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/using-structured-context-via-scope-setextra/#post-17043355)
 * 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.

 * ![](https://ps.w.org/wp-sentry-integration/assets/icon-256x256.jpg?rev=1772463)
 * [Sentry for WordPress](https://wordpress.org/plugins/wp-sentry-integration/)
 * [Support Threads](https://wordpress.org/support/plugin/wp-sentry-integration/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-sentry-integration/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-sentry-integration/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-sentry-integration/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [stayallive](https://wordpress.org/support/users/stayallive/)
 * Last activity: [2 years, 8 months ago](https://wordpress.org/support/topic/using-structured-context-via-scope-setextra/#post-17043355)
 * Status: resolved