-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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 | ||
|
@@ -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)) { | ||
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; | ||
|
@@ -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); | ||
} | ||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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)}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This toString() is performed even when logging is disabled. Does |
||
if (carrier == null) { | ||
logger.log(Level.FINE, "Carrier is null, setting no data"); | ||
return; | ||
|
There was a problem hiding this comment.
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"