From d0041614f8928d1cf6253702df8c32aea8cb02fb Mon Sep 17 00:00:00 2001 From: Kirill Romanov Date: Tue, 9 Jul 2024 20:12:22 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=20Sentry=20=D0=BF=D0=BB=D0=B0=D0=B3?= =?UTF-8?q?=D0=B8=D0=BD=20=D0=B4=D0=BB=D1=8F=20ktor=20client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../djaler/evilbot/config/RestConfig.kt | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/github/djaler/evilbot/config/RestConfig.kt b/src/main/kotlin/com/github/djaler/evilbot/config/RestConfig.kt index 13672dc..15b02f0 100644 --- a/src/main/kotlin/com/github/djaler/evilbot/config/RestConfig.kt +++ b/src/main/kotlin/com/github/djaler/evilbot/config/RestConfig.kt @@ -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 @@ -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()) + } + ) + } +}