Skip to content

Commit cc97b19

Browse files
authored
Store contextId to Sentry (if Sentry is available) (#20)
1 parent d1015a3 commit cc97b19

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/AnzuApp.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use AnzuSystems\Contracts\Exception\AppReadOnlyModeException;
99
use DateTimeImmutable;
1010
use RuntimeException;
11+
use Sentry\SentrySdk;
12+
use Sentry\State\Scope;
1113

1214
class AnzuApp
1315
{
@@ -89,7 +91,7 @@ public static function getUserIdConsole(): int
8991
public static function getContextId(): string
9092
{
9193
if ('' === self::$contextId) {
92-
self::$contextId = (string) uuid_create();
94+
self::setContextId((string) uuid_create());
9395
}
9496

9597
return self::$contextId;
@@ -98,6 +100,12 @@ public static function getContextId(): string
98100
public static function setContextId(string $contextId): void
99101
{
100102
self::$contextId = $contextId;
103+
104+
if (class_exists(SentrySdk::class)) {
105+
SentrySdk::getCurrentHub()->configureScope(function (Scope $scope) {
106+
$scope->setTag('contextId', self::$contextId);
107+
});
108+
}
101109
}
102110

103111
public static function getAppEnv(): string

0 commit comments

Comments
 (0)