Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<namespace>Sentry</namespace>
<types>
<authentication/>
<dav/>
</types>
<documentation>
<admin>https://github.com/ChristophWurst/nextcloud_sentry/blob/master/doc/admin.md</admin>
Expand All @@ -28,4 +29,9 @@
<commands>
<command>OCA\Sentry\Command\Test</command>
</commands>
<sabre>
<plugins>
<plugin>OCA\Sentry\DAV\PerformanceMonitoringPlugin</plugin>
</plugins>
</sabre>
</info>
65 changes: 65 additions & 0 deletions lib/DAV/PerformanceMonitoringPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

/*
* @copyright 2024 Julius Knorr <jus@bitgrid.net>
*
* @author 2024 Julius Knorr <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace OCA\Sentry\DAV;

use Sabre\DAV\Server;
use Sabre\Dav\ServerPlugin;
use Sentry\SentrySdk;
use Sentry\Tracing\SpanStatus;
use Sentry\Tracing\Transaction;
use Sentry\Tracing\TransactionContext;
use function Sentry\startTransaction;

class PerformanceMonitoringPlugin extends ServerPlugin {

private Server $server;
private ?Transaction $transaction = null;

public function initialize(Server $server) {
$this->server = $server;

$this->server->on('method:*', [$this, 'beforeMethod']);
$this->server->on('afterMethod:*', [$this, 'afterMethod']);
}

public function beforeMethod($method) {
$partParts = explode('/', $method->getPath());
$serviceName = array_shift($partParts);
$name = $method->getMethod() . '::' . $serviceName;
$transactionContext = new TransactionContext();
$transactionContext->setName($name);
$transactionContext->setOp('http.request');
$this->transaction = startTransaction($transactionContext);
SentrySdk::getCurrentHub()->setSpan($this->transaction);
}

public function afterMethod($method) {
if ($this->transaction !== null) {
$this->transaction->setStatus(SpanStatus::ok());
$this->transaction->finish();
}
}
}
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<issueHandlers>
<UndefinedClass>
<errorLevel type="suppress">
<referencedClass name="Sabre\Dav\Server" />
<referencedClass name="Sabre\Dav\ServerPlugin" />
<referencedClass name="Symfony\Component\Console\Command\Command" />
</errorLevel>
</UndefinedClass>
Expand Down
Loading