Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions lib/Reporter/SentryReporterAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Exception;
use OCA\Sentry\Helper\CredentialStoreHelper;
use OCP\Authentication\Exceptions\CredentialsUnavailableException;
use OCP\Defaults;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IUserSession;
Expand All @@ -43,14 +44,11 @@

class SentryReporterAdapter implements IMessageReporter, ICollectBreadcrumbs, ISentryReporter {

/** @var IUserSession */
protected $userSession;

/** @var CredentialStoreHelper */
private $credentialStoreHelper;

/** @var bool */
private $userScopeSet = false;
protected IUserSession $userSession;
private CredentialStoreHelper $credentialStoreHelper;
private IConfig $config;
private Defaults $defaults;
private bool $userScopeSet = false;

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

/** @var int */
private $minimumLogLevel;
private int $minimumLogLevel;

public function __construct(IUserSession $userSession,
IConfig $config,
CredentialStoreHelper $credentialStoreHelper) {
CredentialStoreHelper $credentialStoreHelper, Defaults $defaults) {
$this->userSession = $userSession;
$this->config = $config;
$this->minimumLogLevel = (int)$config->getSystemValue('sentry.minimum.log.level', ILogger::WARN);
$this->credentialStoreHelper = $credentialStoreHelper;
$this->defaults = $defaults;
}

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

$scope->setTag('instance_url', $this->config->getSystemValueString('overwrite.cli.url'));
$scope->setTag('instance_name', $this->defaults->getName());

if ($this->userScopeSet) {
// Run the code below just once
return;
Expand All @@ -119,6 +121,7 @@ protected function setSentryScope(array $context): void {
$scope->setUser([
'id' => $user->getUID(),
'username' => $username,
'email' => $user->getEMailAddress()
]);
}
});
Expand Down