Skip to content

Commit

Permalink
APM instrumentation improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jade-vogt committed Sep 17, 2023
1 parent 91f3b14 commit 6df7e87
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>best.tigers</groupId>
<artifactId>tigersbot</artifactId>
<version>1.3.1</version>
<version>1.3.2</version>
<properties>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/best/tigers/tigersbot/handlers/GptHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import best.tigers.tigersbot.error.MissingEnvironmentVariableException;
import best.tigers.tigersbot.services.CompletionService;
import co.elastic.apm.api.ElasticApm;
import com.pengrad.telegrambot.TelegramBot;
import com.pengrad.telegrambot.model.Message;

Expand All @@ -25,10 +26,18 @@ public void handle(Message message) {
return;
}
if (message.text().startsWith("/gpt4 ")) {
showTypingIndicator();
var prompt = message.text().split("/gpt4 ")[1].strip();
var completion = completionService.getAdvancedCompletion(prompt, message.from().username());
sendReplyMessage(message, completion);
var span = ElasticApm.currentTransaction().startSpan("external", "openai", "chatcompletion");
try {
showTypingIndicator();
var prompt = message.text().split("/gpt4 ")[1].strip();
var completion = completionService.getAdvancedCompletion(prompt, message.from().username());
sendReplyMessage(message, completion);
} catch (Throwable e) {
span.captureException(e);
throw e;
} finally {
span.end();
}
return;
}
if (message.text().startsWith("/pissed ")) {
Expand Down

0 comments on commit 6df7e87

Please sign in to comment.