Skip to content

Commit 4df9ca5

Browse files
Merge pull request #700 from ChristophWurst/feat/dav
feat: Transactions for DAV
2 parents 52ac28f + 519fe30 commit 4df9ca5

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

appinfo/info.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<namespace>Sentry</namespace>
1313
<types>
1414
<authentication/>
15+
<dav/>
1516
</types>
1617
<documentation>
1718
<admin>https://github.com/ChristophWurst/nextcloud_sentry/blob/master/doc/admin.md</admin>
@@ -28,4 +29,9 @@
2829
<commands>
2930
<command>OCA\Sentry\Command\Test</command>
3031
</commands>
32+
<sabre>
33+
<plugins>
34+
<plugin>OCA\Sentry\DAV\PerformanceMonitoringPlugin</plugin>
35+
</plugins>
36+
</sabre>
3137
</info>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* @copyright 2024 Julius Knorr <jus@bitgrid.net>
7+
*
8+
* @author 2024 Julius Knorr <jus@bitgrid.net>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*/
25+
26+
namespace OCA\Sentry\DAV;
27+
28+
use Sabre\DAV\Server;
29+
use Sabre\Dav\ServerPlugin;
30+
use Sentry\SentrySdk;
31+
use Sentry\Tracing\SpanStatus;
32+
use Sentry\Tracing\Transaction;
33+
use Sentry\Tracing\TransactionContext;
34+
use function Sentry\startTransaction;
35+
36+
class PerformanceMonitoringPlugin extends ServerPlugin {
37+
38+
private Server $server;
39+
private ?Transaction $transaction = null;
40+
41+
public function initialize(Server $server) {
42+
$this->server = $server;
43+
44+
$this->server->on('method:*', [$this, 'beforeMethod']);
45+
$this->server->on('afterMethod:*', [$this, 'afterMethod']);
46+
}
47+
48+
public function beforeMethod($method) {
49+
$partParts = explode('/', $method->getPath());
50+
$serviceName = array_shift($partParts);
51+
$name = $method->getMethod() . '::' . $serviceName;
52+
$transactionContext = new TransactionContext();
53+
$transactionContext->setName($name);
54+
$transactionContext->setOp('http.request');
55+
$this->transaction = startTransaction($transactionContext);
56+
SentrySdk::getCurrentHub()->setSpan($this->transaction);
57+
}
58+
59+
public function afterMethod($method) {
60+
if ($this->transaction !== null) {
61+
$this->transaction->setStatus(SpanStatus::ok());
62+
$this->transaction->finish();
63+
}
64+
}
65+
}

psalm.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<issueHandlers>
1818
<UndefinedClass>
1919
<errorLevel type="suppress">
20+
<referencedClass name="Sabre\Dav\Server" />
21+
<referencedClass name="Sabre\Dav\ServerPlugin" />
2022
<referencedClass name="Symfony\Component\Console\Command\Command" />
2123
</errorLevel>
2224
</UndefinedClass>

0 commit comments

Comments
 (0)