Skip to content

Commit 0e962cc

Browse files
committed
Fix issue, where span status is incorrect in case of error
1 parent bffa2a9 commit 0e962cc

File tree

1 file changed

+13
-7
lines changed
  • instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal

1 file changed

+13
-7
lines changed

instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt

+13-7
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,25 @@ object KtorServerTelemetryUtil {
4040
if (context != null) {
4141
call.attributes.put(contextKey, context)
4242
withContext(context.asContextElement()) {
43-
try {
44-
proceed()
45-
} catch (err: Throwable) {
46-
// Stash error for reporting later since need ktor to finish setting up the response
47-
call.attributes.put(errorKey, err)
48-
throw err
49-
}
43+
proceed()
5044
}
5145
} else {
5246
proceed()
5347
}
5448
}
5549

50+
val errorPhase = PipelinePhase("OpenTelemetryError")
51+
application.insertPhaseBefore(ApplicationCallPipeline.Monitoring, errorPhase)
52+
application.intercept(errorPhase) {
53+
try {
54+
proceed()
55+
} catch (err: Throwable) {
56+
// Stash error for reporting later since need ktor to finish setting up the response
57+
call.attributes.put(errorKey, err)
58+
throw err
59+
}
60+
}
61+
5662
val postSendPhase = PipelinePhase("OpenTelemetryPostSend")
5763
application.sendPipeline.insertPhaseAfter(ApplicationSendPipeline.After, postSendPhase)
5864
application.sendPipeline.intercept(postSendPhase) {

0 commit comments

Comments
 (0)