Skip to content

Commit 3d6ae40

Browse files
committed
Add exception handling plugin to Ktor HTTP server test
This commit installs a route-scoped plugin that may mask exceptions from OpenTelemetry, if the latter is configured at the wrong phase
1 parent 0e962cc commit 3d6ae40

File tree

1 file changed

+10
-0
lines changed
  • instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0

1 file changed

+10
-0
lines changed

instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpServerTest.kt

+10
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55

66
package io.opentelemetry.instrumentation.ktor.v3_0
77

8+
import io.ktor.http.HttpStatusCode
89
import io.ktor.server.application.*
10+
import io.ktor.server.application.hooks.CallFailed
11+
import io.ktor.server.response.respondText
912
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension
1013
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension
14+
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
1115
import org.junit.jupiter.api.extension.RegisterExtension
1216

1317
class KtorHttpServerTest : AbstractKtorHttpServerTest() {
@@ -27,6 +31,12 @@ class KtorHttpServerTest : AbstractKtorHttpServerTest() {
2731
capturedRequestHeaders(TEST_REQUEST_HEADER)
2832
capturedResponseHeaders(TEST_RESPONSE_HEADER)
2933
}
34+
35+
install(createRouteScopedPlugin("Failure handler, that can mask exceptions if exception handling is in the wrong phase", ServerEndpoint.EXCEPTION.path, {}) {
36+
on(CallFailed) { call, cause ->
37+
call.respondText("failure: ${cause.message}", status = HttpStatusCode.InternalServerError)
38+
}
39+
})
3040
}
3141
}
3242
}

0 commit comments

Comments
 (0)