diff --git a/exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpGrpcSender.java b/exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpGrpcSender.java index 5da750edead..1871b75b6fd 100644 --- a/exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpGrpcSender.java +++ b/exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpGrpcSender.java @@ -23,6 +23,8 @@ package io.opentelemetry.exporter.sender.okhttp.internal; +import static io.opentelemetry.exporter.sender.okhttp.internal.OkHttpUtil.newRequestBuilder; + import io.opentelemetry.exporter.internal.RetryUtil; import io.opentelemetry.exporter.internal.grpc.GrpcExporterUtil; import io.opentelemetry.exporter.internal.grpc.GrpcResponse; @@ -107,7 +109,7 @@ public OkHttpGrpcSender( @Override public void send(T request, Runnable onSuccess, BiConsumer onError) { - Request.Builder requestBuilder = new Request.Builder().url(url).headers(headers); + Request.Builder requestBuilder = newRequestBuilder().url(url).headers(headers); RequestBody requestBody = new GrpcRequestBody(request, compressionEnabled); requestBuilder.post(requestBody); diff --git a/exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpHttpSender.java b/exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpHttpSender.java index 306c7b97163..171e69e5230 100644 --- a/exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpHttpSender.java +++ b/exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpHttpSender.java @@ -5,6 +5,8 @@ package io.opentelemetry.exporter.sender.okhttp.internal; +import static io.opentelemetry.exporter.sender.okhttp.internal.OkHttpUtil.newRequestBuilder; + import io.opentelemetry.exporter.internal.RetryUtil; import io.opentelemetry.exporter.internal.auth.Authenticator; import io.opentelemetry.exporter.internal.http.HttpSender; @@ -91,7 +93,7 @@ public void send( int contentLength, Consumer onResponse, Consumer onError) { - Request.Builder requestBuilder = new Request.Builder().url(url); + Request.Builder requestBuilder = newRequestBuilder().url(url); headerSupplier.get().forEach(requestBuilder::addHeader); RequestBody body = new RawRequestBody(marshaler, contentLength, mediaType); if (compressionEnabled) { diff --git a/exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpUtil.java b/exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpUtil.java index 8aef6b7c21a..7d81229cd5e 100644 --- a/exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpUtil.java +++ b/exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpUtil.java @@ -10,6 +10,7 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import okhttp3.Dispatcher; +import okhttp3.Request; /** * Utilities for OkHttp. @@ -31,5 +32,13 @@ public static Dispatcher newDispatcher() { new DaemonThreadFactory("okhttp-dispatch"))); } + /** + * Returns a {@link Request.Builder} with a tag to identify a request created by OTel. The tag can + * later be checked by an automatic instrumentation to avoid tracing OTel exporter's calls. + */ + public static Request.Builder newRequestBuilder() { + return new Request.Builder().tag("suppress_instrumentation"); + } + private OkHttpUtil() {} }