Allow overriding per-request sampling decision when tracing OkHttp requests
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- kotlin
- Domain
- mobile-dev, observability-sre
Research direction
Start at the OkHttp TracingInterceptor and its existing traceSampler API, then inspect how per-request sampling and the x-datadog-sampling-priority header are handled. Define the public override behavior for Sample, Ignore, and UseDefault, and verify that request tracing follows those choices independently of the fallback sampling rate.
Written by the indexing model from the issue text.
Description
Are you requesting automatic instrumentation for a framework or library? Please describe.
- Framework or library name:
OkHttp - Library type: networking
- Library version: 4.12.0
Is your feature request related to a problem? Please describe.
To debug a specific issue, I'd like to dynamically decide to trace all requests of a given type/endpoint. Currently I can pass traceSampler to a TracingInterceptor, but it only allows providing dynamic sampling rate.
Describe the solution you'd like
I'd like a clear API to override whether a request should be traced, regardless of the default/fallback sampling rate, something like:
TracingInterceptor(
perRequestSampler = { request: okhttp3.Request ->
if (shouldSample(request)) {
Sampler.Sample
} else if (shouldIgnore(request)) {
Sampler.Ignore
} else {
Sampler.UseDefault
}
}
)
Describe alternatives you've considered
Currently I'm using a custom interceptor added before the TracingInterceptor:
Interceptor { chain ->
val request = chain.request().let { request ->
if (forceSample(request)) {
request.newBuilder()
.addHeader("x-datadog-sampling-priority", "${PrioritySampling.USER_KEEP}")
.build()
} else {
request
}
}
chain.proceed(request)
},
This approach seems to work but:
- it requires adding the interceptor in the right place (before the
TracingInterceptor) or else it will silently not work - I couldn't find any documentation for
x-datadog-sampling-priorityheader. There are two constants in the code with this string but both are internal, suggesting it shouldn't be used by the consumers. I also couldn't find any documentation suggesting thatPrioritySamplingconstants should be used as the values for that header, so generally this feels like an implementation detail that may break with the SDK updates.
Additional context
- Dominant language
- Kotlin
- Stars
- 226
- Forks
- 86
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 65
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from DataDog/dd-sdk-android
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
DataDog/dd-sdk-android#3904 · 1 comment ·
Maintainers usually reply within 1 day
-
question
Difficulty 4/5 3-5 days Newbie friendliness 45/100
DataDog/dd-sdk-android#3888 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 32/100
DataDog/dd-sdk-android#3223 · 4 comments · 2 reactions ·
Maintainers usually reply within 1 day
-
automatically closed question stale
Difficulty 5/5 Over a week Newbie friendliness 25/100
DataDog/dd-sdk-android#2970 · 6 comments ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 38/100
DataDog/dd-sdk-android#2700 · 1 comment ·
Maintainers usually reply within 1 day
All issues in DataDog/dd-sdk-android
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
recloudstream/cloudstream#3226 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
aws/aws-crt-kotlin#309 ·
Maintainers usually reply within 3 days
-
OAI-PMH
Difficulty 2/5 1-3 hours Newbie friendliness 78/100