Skip to content

Commit a01524f

Browse files
committed
chore: misc fixes
1 parent 6491532 commit a01524f

File tree

4 files changed

+31
-26
lines changed

4 files changed

+31
-26
lines changed

backend/jvm/src/main/kotlin/dev/suresh/plugins/Http.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import io.ktor.server.sessions.*
2525
import io.ktor.server.sse.*
2626
import io.ktor.server.websocket.*
2727
import kotlin.concurrent.atomics.AtomicLong
28-
import kotlin.concurrent.atomics.incrementAndFetch
2928
import kotlin.time.Duration
3029
import kotlin.time.Duration.Companion.seconds
3130
import org.slf4j.event.Level
@@ -93,16 +92,16 @@ fun Application.configureHTTP() {
9392

9493
install(HSTS)
9594

96-
install(CallId) {
97-
header(HttpHeaders.XRequestId)
98-
generate {
99-
when (it.isApi) {
100-
true -> "$TRACE_ID-${counter.incrementAndFetch()}"
101-
else -> "$TRACE_ID-00000"
102-
}
103-
}
104-
verify { it.isNotEmpty() }
105-
}
95+
// install(CallId) {
96+
// header(HttpHeaders.XRequestId)
97+
// generate {
98+
// when (it.isApi) {
99+
// true -> "$TRACE_ID-${counter.incrementAndFetch()}"
100+
// else -> "$TRACE_ID-00000"
101+
// }
102+
// }
103+
// verify { it.isNotEmpty() }
104+
// }
106105

107106
install(CallLogging) {
108107
level = Level.INFO
@@ -111,7 +110,7 @@ fun Application.configureHTTP() {
111110

112111
// Add MDC entries
113112
mdc("remoteHost") { call -> call.request.origin.remoteHost }
114-
callIdMdc(TRACE_ID)
113+
// callIdMdc(TRACE_ID)
115114

116115
// Enable logging for API routes only
117116
filter { it.isApi }

backend/jvm/src/main/resources/logback.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<!--<include resource="logback-include.xml"/>-->
1313

1414
<property name="pattern"
15-
value="%date{yyyy-MM-dd'T'HH:mm:ss.SSS z, America/Los_Angeles} %X{trace-id} %-5level %X{remoteHost} [%thread] %logger{16} - %msg%n%rEx"/>
15+
value="%date{yyyy-MM-dd'T'HH:mm:ss.SSS z, America/Los_Angeles} %-5level %X{remoteHost} [%thread] %logger{16} - %msg%n%rEx"/>
1616

1717
<property name="otel-pattern"
1818
value="%date{yyyy-MM-dd'T'HH:mm:ss.SSS z, America/Los_Angeles} trace_id=%X{trace_id} span_id=%X{span_id} trace_flags=%X{trace_flags} %-5level %logger{16} - %msg%n"/>

backend/jvm/src/main/resources/otel/sdk-config.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,13 @@ instrumentation:
369369
# https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/logback/logback-appender-1.0/javaagent
370370
logback-appender:
371371
enabled: true
372-
experimental-log-attributes: false
372+
experimental-log-attributes: true
373373
experimental:
374374
capture-code-attributes: false
375-
capture-marker-attributes: false
375+
capture-marker-attributes: true
376376
capture-key-value-pair-attributes: false
377377
capture-logger-context-attributes: false
378378
capture-arguments: false
379-
capture-mdc-attributes: false
379+
capture-mdc-attributes: true
380380
ktor:
381-
# Disable default ktor instrumentation.
382-
enabled: false
381+
enabled: true

backend/jvm/src/test/kotlin/dev/suresh/AppTests.kt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@ import io.ktor.server.testing.*
2121
import kotlinx.coroutines.slf4j.MDCContext
2222
import kotlinx.coroutines.test.runTest
2323
import kotlinx.coroutines.withContext
24-
import kotlinx.serialization.SerialName
25-
import kotlinx.serialization.Serializable
24+
import kotlinx.serialization.*
2625
import org.junit.jupiter.api.condition.EnabledIfSystemProperty
27-
import org.slf4j.LoggerFactory
28-
import org.slf4j.MDC
29-
import org.testcontainers.containers.GenericContainer
30-
import org.testcontainers.containers.PostgreSQLContainer
26+
import org.slf4j.*
27+
import org.testcontainers.containers.*
3128
import org.testcontainers.containers.output.Slf4jLogConsumer
3229
import org.testcontainers.containers.wait.strategy.Wait
3330
import org.testcontainers.images.builder.Transferable
@@ -65,8 +62,18 @@ class AppTests {
6562

6663
@Test
6764
fun appTest() = testApplication {
65+
val infoLogs = mutableListOf<String>()
66+
val errorLogs = mutableListOf<String>()
67+
6868
environment {
69-
log = logger
69+
log = object : Logger by logger{
70+
override fun info(msg: String) {
71+
infoLogs += msg
72+
}
73+
override fun error(msg: String) {
74+
errorLogs += msg
75+
}
76+
}
7077
config = MapApplicationConfig("ktor.environment" to "test")
7178
}
7279

@@ -170,7 +177,7 @@ class AppTests {
170177
it.start()
171178
val endPoint = "https://${it.host}:${it.getMappedPort(tlsPort)}/"
172179
val statusCode = testHttpClient.get(endPoint).status
173-
assertTrue(statusCode.value == 200)
180+
assertEquals(statusCode.value, 200)
174181
}
175182
}
176183

0 commit comments

Comments
 (0)