Skip to content

Commit 97aa76b

Browse files
Add logging to all GraphQL mutations (#3721)
All mutations are currently untraceable, making debugging difficult. This PR adds basic logging to each of our existing mutations to resolve this.
1 parent c6c69b9 commit 97aa76b

22 files changed

Lines changed: 81 additions & 0 deletions

app/GraphQL/Mutations/ChangeGlobalRole.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Enums\GlobalRole;
88
use App\Exceptions\GraphQLMutationException;
99
use App\Models\User;
10+
use Illuminate\Support\Facades\Log;
1011
use Illuminate\Support\Facades\Validator;
1112
use Illuminate\Validation\Rule;
1213
use Illuminate\Validation\ValidationException;
@@ -55,6 +56,8 @@ public function __invoke(null $_, array $args): self
5556
$userToChange->admin = $args['role'] === GlobalRole::ADMINISTRATOR;
5657
$userToChange->save();
5758

59+
Log::info("User {$user->id} changed global role to {$args['role']->value} for user {$userToChange->id}.");
60+
5861
$this->user = $userToChange;
5962

6063
return $this;

app/GraphQL/Mutations/ChangeProjectRole.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\Models\Project;
1010
use App\Models\User;
1111
use Exception;
12+
use Illuminate\Support\Facades\Log;
1213
use Illuminate\Support\Facades\Validator;
1314
use Illuminate\Validation\Rule;
1415

@@ -65,6 +66,8 @@ public function __invoke(null $_, array $args): self
6566
},
6667
]);
6768

69+
Log::info("User {$user->id} changed role to {$args['role']->value} for user {$userToChange->id} in project {$project->id}.");
70+
6871
if ($rowsEdited !== 1) {
6972
throw new Exception('Failed to update pivot table with new role.');
7073
}

app/GraphQL/Mutations/ClaimSite.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Exceptions\GraphQLMutationException;
88
use App\Models\Site;
99
use App\Models\User;
10+
use Illuminate\Support\Facades\Log;
1011

1112
final class ClaimSite extends AbstractMutation
1213
{
@@ -36,6 +37,8 @@ public function __invoke(null $_, array $args): self
3637

3738
$site->maintainers()->syncWithoutDetaching($user);
3839

40+
Log::info("User {$user->id} claimed site {$site->id}.");
41+
3942
$this->site = $site;
4043
$this->user = $user;
4144

app/GraphQL/Mutations/CreateAuthenticationToken.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Auth\AuthenticationException;
1111
use Illuminate\Support\Carbon;
1212
use Illuminate\Support\Facades\Gate;
13+
use Illuminate\Support\Facades\Log;
1314

1415
final class CreateAuthenticationToken extends AbstractMutation
1516
{
@@ -47,6 +48,13 @@ public function __invoke(null $_, array $args): self
4748
$args['expiration'],
4849
);
4950

51+
$logMessage = "User {$user->id} created authentication token with scope {$this->token->scope}";
52+
if ($this->token->projectid > 0) {
53+
$logMessage .= " for project {$this->token->projectid}";
54+
}
55+
56+
Log::info("$logMessage.");
57+
5058
return $this;
5159
}
5260
}

app/GraphQL/Mutations/CreateComment.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Models\Comment;
99
use Illuminate\Auth\AuthenticationException;
1010
use Illuminate\Support\Facades\Gate;
11+
use Illuminate\Support\Facades\Log;
1112

1213
final class CreateComment extends AbstractMutation
1314
{
@@ -41,6 +42,8 @@ public function __invoke(null $_, array $args): self
4142

4243
$this->comment = $comment->refresh();
4344

45+
Log::info("User {$user->id} left comment {$comment->id} on build {$build?->id}.");
46+
4447
return $this;
4548
}
4649
}

app/GraphQL/Mutations/CreateGlobalInvitation.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Exception;
1313
use Illuminate\Support\Carbon;
1414
use Illuminate\Support\Facades\Hash;
15+
use Illuminate\Support\Facades\Log;
1516
use Illuminate\Support\Facades\Mail;
1617
use Illuminate\Support\Facades\Validator;
1718
use Illuminate\Support\Str;
@@ -74,6 +75,8 @@ public function __invoke(null $_, array $args): self
7475
'password' => Hash::make($password),
7576
]);
7677

78+
Log::info("User {$user->id} invited user {$this->invitedUser->email} with role {$this->invitedUser->role->value}.");
79+
7780
// The email gets sent to the queue, so we have no way to know immediately whether it was sent or not.
7881
// TODO: We should eventually track whether the email was actually sent.
7982
Mail::to($args['email'])->send(new InvitedToCdash($this->invitedUser, $password));

app/GraphQL/Mutations/CreatePinnedTestMeasurement.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Models\PinnedTestMeasurement;
88
use App\Models\Project;
99
use Illuminate\Support\Facades\Gate;
10+
use Illuminate\Support\Facades\Log;
1011

1112
final class CreatePinnedTestMeasurement extends AbstractMutation
1213
{
@@ -35,6 +36,9 @@ public function __invoke(null $_, array $args): self
3536
'position' => $nextAvailablePosition,
3637
]);
3738

39+
$user = auth()->user();
40+
Log::info("User {$user?->id} created pinned test measurement {$this->pinnedTestMeasurement?->id} for project {$project?->id}.");
41+
3842
return $this;
3943
}
4044
}

app/GraphQL/Mutations/CreateProject.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Models\Project;
88
use App\Services\ProjectService;
99
use Illuminate\Support\Facades\Gate;
10+
use Illuminate\Support\Facades\Log;
1011

1112
class CreateProject
1213
{
@@ -27,6 +28,9 @@ public function __invoke(null $_, array $args): Project
2728
'role' => Project::PROJECT_ADMIN,
2829
]);
2930

31+
$user = auth()->user();
32+
Log::info("User {$user?->id} created project {$project->id}.");
33+
3034
return $project;
3135
}
3236
}

app/GraphQL/Mutations/CreateRepository.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Models\Project;
88
use App\Models\Repository;
99
use Illuminate\Support\Facades\Gate;
10+
use Illuminate\Support\Facades\Log;
1011

1112
final class CreateRepository extends AbstractMutation
1213
{
@@ -34,6 +35,9 @@ public function __invoke(null $_, array $args): self
3435
'branch' => $args['branch'],
3536
]);
3637

38+
$user = auth()->user();
39+
Log::info("User {$user?->id} created repository {$this->repository?->id} for project {$project?->id}.");
40+
3741
return $this;
3842
}
3943
}

app/GraphQL/Mutations/DeleteAuthenticationToken.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Models\AuthToken;
88
use App\Utils\AuthTokenUtil;
99
use Illuminate\Auth\AuthenticationException;
10+
use Illuminate\Support\Facades\Log;
1011

1112
final class DeleteAuthenticationToken extends AbstractMutation
1213
{
@@ -26,6 +27,8 @@ public function __invoke(null $_, array $args): self
2627
throw new AuthenticationException('This action is unauthorized.');
2728
}
2829

30+
Log::info("User {$userid} deleted authentication token {$args['tokenId']}.");
31+
2932
return $this;
3033
}
3134
}

0 commit comments

Comments
 (0)