Skip to content

Commit c72df01

Browse files
committed
feat: Add extra tags to Sentry and modernize SentryReporterAdapter
- Add email to user context - instance_url for context (especially useful for cron job issues) - instance_name for extra context Signed-off-by: Thomas Citharel <tcit@tcit.fr>
1 parent f18a699 commit c72df01

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/Reporter/SentryReporterAdapter.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Exception;
2828
use OCA\Sentry\Helper\CredentialStoreHelper;
2929
use OCP\Authentication\Exceptions\CredentialsUnavailableException;
30+
use OCP\Defaults;
3031
use OCP\IConfig;
3132
use OCP\ILogger;
3233
use OCP\IUserSession;
@@ -43,14 +44,11 @@
4344

4445
class SentryReporterAdapter implements IMessageReporter, ICollectBreadcrumbs, ISentryReporter {
4546

46-
/** @var IUserSession */
47-
protected $userSession;
48-
49-
/** @var CredentialStoreHelper */
50-
private $credentialStoreHelper;
51-
52-
/** @var bool */
53-
private $userScopeSet = false;
47+
protected IUserSession $userSession;
48+
private CredentialStoreHelper $credentialStoreHelper;
49+
private IConfig $config;
50+
private Defaults $defaults;
51+
private bool $userScopeSet = false;
5452

5553
/** @var array mapping of log levels */
5654
private const levels = [
@@ -61,15 +59,16 @@ class SentryReporterAdapter implements IMessageReporter, ICollectBreadcrumbs, IS
6159
ILogger::FATAL => Severity::FATAL,
6260
];
6361

64-
/** @var int */
65-
private $minimumLogLevel;
62+
private int $minimumLogLevel;
6663

6764
public function __construct(IUserSession $userSession,
6865
IConfig $config,
69-
CredentialStoreHelper $credentialStoreHelper) {
66+
CredentialStoreHelper $credentialStoreHelper, Defaults $defaults) {
7067
$this->userSession = $userSession;
68+
$this->config = $config;
7169
$this->minimumLogLevel = (int)$config->getSystemValue('sentry.minimum.log.level', ILogger::WARN);
7270
$this->credentialStoreHelper = $credentialStoreHelper;
71+
$this->defaults = $defaults;
7372
}
7473

7574
/**
@@ -101,6 +100,9 @@ protected function setSentryScope(array $context): void {
101100
$scope->setTag('app', $context['app']);
102101
}
103102

103+
$scope->setTag('instance_url', $this->config->getSystemValueString('overwrite.cli.url'));
104+
$scope->setTag('instance_name', $this->defaults->getName());
105+
104106
if ($this->userScopeSet) {
105107
// Run the code below just once
106108
return;
@@ -119,6 +121,7 @@ protected function setSentryScope(array $context): void {
119121
$scope->setUser([
120122
'id' => $user->getUID(),
121123
'username' => $username,
124+
'email' => $user->getEMailAddress()
122125
]);
123126
}
124127
});

0 commit comments

Comments
 (0)