Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Allow overriding per-request sampling decision when tracing OkHttp requests

Open
#1,750 2 comments 0 reactions 0 assignees View on GitHub

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

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

enhancement

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-priority header. 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 that PrioritySampling constants 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DataDog/dd-sdk-android

All issues in DataDog/dd-sdk-android

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.