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 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 tracedHosts = listOf("example.com", "example.eu")
        val okHttpClient = OkHttpClient.Builder()
            .addInterceptor(TracingInterceptor(tracedHosts)))
            // Optionally to get information about redirections and retries
            // .addNetworkInterceptor(new TracingInterceptor(tracedHosts))
            .build();
    • Constructor Detail

      • TracingInterceptor

        TracingInterceptor(List<String> tracedHosts, TracedRequestListener tracedRequestListener, Float traceSamplingRate)
        Creates a TracingInterceptor to automatically create a trace around OkHttp Requests.
        Parameters:
        tracedHosts - a list of all the hosts that you want to be automatically tracked by this interceptor with Datadog style headers.
        tracedRequestListener - a listener for automatically created Spans
        traceSamplingRate - the sampling rate for APM traces created for auto-instrumented requests.
      • TracingInterceptor

        TracingInterceptor(List<String> tracedHosts, TracedRequestListener tracedRequestListener)
        Creates a TracingInterceptor to automatically create a trace around OkHttp Requests.
        Parameters:
        tracedHosts - a list of all the hosts that you want to be automatically tracked by this interceptor with Datadog style headers.
        tracedRequestListener - a listener for automatically created Spans
      • TracingInterceptor

        TracingInterceptor(List<String> tracedHosts)
        Creates a TracingInterceptor to automatically create a trace around OkHttp Requests.
        Parameters:
        tracedHosts - a list of all the hosts that you want to be automatically tracked by this interceptor with Datadog style headers.
      • TracingInterceptor

        TracingInterceptor(Map<String, Set<TracingHeaderType>> tracedHostsWithHeaderType, TracedRequestListener tracedRequestListener, Float traceSamplingRate)
        Creates a TracingInterceptor to automatically create a trace around OkHttp Requests.
        Parameters:
        tracedHostsWithHeaderType - a list of all the hosts and header types that you want to be automatically tracked by this interceptor.
        tracedRequestListener - a listener for automatically created Spans
        traceSamplingRate - the sampling rate for APM traces created for auto-instrumented requests.
      • TracingInterceptor

        TracingInterceptor(Map<String, Set<TracingHeaderType>> tracedHostsWithHeaderType, TracedRequestListener tracedRequestListener)
        Creates a TracingInterceptor to automatically create a trace around OkHttp Requests.
        Parameters:
        tracedHostsWithHeaderType - a list of all the hosts and header types that you want to be automatically tracked by this interceptor.
        tracedRequestListener - a listener for automatically created Spans
      • TracingInterceptor

        TracingInterceptor(Map<String, Set<TracingHeaderType>> tracedHostsWithHeaderType)
        Creates a TracingInterceptor to automatically create a trace around OkHttp Requests.
        Parameters:
        tracedHostsWithHeaderType - a list of all the hosts and header types that you want to be automatically tracked by this interceptor.
      • TracingInterceptor

        TracingInterceptor(TracedRequestListener tracedRequestListener, Float traceSamplingRate)
        Creates a TracingInterceptor to automatically create a trace around OkHttp Requests.
        Parameters:
        tracedRequestListener - a listener for automatically created Spans
        traceSamplingRate - the sampling rate for APM traces created for auto-instrumented requests.
      • TracingInterceptor

        TracingInterceptor(TracedRequestListener tracedRequestListener)
        Creates a TracingInterceptor to automatically create a trace around OkHttp Requests.
        Parameters:
        tracedRequestListener - a listener for automatically created Spans
      • TracingInterceptor

        TracingInterceptor()
        Creates a TracingInterceptor to automatically create a trace around OkHttp Requests.
    • Method Detail

      • intercept

         Response intercept(Interceptor.Chain chain)