Skip to content

Commit

Permalink
fix: реализован Sentry плагин для ktor client
Browse files Browse the repository at this point in the history
  • Loading branch information
Djaler committed Jul 9, 2024
1 parent 0d5d4e8 commit d004161
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions src/main/kotlin/com/github/djaler/evilbot/config/RestConfig.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.github.djaler.evilbot.config

import com.fasterxml.jackson.databind.ObjectMapper
import io.ktor.client.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.plugins.logging.*
import io.ktor.http.*
import io.ktor.serialization.jackson.*
import io.ktor.client.HttpClient
import io.ktor.client.plugins.HttpTimeout
import io.ktor.client.plugins.api.createClientPlugin
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.plugins.logging.LogLevel
import io.ktor.client.plugins.logging.Logging
import io.ktor.client.statement.bodyAsText
import io.ktor.client.statement.request
import io.ktor.http.ContentType
import io.ktor.serialization.jackson.JacksonConverter
import io.sentry.Breadcrumb
import io.sentry.Sentry
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

Expand All @@ -24,6 +30,33 @@ class RestConfig {
install(Logging) {
level = LogLevel.ALL
}

install(SentryPlugin)
}
}
}

val SentryPlugin = createClientPlugin("SentryPlugin") {
onRequest { request, content ->
Sentry.addBreadcrumb(
Breadcrumb.http(
request.url.toString(),
request.method.toString()
).apply {
setData("content", content)
}
)
}

onResponse {response ->
val request = response.request
Sentry.addBreadcrumb(
Breadcrumb.http(
request.url.toString(),
request.method.toString()
).apply {
setData("response", response.bodyAsText())
}
)
}
}

0 comments on commit d004161

Please sign in to comment.