Skip to content

Commit

Permalink
Attempting to get metrics from okhttp and reactor for better code vis…
Browse files Browse the repository at this point in the history
…ibility
  • Loading branch information
NovaFox161 committed Apr 16, 2024
1 parent 8691408 commit a7a2505
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ allprojects {
implementation("ch.qos.logback.contrib:logback-json-classic:$logbackContribVersion")
implementation("ch.qos.logback.contrib:logback-jackson:$logbackContribVersion")
implementation("io.micrometer:micrometer-registry-prometheus")
implementation("io.projectreactor:reactor-core-micrometer")

// Google libs
implementation("com.google.api-client:google-api-client:$googleApiClientVersion")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import discord4j.common.JacksonResources
import io.micrometer.core.instrument.MeterRegistry
import io.micrometer.core.instrument.binder.okhttp3.OkHttpMetricsEventListener
import okhttp3.OkHttpClient
import org.dreamexposure.discal.core.serializers.DurationMapper
import org.dreamexposure.discal.core.serializers.SnowflakeMapper
Expand Down Expand Up @@ -31,7 +33,13 @@ class BeanConfig {
}

@Bean
fun httpClient(): OkHttpClient {
return OkHttpClient()
fun httpClient(registry: MeterRegistry): OkHttpClient {
return OkHttpClient.Builder()
.eventListener(
OkHttpMetricsEventListener.builder(registry, "okhttp.requests")
// This does allow for cardinality explosion... unsure how I want to deal with that?
.uriMapper { it.url.encodedPath }
.build()
).build()
}
}

0 comments on commit a7a2505

Please sign in to comment.