Describe the bug
We are using opentelemetry to collect ktor metrics, and http_server_active_requests in many cases is a big and negative number
Steps to reproduce
- Define ktor routes which throws exception during or after respond:
get ("/error-during-send") {
call.respondBytesWriter {
throw IllegalArgumentException("exception occurred")
}
}
get ("/error-after-send") {
call.respondText("Ok")
throw IllegalArgumentException("exception occurred")
}
- Configure KtorServerTelemetry:
install(KtorServerTelemetry) {
setOpenTelemetry(openTelemetry)
Experimental.emitExperimentalTelemetry(this)
}
- Perform request to any of defined routes, as a result http_server_active_requests = -1
Expected behavior
http_server_active_requests is always >= 0
Actual behavior
KtorServerTelemetry is done via DefaultHttpServerInstrumenterBuilder and the needed metric is set here, the code for activeRequests looks good with valid +1 on start and -1 on end.
But I also found this bug with PR, which can be connected. The solution was to add .propagateOperationListenersToOnEnd() when InstrumenterBuilder is created
Shouldn't the same be done with DefaultHttpServerInstrumenterBuilder?
public InstrumenterBuilder<REQUEST, RESPONSE> instrumenterBuilder() {
SpanNameExtractor<? super REQUEST> spanNameExtractor =
spanNameExtractorTransformer.apply(httpSpanNameExtractorBuilder.build());
InstrumenterBuilder<REQUEST, RESPONSE> builder =
Instrumenter.<REQUEST, RESPONSE>builder(
openTelemetry, instrumentationName, spanNameExtractor)
.setSpanStatusExtractor(
statusExtractorTransformer.apply(HttpSpanStatusExtractor.create(attributesGetter)))
.addAttributesExtractor(httpAttributesExtractorBuilder.build())
.addAttributesExtractors(additionalExtractors)
.addContextCustomizer(httpServerRouteBuilder.build())
.addOperationMetrics(HttpServerMetrics.get())
.setSchemaUrl(SchemaUrls.V1_37_0);
if (emitExperimentalHttpServerTelemetry) {
builder
.addAttributesExtractor(HttpExperimentalAttributesExtractor.create(attributesGetter))
.addOperationMetrics(HttpServerExperimentalMetrics.get());
}
InstrumenterUtil.propagateOperationListenersToOnEnd(builder); // here
builderCustomizer.accept(builder);
return builder;
}
Javaagent or library instrumentation version
v3.3.0
Environment
No response
Additional context
No response
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.
Describe the bug
We are using opentelemetry to collect ktor metrics, and
http_server_active_requestsin many cases is a big and negative numberSteps to reproduce
Expected behavior
http_server_active_requestsis always >= 0Actual behavior
KtorServerTelemetryis done viaDefaultHttpServerInstrumenterBuilderand the needed metric is set here, the code foractiveRequestslooks good with valid +1 on start and -1 on end.But I also found this bug with PR, which can be connected. The solution was to add
.propagateOperationListenersToOnEnd()whenInstrumenterBuilderis createdShouldn't the same be done with
DefaultHttpServerInstrumenterBuilder?Javaagent or library instrumentation version
v3.3.0
Environment
No response
Additional context
No response
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding
+1orme too, to help us triage it. Learn more here.