Skip to content

Commit

Permalink
Send extra data with every captureMessage to Sentry (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmiksche authored and felixkempf committed Nov 16, 2017
1 parent ea6f916 commit dbe07a1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ The `CakeMonitor` configuration section in your `app.php` must contain a `Sentry
$data['user']['id'] = '*****';
}
},
'extraDataCallback' => function() { # Extra data to send with every Sentry call. Works with SentryHandler::captureMessage() only!
if (!empty($_SESSION['Test'])) {
return $_SESSION['Test'];
}
}
]

In your `bootstrap.php` you have to tell CakePHP which ErrorHandler to use. Please find the following section:
Expand Down Expand Up @@ -155,4 +160,4 @@ Logging a message into sentry:
'result' => $result,
'status' => $status
]
]);
]);
3 changes: 2 additions & 1 deletion config/monitor.default.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
'enabled' => false,
'dsn' => null,
'sanitizeFields' => [],
'sanitizeExtraCallback' => null
'sanitizeExtraCallback' => null,
'extraDataCallback' => null
]
]
];
4 changes: 4 additions & 0 deletions src/Error/SentryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public function captureMessage($message, $params = [], $data = [], $stack = fals
return false;
}

if (is_callable(Configure::read('CakeMonitor.Sentry.extraDataCallback'))) {
$data['extra']['extraDataCallback'] = call_user_func(Configure::read('CakeMonitor.Sentry.extraDataCallback'));
}

return $this->_ravenClient->captureMessage($message, $params, $data, $stack, $vars);
}
}

0 comments on commit dbe07a1

Please sign in to comment.