Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a tag to identify OkHttp calls made from OTel exporters #5906

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -107,7 +109,7 @@ public OkHttpGrpcSender(

@Override
public void send(T request, Runnable onSuccess, BiConsumer<GrpcResponse, Throwable> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,7 +93,7 @@ public void send(
int contentLength,
Consumer<Response> onResponse,
Consumer<Throwable> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import okhttp3.Dispatcher;
import okhttp3.Request;

/**
* Utilities for OkHttp.
Expand All @@ -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() {}
}