Package 

Class TracingInterceptor

  • All Implemented Interfaces:
    okhttp3.Interceptor

    
    public class TracingInterceptor
     implements Interceptor
                        

    Provides automatic trace integration for OkHttpClient by way of the Interceptor system.

    This interceptor will create a Span around the request and fill the request information (url, method, status code, optional error). It will also propagate the span and trace information in the request header to link it with backend spans.

    If you use multiple Interceptors, make sure that this one is called first. If you also want to track network requests as RUM Resources, use the com.datadog.android.okhttp.DatadogInterceptor instead, which combines the RUM and APM integrations.

    If you want to get more insights on the network requests (e.g.: redirections), you can also add this interceptor as a Network level interceptor.

    To use:

        val tracedHostsWithHeaderType = mapOf("example.com" to setOf(
                    TracingHeaderType.DATADOG,
                    TracingHeaderType.TRACECONTEXT),
                "example.eu" to  setOf(
                    TracingHeaderType.DATADOG,
                    TracingHeaderType.TRACECONTEXT))
        val okHttpClient = OkHttpClient.Builder()
            .addInterceptor(TracingInterceptor.Builder(tracedHostsWithHeaderType).build())
            // Optionally to get information about redirections and retries
            // .addNetworkInterceptor(TracingInterceptor.Builder(tracedHostsWithHeaderType).build())
            .build()
    • Method Summary

      Modifier and Type Method Description
      Response intercept(Interceptor.Chain chain)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • intercept

         Response intercept(Interceptor.Chain chain)