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

gcp-observability: add grpc-census as a dependency and update opencensus version #9140

Merged
merged 3 commits into from May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -60,7 +60,7 @@ subprojects {
googleauthVersion = '1.4.0'
protobufVersion = '3.19.2'
protocVersion = protobufVersion
opencensusVersion = '0.28.0'
opencensusVersion = '0.31.0'
autovalueVersion = '1.9'

configureProtoCompilation = {
Expand Down
14 changes: 11 additions & 3 deletions census/src/main/java/io/grpc/census/CensusTracingModule.java
Expand Up @@ -41,7 +41,6 @@
import io.opencensus.trace.Status;
import io.opencensus.trace.Tracer;
import io.opencensus.trace.propagation.BinaryFormat;
import io.opencensus.trace.unsafe.ContextUtils;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -366,12 +365,18 @@ public void streamClosed(io.grpc.Status status) {
span.end(createEndSpanOptions(status, isSampledToLocalTracing));
}

/*
TODO(dnvindhya): Replace deprecated ContextUtils usage with ContextHandleUtils to interact
with io.grpc.Context as described in {@link io.opencensus.trace.unsafeContextUtils} to remove
SuppressWarnings annotation.
*/
@SuppressWarnings("deprecation")
sanjaypujare marked this conversation as resolved.
Show resolved Hide resolved
@Override
public Context filterContext(Context context) {
// Access directly the unsafe trace API to create the new Context. This is a safe usage
// because gRPC always creates a new Context for each of the server calls and does not
// inherit from the parent Context.
return ContextUtils.withValue(context, span);
return io.opencensus.trace.unsafe.ContextUtils.withValue(context, span);
}

@Override
Expand Down Expand Up @@ -404,6 +409,8 @@ public ServerStreamTracer newServerStreamTracer(String fullMethodName, Metadata

@VisibleForTesting
final class TracingClientInterceptor implements ClientInterceptor {

@SuppressWarnings("deprecation")
DNVindhya marked this conversation as resolved.
Show resolved Hide resolved
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
Expand All @@ -412,7 +419,8 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
// as Tracer.getCurrentSpan() except when no value available when the return value is null
// for the direct access and BlankSpan when Tracer API is used.
final CallAttemptsTracerFactory tracerFactory =
newClientCallTracer(ContextUtils.getValue(Context.current()), method);
newClientCallTracer(
io.opencensus.trace.unsafe.ContextUtils.getValue(Context.current()), method);
ClientCall<ReqT, RespT> call =
next.newCall(
method,
Expand Down
13 changes: 8 additions & 5 deletions census/src/test/java/io/grpc/census/CensusModulesTest.java
Expand Up @@ -95,7 +95,6 @@
import io.opencensus.trace.Tracer;
import io.opencensus.trace.propagation.BinaryFormat;
import io.opencensus.trace.propagation.SpanContextParseException;
import io.opencensus.trace.unsafe.ContextUtils;
import java.io.InputStream;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -247,6 +246,7 @@ public void clientInterceptorCustomTag() {
// Test that Census ClientInterceptors uses the TagContext and Span out of the current Context
// to create the ClientCallTracer, and that it intercepts ClientCall.Listener.onClose() to call
// ClientCallTracer.callEnded().
@SuppressWarnings("deprecation")
private void testClientInterceptors(boolean nonDefaultContext) {
grpcServerRule.getServiceRegistry().addService(
ServerServiceDefinition.builder("package1.service2").addMethod(
Expand Down Expand Up @@ -284,7 +284,7 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
.emptyBuilder()
.putLocal(StatsTestUtils.EXTRA_TAG, TagValue.create("extra value"))
.build());
ctx = ContextUtils.withValue(ctx, fakeClientParentSpan);
ctx = io.opencensus.trace.unsafe.ContextUtils.withValue(ctx, fakeClientParentSpan);
Context origCtx = ctx.attach();
try {
call = interceptedChannel.newCall(method, CALL_OPTIONS);
Expand All @@ -295,7 +295,8 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
assertEquals(
io.opencensus.tags.unsafe.ContextUtils.getValue(Context.ROOT),
io.opencensus.tags.unsafe.ContextUtils.getValue(Context.current()));
assertEquals(ContextUtils.getValue(Context.current()), BlankSpan.INSTANCE);
assertEquals(io.opencensus.trace.unsafe.ContextUtils.getValue(Context.current()),
BlankSpan.INSTANCE);
call = interceptedChannel.newCall(method, CALL_OPTIONS);
}

Expand Down Expand Up @@ -1035,6 +1036,7 @@ public void statsHeaderMalformed() {
assertSame(tagger.empty(), headers.get(censusStats.statsHeader));
}

@SuppressWarnings("deprecation")
@Test
public void traceHeadersPropagateSpanContext() throws Exception {
CallAttemptsTracerFactory callTracer =
Expand Down Expand Up @@ -1062,7 +1064,7 @@ public void traceHeadersPropagateSpanContext() throws Exception {
verify(spyServerSpanBuilder).setRecordEvents(eq(true));

Context filteredContext = serverTracer.filterContext(Context.ROOT);
assertSame(spyServerSpan, ContextUtils.getValue(filteredContext));
assertSame(spyServerSpan, io.opencensus.trace.unsafe.ContextUtils.getValue(filteredContext));
}

@Test
Expand Down Expand Up @@ -1279,6 +1281,7 @@ private void subtestServerBasicStatsNoHeaders(
}
}

@SuppressWarnings("deprecation")
@Test
public void serverBasicTracingNoHeaders() {
ServerStreamTracer.Factory tracerFactory = censusTracing.getServerTracerFactory();
Expand All @@ -1290,7 +1293,7 @@ public void serverBasicTracingNoHeaders() {
verify(spyServerSpanBuilder).setRecordEvents(eq(true));

Context filteredContext = serverStreamTracer.filterContext(Context.ROOT);
assertSame(spyServerSpan, ContextUtils.getValue(filteredContext));
assertSame(spyServerSpan, io.opencensus.trace.unsafe.ContextUtils.getValue(filteredContext));

serverStreamTracer.serverCallStarted(
new CallInfo<>(method, Attributes.EMPTY, null));
Expand Down
11 changes: 9 additions & 2 deletions gcp-observability/build.gradle
Expand Up @@ -21,16 +21,19 @@ description = "gRPC: Google Cloud Platform Observability"

dependencies {
def cloudLoggingVersion = '3.6.1'
def opencensusExporterVersion = '0.31.0'

annotationProcessor libraries.autovalue
api project(':grpc-api')

sanjaypujare marked this conversation as resolved.
Show resolved Hide resolved
implementation project(':grpc-protobuf'),
project(':grpc-stub'),
project(':grpc-alts'),
project(':grpc-census'),
libraries.google_auth_oauth2_http,
libraries.autovalue_annotation,
libraries.perfmark,
libraries.opencensus_contrib_grpc_metrics,
('com.google.guava:guava:31.0.1-jre'),
('com.google.errorprone:error_prone_annotations:2.11.0'),
('com.google.auth:google-auth-library-credentials:1.4.0'),
Expand All @@ -39,7 +42,11 @@ dependencies {
('com.google.http-client:google-http-client:1.41.0'),
('com.google.http-client:google-http-client-gson:1.41.0'),
('com.google.api.grpc:proto-google-common-protos:2.7.1'),
("com.google.cloud:google-cloud-logging:${cloudLoggingVersion}")
("com.google.cloud:google-cloud-logging:${cloudLoggingVersion}"),
("io.opencensus:opencensus-exporter-stats-stackdriver:${opencensusExporterVersion}"),
("io.opencensus:opencensus-exporter-trace-stackdriver:${opencensusExporterVersion}")

runtimeOnly libraries.opencensus_impl

testImplementation project(':grpc-testing'),
project(':grpc-testing-proto'),
Expand Down
Expand Up @@ -100,7 +100,6 @@
import io.opencensus.trace.Span;
import io.opencensus.trace.SpanContext;
import io.opencensus.trace.Tracing;
import io.opencensus.trace.unsafe.ContextUtils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -1547,6 +1546,7 @@ public void customMetadata() throws Exception {
Collections.singleton(streamingRequest), Collections.singleton(goldenStreamingResponse));
}

@SuppressWarnings("deprecation")
@Test(timeout = 10000)
public void censusContextsPropagated() {
Assume.assumeTrue("Skip the test because server is not in the same process.", server != null);
Expand All @@ -1561,7 +1561,7 @@ public void censusContextsPropagated() {
.emptyBuilder()
.putLocal(StatsTestUtils.EXTRA_TAG, TagValue.create("extra value"))
.build());
ctx = ContextUtils.withValue(ctx, clientParentSpan);
ctx = io.opencensus.trace.unsafe.ContextUtils.withValue(ctx, clientParentSpan);
Context origCtx = ctx.attach();
try {
blockingStub.unaryCall(SimpleRequest.getDefaultInstance());
Expand All @@ -1581,7 +1581,7 @@ public void censusContextsPropagated() {
}
assertTrue("tag not found", tagFound);

Span span = ContextUtils.getValue(serverCtx);
Span span = io.opencensus.trace.unsafe.ContextUtils.getValue(serverCtx);
assertNotNull(span);
SpanContext spanContext = span.getContext();
assertEquals(clientParentSpan.getContext().getTraceId(), spanContext.getTraceId());
Expand Down