4
4
import java .util .List ;
5
5
import java .util .Map ;
6
6
import java .util .Optional ;
7
- import java .util .stream .Collectors ;
7
+
8
+ import jakarta .inject .Inject ;
8
9
9
10
import org .jboss .logging .Logger ;
10
11
import org .kohsuke .github .GHEventPayload ;
22
23
import com .github .rvesse .airline .parser .ParseResult ;
23
24
import com .github .rvesse .airline .parser .errors .handlers .CollectAll ;
24
25
26
+ import io .quarkiverse .githubapp .GitHubEvent ;
25
27
import io .quarkiverse .githubapp .command .airline .AirlineInject ;
26
28
import io .quarkiverse .githubapp .command .airline .CommandOptions .DefaultExecutionErrorHandlerMarker ;
27
29
import io .quarkiverse .githubapp .command .airline .ExecutionErrorHandler ;
30
32
import io .quarkiverse .githubapp .command .airline .ParseErrorHandler .ParseErrorContext ;
31
33
import io .quarkiverse .githubapp .command .airline .runtime .util .Commandline ;
32
34
import io .quarkiverse .githubapp .command .airline .runtime .util .Reactions ;
35
+ import io .quarkiverse .githubapp .runtime .telemetry .opentelemetry .OpenTelemetryAttributes .CommandErrorType ;
36
+ import io .quarkiverse .githubapp .telemetry .TelemetryMetricsReporter ;
37
+ import io .quarkiverse .githubapp .telemetry .TelemetryTracesReporter ;
33
38
import io .quarkus .arc .Arc ;
34
39
import io .quarkus .arc .InstanceHandle ;
35
40
@@ -43,6 +48,11 @@ public abstract class AbstractCommandDispatcher<C> {
43
48
private final Map <String , CommandPermissionConfig > commandPermissionConfigs ;
44
49
private final Map <String , CommandTeamConfig > commandTeamConfigs ;
45
50
51
+ @ Inject
52
+ TelemetryTracesReporter openTelemetryTracesReporter ;
53
+ @ Inject
54
+ TelemetryMetricsReporter openTelemetryMetricsReporter ;
55
+
46
56
protected AbstractCommandDispatcher (Class <?> cliClass , CliConfig cliConfig ) {
47
57
ParserBuilder <C > parserBuilder = new ParserBuilder <C >();
48
58
parserBuilder .withCommandFactory (new ArcCommandFactory <>());
@@ -62,7 +72,8 @@ protected AbstractCommandDispatcher(Class<?> cliClass, CliConfig cliConfig) {
62
72
63
73
protected abstract Map <String , CommandTeamConfig > getCommandTeamConfigs ();
64
74
65
- protected Optional <CommandExecutionContext <C >> getCommand (GHEventPayload .IssueComment issueCommentPayload ) {
75
+ protected Optional <CommandExecutionContext <C >> getCommand (GitHubEvent gitHubEvent ,
76
+ GHEventPayload .IssueComment issueCommentPayload ) {
66
77
String body = issueCommentPayload .getComment ().getBody ();
67
78
68
79
if (body == null || body .isBlank ()) {
@@ -86,7 +97,7 @@ protected Optional<CommandExecutionContext<C>> getCommand(GHEventPayload.IssueCo
86
97
commandLine = Commandline .translateCommandline (firstLine );
87
98
commandLine .remove (0 );
88
99
} catch (IllegalArgumentException e ) {
89
- handleParseError (issueCommentPayload , firstLine , null , e .getMessage ());
100
+ handleParseError (gitHubEvent , issueCommentPayload , firstLine , null , e .getMessage ());
90
101
91
102
if (cliConfig .getDefaultCommandConfig ().getReactionStrategy ().reactionOnError ()) {
92
103
Reactions .createReaction (issueCommentPayload , ReactionContent .CONFUSED );
@@ -116,6 +127,10 @@ protected Optional<CommandExecutionContext<C>> getCommand(GHEventPayload.IssueCo
116
127
if (commandConfig .getReactionStrategy ().reactionOnError ()) {
117
128
Reactions .createReaction (issueCommentPayload , ReactionContent .MINUS_ONE );
118
129
}
130
+ openTelemetryTracesReporter .reportCommandMethodError (gitHubEvent , commandClassName , firstLine ,
131
+ CommandErrorType .PERMISSION_ERROR , null );
132
+ openTelemetryMetricsReporter .incrementCommandMethodError (gitHubEvent , commandClassName ,
133
+ CommandErrorType .PERMISSION_ERROR , null );
119
134
return Optional .empty ();
120
135
}
121
136
@@ -134,7 +149,7 @@ protected Optional<CommandExecutionContext<C>> getCommand(GHEventPayload.IssueCo
134
149
Reactions .createReaction (issueCommentPayload , ReactionContent .CONFUSED );
135
150
}
136
151
137
- handleParseError (issueCommentPayload , firstLine , parseResult , null );
152
+ handleParseError (gitHubEvent , issueCommentPayload , firstLine , parseResult , null );
138
153
139
154
return Optional .empty ();
140
155
}
@@ -169,7 +184,7 @@ private boolean hasPermission(CommandPermissionConfig commandPermissionConfig,
169
184
170
185
List <GHTeam > matchingTeams = repository .getTeams ().stream ()
171
186
.filter (t -> commandTeamConfig .getTeams ().contains (t .getSlug ()))
172
- .collect ( Collectors . toList () );
187
+ .toList ();
173
188
174
189
for (GHTeam matchingTeam : matchingTeams ) {
175
190
if (matchingTeam .hasMember (user )) {
@@ -195,7 +210,7 @@ private CommandConfig getBestCommandConfigInErrorState(ParseResult<C> parseResul
195
210
cliConfig .getDefaultCommandConfig ());
196
211
}
197
212
198
- protected void handleParseError (IssueComment issueCommentPayload , String command ,
213
+ protected void handleParseError (GitHubEvent gitHubEvent , IssueComment issueCommentPayload , String command ,
199
214
ParseResult <C > parseResult , String error ) {
200
215
Class <? extends ParseErrorHandler > parseErrorHandlerClass = cliConfig .getParseErrorHandler ();
201
216
@@ -209,9 +224,14 @@ protected void handleParseError(IssueComment issueCommentPayload, String command
209
224
parseErrorHandlerInstance .get ().handleParseError (issueCommentPayload ,
210
225
new ParseErrorContext (cliConfig , cli , command , parseResult , error ));
211
226
}
227
+
228
+ openTelemetryTracesReporter .reportCommandMethodError (gitHubEvent , null , command , CommandErrorType .PARSE_ERROR ,
229
+ error );
230
+ openTelemetryMetricsReporter .incrementCommandMethodError (gitHubEvent , null , CommandErrorType .PARSE_ERROR ,
231
+ error );
212
232
}
213
233
214
- protected void handleExecutionError (GHEventPayload .IssueComment issueCommentPayload ,
234
+ protected void handleExecutionError (GitHubEvent gitHubEvent , GHEventPayload .IssueComment issueCommentPayload ,
215
235
CommandExecutionContext <C > commandExecutionContext , Exception exception ) {
216
236
Class <? extends ExecutionErrorHandler > executionErrorHandlerClass = commandExecutionContext .getCommandConfig ()
217
237
.getExecutionErrorHandler ();
@@ -232,6 +252,21 @@ protected void handleExecutionError(GHEventPayload.IssueComment issueCommentPayl
232
252
executionErrorHandlerInstance .get ().handleExecutionError (issueCommentPayload ,
233
253
new ExecutionErrorContext (commandExecutionContext , exception ));
234
254
}
255
+
256
+ openTelemetryTracesReporter .reportCommandMethodError (gitHubEvent ,
257
+ commandExecutionContext .getCommand ().getClass ().getName (), commandExecutionContext .getCommandLine (),
258
+ CommandErrorType .EXECUTION_ERROR , exception .getMessage ());
259
+ openTelemetryMetricsReporter .incrementCommandMethodError (gitHubEvent ,
260
+ commandExecutionContext .getCommand ().getClass ().getName (), CommandErrorType .EXECUTION_ERROR ,
261
+ exception .getMessage ());
262
+ }
263
+
264
+ protected void handleSuccess (GitHubEvent gitHubEvent , GHEventPayload .IssueComment issueCommentPayload ,
265
+ CommandExecutionContext <C > commandExecutionContext ) {
266
+ openTelemetryTracesReporter .reportCommandMethodSuccess (gitHubEvent ,
267
+ commandExecutionContext .getCommand ().getClass ().getName (), commandExecutionContext .getCommandLine ());
268
+ openTelemetryMetricsReporter .incrementCommandMethodSuccess (gitHubEvent ,
269
+ commandExecutionContext .getCommand ().getClass ().getName ());
235
270
}
236
271
237
272
public static class CommandExecutionContext <C > {
0 commit comments