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

interop-test: add interop test open telemetry tracing flags #11674

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -57,6 +57,9 @@
import io.grpc.netty.NettyChannelBuilder;
import io.grpc.okhttp.InternalOkHttpChannelBuilder;
import io.grpc.okhttp.OkHttpChannelBuilder;
import io.grpc.opentelemetry.GrpcOpenTelemetry;
import io.grpc.opentelemetry.GrpcTraceBinContextPropagator;
import io.grpc.opentelemetry.InternalGrpcOpenTelemetry;
import io.grpc.stub.ClientCalls;
import io.grpc.stub.MetadataUtils;
import io.grpc.stub.StreamObserver;
Expand All @@ -68,6 +71,12 @@
import io.grpc.testing.integration.Messages.StreamingOutputCallRequest;
import io.grpc.testing.integration.Messages.StreamingOutputCallResponse;
import io.grpc.testing.integration.Messages.TestOrcaReport;
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
Expand Down Expand Up @@ -136,7 +145,8 @@ public static void main(String[] args) throws Exception {
private int soakResponseSize = 314159;
private String additionalMetadata = "";
private static LoadBalancerProvider customBackendMetricsLoadBalancerProvider;

private boolean useOpenTelemetryTracing;
private TextMapPropagator textMapPropagator = GrpcTraceBinContextPropagator.defaultInstance();
private Tester tester = new Tester();

@VisibleForTesting
Expand Down Expand Up @@ -216,6 +226,18 @@ void parseArgs(String[] args) throws Exception {
soakResponseSize = Integer.parseInt(value);
} else if ("additional_metadata".equals(key)) {
additionalMetadata = value;
} else if ("use_open_telemetry_tracing".equals(key)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more than just tracing, so I thought it'd be named more like "use_open_telemetry"

useOpenTelemetryTracing = Boolean.parseBoolean(value);
} else if ("open_telemetry_propagator".equals(key)) {
if (value.toLowerCase().contains("w3c")) {
textMapPropagator = W3CTraceContextPropagator.getInstance();
} else if (value.toLowerCase().contains("grpc-trace-bin")) {
textMapPropagator = GrpcTraceBinContextPropagator.defaultInstance();
} else {
System.err.println("Unsupported text map propagator, use 'w3c' or 'grpc-trace-bin'");
usage = true;
break;
}
} else {
System.err.println("Unknown argument: " + key);
usage = true;
Expand Down Expand Up @@ -294,6 +316,12 @@ void parseArgs(String[] args) throws Exception {
+ "\n Additional metadata to send in each request, as a "
+ "\n semicolon-separated list of key:value pairs. Default "
+ c.additionalMetadata
+ "\n --use_open_telemetry_tracing Whether to use open telemetry tracing. Default "
+ c.useOpenTelemetryTracing
+ "\n --text_map_propagator w3c|grpc-trace-bin "
+ "\n The TextMapPropagator for openTelemetry. Default "
+ "grpc-trace-bin "

);
System.exit(1);
}
Expand Down Expand Up @@ -678,6 +706,25 @@ protected ManagedChannelBuilder<?> createChannelBuilder() {
if (addMdInterceptor != null) {
nettyBuilder.intercept(addMdInterceptor);
}
if (useOpenTelemetryTracing) {
OpenTelemetrySdk openTelemetrySdk = OpenTelemetrySdk.builder()
.setTracerProvider(SdkTracerProvider.builder()
.setSampler(Sampler.alwaysOn())
.build())
.setPropagators(ContextPropagators.create(TextMapPropagator.composite(
textMapPropagator
)))
.build();
GrpcOpenTelemetry.Builder grpcOpentelemetryBuilder = GrpcOpenTelemetry.newBuilder()
.sdk(openTelemetrySdk);
InternalGrpcOpenTelemetry.enableTracing(grpcOpentelemetryBuilder, true);
GrpcOpenTelemetry grpcOpenTelemetry = grpcOpentelemetryBuilder.build();
// Disabling census-tracing is necessary to avoid trace ID mismatches.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The auto-applying is still causing trouble... This is a symptom of larger issues. It's okay for a while, but our users may have to deal with the same.

// This is because census-tracing overrides the grpc-trace-bin header with
// OpenTelemetry's GrpcTraceBinPropagator.
InternalNettyChannelBuilder.setTracingEnabled(nettyBuilder, false);
grpcOpenTelemetry.configureChannelBuilder(nettyBuilder);
}
return nettyBuilder.intercept(createCensusStatsClientInterceptor());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.io.BaseEncoding;
import io.grpc.Metadata;
import io.opentelemetry.context.propagation.TextMapSetter;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
Expand All @@ -40,6 +41,8 @@ public static MetadataSetter getInstance() {

@Override
public void set(@Nullable Metadata carrier, String key, String value) {
logger.log(Level.FINE, "Setting text trace header key={0} value={1}",
new Object[]{key, value});
if (carrier == null) {
logger.log(Level.FINE, "Carrier is null, setting no data");
return;
Expand All @@ -57,6 +60,8 @@ public void set(@Nullable Metadata carrier, String key, String value) {
}

void set(@Nullable Metadata carrier, String key, byte[] value) {
logger.log(Level.FINE, "Setting binary trace header key={0} value={1}",
new Object[]{key, Arrays.toString(value)});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This toString() is performed even when logging is disabled. Does Arrays.asList() work?

if (carrier == null) {
logger.log(Level.FINE, "Carrier is null, setting no data");
return;
Expand Down
Loading