Skip to content

Commit

Permalink
Instrument interaction callback types
Browse files Browse the repository at this point in the history
  • Loading branch information
schnapster committed Jan 15, 2025
1 parent 14002ee commit 8cda957
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/main/kotlin/dev/capybaralabs/shipa/ShipaMetrics.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.capybaralabs.shipa

import dev.capybaralabs.shipa.discord.interaction.model.InteractionResponse
import dev.capybaralabs.shipa.discord.millis
import io.micrometer.core.instrument.Counter
import io.micrometer.core.instrument.MeterRegistry
Expand Down Expand Up @@ -51,6 +52,18 @@ class ShipaMetrics(private val meterRegistry: MeterRegistry) {
.register(meterRegistry)
}

fun interactionCallbackTypes(interactionResponse: InteractionResponse): Counter {
return Counter
.builder("shipa.interaction.callback.types")
.description("The type of interaction response we respond with to the Discord webhooks")
.tags(
Tags.of(
Tag.of("type", interactionResponse.type.name),
),
)
.register(meterRegistry)
}

fun commandProcessTime(name: String, type: String): Timer {
return Timer
.builder("shipa.command.process.time")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ internal class InteractionController(

interactionScope.launchInteractionProcessing(interaction, initialResponse, totalTimer)
return result.asCompletableFuture()
.thenApply { ResponseEntity.ok().body(it) }
.orTimeout(3, SECONDS)
.thenApply {
metrics.interactionCallbackTypes(it).increment()
ResponseEntity.ok().body(it)
}
.orTimeout(3, SECONDS) // consider timing out based on Discord timestamp, not our own.
.exceptionallyCompose {
if (it is TimeoutException) {
CompletableFuture.failedFuture(TimeoutException("result Future timed out on interaction ${interaction.id}"))
Expand Down

0 comments on commit 8cda957

Please sign in to comment.