Commit b2dc9371 authored by mark burdett's avatar mark burdett
Browse files

Issue #3254091 by mfb: Can we send additional data to Sentry?

parent 34895485
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -150,19 +150,38 @@ catch (\Exception $e) {
}
```

See the raven.api.php file for documentation of the Raven hooks mentioned above,
which allow you to modify Sentry events and breadcrumbs created through the
Drupal logger.

You can find documentation for Sentry at:

 * https://docs.sentry.io/platforms/php/

For example, to add context:
For example, to add context to all future events:

```
\Sentry\configureScope(function (\Sentry\State\Scope $scope): void {
  $scope->setUser(['language' => 'es']);
  $scope->setTag('interesting', 'yes');
  $scope->setContext('character', [
    'name' => 'Mighty Fighter',
    'age' => 19,
    'attack_type' => 'melee'
  ]);
});
```

Or, to add context only to events sent to Sentry in the current scope, wrap your
code inside the \Sentry\withScope() function.

Breadcrumbs can be added via \Sentry\addBreadcrumb().

You can also create an event processor to enrich each Sentry event with context.
See the various integrations included with Sentry SDK and Raven module for
examples.


TROUBLESHOOTING
---------------

+6 −4
Original line number Diff line number Diff line
@@ -37,16 +37,18 @@ function hook_raven_breadcrumb_alter(array &$breadcrumb) {
 * Alter or suppress log messages before they are sent to Sentry.
 *
 * This hook can be used to alter the captured data before sending to Sentry.
 * The message can be ignored by setting $filter['process'] to FALSE.
 * The message can be ignored by setting $filter['process'] to FALSE. The Sentry
 * event can be modified by calling \Sentry\Event methods on $filter['event'],
 * e.g. $filter['event']->setTags(), $filter['event']->setContext(), etc.
 *
 * @param array $filter
 *   The parameters passed to the \Drupal\raven\Logger::log() method, as well as
 *   the object that will be passed to the \Sentry\captureEvent() method:
 *   the \Sentry\Event that will be passed to the \Sentry\captureEvent() method:
 *   - level: The log level passed to \Drupal\raven\Logger::log().
 *   - message: The log message passed to \Drupal\raven\Logger::log().
 *   - context: The original context array passed to Logger::log().
 *   - event: The event object to be passed to \Sentry\captureEvent().
 *   - client: The Raven client object.
 *   - event: The \Sentry\Event object to be passed to \Sentry\captureEvent().
 *   - client: The \Sentry\Client object.
 *   - process: If FALSE, the message will not be sent to Sentry.
 *
 * @see \Drupal\raven\Logger\Raven::log()