feat(ktor): add Ktor client tracing instrumentation - #14090
Open
cj848 wants to merge 6 commits into
Open
Conversation
|
|
cj848
marked this pull request as ready for review
August 2, 2026 11:16
cj848
force-pushed
the
feat/ktor-client-plugin
branch
from
August 2, 2026 22:57
524bf27 to
b39d612
Compare
Instrument io.ktor.client.plugins.HttpSend$DefaultSender.execute for Ktor client outbound calls. Each call produces a KTOR_CLIENT span event with propagation headers, plus a KTOR_CLIENT_INTERNAL async span event completed when the suspending continuation resumes. Retry attempts via HttpRequestRetry emit one span event per attempt. The behaviour mirrors a custom plugin maintained outside this repo in production deployments. Disabled by default via -Dprofiler.ktor.client.enable=true.
Adds KTOR_CLIENT=1900 and KTOR_CLIENT_INTERNAL=1901 to KtorConstants so the client interceptor can label span events with its own ServiceType instead of re-using the shared OK_HTTP_CLIENT slot.
Declares KTOR_CLIENT (1900, recordStatistics) and KTOR_CLIENT_INTERNAL (1901, matcher on http.status.code annotation 46) so the agent TraceMetadataProviderLoader registers both types at boot.
The client transform targets io.ktor.client.plugins.HttpSend$DefaultSender and io.ktor.client.request.HttpRequestBuilder, so the ktor client core artifact is needed at provided scope alongside the existing server deps. kotlinx-coroutines-core-jvm moves to provided too because SuspendFunctionGunInterceptor constructs a CoroutineScope receiver.
Adds profiler.ktor.client.enable / .param / .mark.error to the README so operators know the outbound tracing is opt-in.
- KtorPluginConfigTest: client flag defaults / overrides - KtorClientHeaderAdaptorTest: set/get/contains round-trip - KtorClientRequestAdaptorTest: destinationId, URL, IPv6, empty-host - KtorClientCoroutineSuspendedMarkerTest: Kotlin suspension marker - KtorClientContinuationConstructorInterceptorTest: pending holder attach/skip - KtorClientContinuationInterceptorTest: resume / suspend / error / accessor cleanup - KtorClientParentTraceStateTest: finish-once semantics + close-on-record-failure - KtorClientTraceAccessorTest: set/get round-trip - KtorClientTraceStorageTest: ThreadLocal isolation Skipped KtorClientSendInterceptor and KtorClientTraceHolder — they need a real Pinpoint agent registry (ServiceTypeProvider) which is only booted in an agent runtime; an integration that drives the real naver-pinpoint-agent tarball plus a suspended HttpRequestRetry continuation is a follow-up if upstream wants one.
cj848
force-pushed
the
feat/ktor-client-plugin
branch
from
August 2, 2026 23:18
b39d612 to
14c0192
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Add outbound-call tracing for Ktor HTTP client (
io.ktor.client.plugins.HttpSend$DefaultSender.execute(...)) to the built-in ktor plugin.KTOR_CLIENTspan event with propagation headers.KTOR_CLIENT_INTERNALasync span event, completed when the suspending continuation resumes.HttpRequestRetryemit one span event per attempt (each retry is a distinct remote call).-Dprofiler.ktor.client.enable=true.Needs review
KTOR_CLIENT=1900/KTOR_CLIENT_INTERNAL=1901in type-provider.yml. Move them if upstream prefers a different slot.naver-pinpoint-agenttarball plus a suspendedHttpRequestRetrycontinuation) is possible but needs the upstream IT harness; happy to add as a follow-up PR if desired.Open questions
profiler.ktor.client.enabledefault flip to true once this lands?Refs: https://pinpoint-apm.github.io/pinpoint/plugindevguide.html