Skip to content

Commit 15ecc07

Browse files
authored
gcp-observability: add grpc-census as a dependency and update opencensus version (grpc#9140)
1 parent de7db56 commit 15ecc07

File tree

5 files changed

+32
-14
lines changed

5 files changed

+32
-14
lines changed

Diff for: build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ subprojects {
6060
googleauthVersion = '1.4.0'
6161
protobufVersion = '3.19.2'
6262
protocVersion = protobufVersion
63-
opencensusVersion = '0.28.0'
63+
opencensusVersion = '0.31.0'
6464
autovalueVersion = '1.9'
6565

6666
configureProtoCompilation = {

Diff for: census/src/main/java/io/grpc/census/CensusTracingModule.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import io.opencensus.trace.Status;
4242
import io.opencensus.trace.Tracer;
4343
import io.opencensus.trace.propagation.BinaryFormat;
44-
import io.opencensus.trace.unsafe.ContextUtils;
4544
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
4645
import java.util.logging.Level;
4746
import java.util.logging.Logger;
@@ -366,12 +365,18 @@ public void streamClosed(io.grpc.Status status) {
366365
span.end(createEndSpanOptions(status, isSampledToLocalTracing));
367366
}
368367

368+
/*
369+
TODO(dnvindhya): Replace deprecated ContextUtils usage with ContextHandleUtils to interact
370+
with io.grpc.Context as described in {@link io.opencensus.trace.unsafeContextUtils} to remove
371+
SuppressWarnings annotation.
372+
*/
373+
@SuppressWarnings("deprecation")
369374
@Override
370375
public Context filterContext(Context context) {
371376
// Access directly the unsafe trace API to create the new Context. This is a safe usage
372377
// because gRPC always creates a new Context for each of the server calls and does not
373378
// inherit from the parent Context.
374-
return ContextUtils.withValue(context, span);
379+
return io.opencensus.trace.unsafe.ContextUtils.withValue(context, span);
375380
}
376381

377382
@Override
@@ -404,6 +409,8 @@ public ServerStreamTracer newServerStreamTracer(String fullMethodName, Metadata
404409

405410
@VisibleForTesting
406411
final class TracingClientInterceptor implements ClientInterceptor {
412+
413+
@SuppressWarnings("deprecation")
407414
@Override
408415
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
409416
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
@@ -412,7 +419,8 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
412419
// as Tracer.getCurrentSpan() except when no value available when the return value is null
413420
// for the direct access and BlankSpan when Tracer API is used.
414421
final CallAttemptsTracerFactory tracerFactory =
415-
newClientCallTracer(ContextUtils.getValue(Context.current()), method);
422+
newClientCallTracer(
423+
io.opencensus.trace.unsafe.ContextUtils.getValue(Context.current()), method);
416424
ClientCall<ReqT, RespT> call =
417425
next.newCall(
418426
method,

Diff for: census/src/test/java/io/grpc/census/CensusModulesTest.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
import io.opencensus.trace.Tracer;
9696
import io.opencensus.trace.propagation.BinaryFormat;
9797
import io.opencensus.trace.propagation.SpanContextParseException;
98-
import io.opencensus.trace.unsafe.ContextUtils;
9998
import java.io.InputStream;
10099
import java.util.HashSet;
101100
import java.util.List;
@@ -247,6 +246,7 @@ public void clientInterceptorCustomTag() {
247246
// Test that Census ClientInterceptors uses the TagContext and Span out of the current Context
248247
// to create the ClientCallTracer, and that it intercepts ClientCall.Listener.onClose() to call
249248
// ClientCallTracer.callEnded().
249+
@SuppressWarnings("deprecation")
250250
private void testClientInterceptors(boolean nonDefaultContext) {
251251
grpcServerRule.getServiceRegistry().addService(
252252
ServerServiceDefinition.builder("package1.service2").addMethod(
@@ -284,7 +284,7 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
284284
.emptyBuilder()
285285
.putLocal(StatsTestUtils.EXTRA_TAG, TagValue.create("extra value"))
286286
.build());
287-
ctx = ContextUtils.withValue(ctx, fakeClientParentSpan);
287+
ctx = io.opencensus.trace.unsafe.ContextUtils.withValue(ctx, fakeClientParentSpan);
288288
Context origCtx = ctx.attach();
289289
try {
290290
call = interceptedChannel.newCall(method, CALL_OPTIONS);
@@ -295,7 +295,8 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
295295
assertEquals(
296296
io.opencensus.tags.unsafe.ContextUtils.getValue(Context.ROOT),
297297
io.opencensus.tags.unsafe.ContextUtils.getValue(Context.current()));
298-
assertEquals(ContextUtils.getValue(Context.current()), BlankSpan.INSTANCE);
298+
assertEquals(io.opencensus.trace.unsafe.ContextUtils.getValue(Context.current()),
299+
BlankSpan.INSTANCE);
299300
call = interceptedChannel.newCall(method, CALL_OPTIONS);
300301
}
301302

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

1039+
@SuppressWarnings("deprecation")
10381040
@Test
10391041
public void traceHeadersPropagateSpanContext() throws Exception {
10401042
CallAttemptsTracerFactory callTracer =
@@ -1062,7 +1064,7 @@ public void traceHeadersPropagateSpanContext() throws Exception {
10621064
verify(spyServerSpanBuilder).setRecordEvents(eq(true));
10631065

10641066
Context filteredContext = serverTracer.filterContext(Context.ROOT);
1065-
assertSame(spyServerSpan, ContextUtils.getValue(filteredContext));
1067+
assertSame(spyServerSpan, io.opencensus.trace.unsafe.ContextUtils.getValue(filteredContext));
10661068
}
10671069

10681070
@Test
@@ -1279,6 +1281,7 @@ private void subtestServerBasicStatsNoHeaders(
12791281
}
12801282
}
12811283

1284+
@SuppressWarnings("deprecation")
12821285
@Test
12831286
public void serverBasicTracingNoHeaders() {
12841287
ServerStreamTracer.Factory tracerFactory = censusTracing.getServerTracerFactory();
@@ -1290,7 +1293,7 @@ public void serverBasicTracingNoHeaders() {
12901293
verify(spyServerSpanBuilder).setRecordEvents(eq(true));
12911294

12921295
Context filteredContext = serverStreamTracer.filterContext(Context.ROOT);
1293-
assertSame(spyServerSpan, ContextUtils.getValue(filteredContext));
1296+
assertSame(spyServerSpan, io.opencensus.trace.unsafe.ContextUtils.getValue(filteredContext));
12941297

12951298
serverStreamTracer.serverCallStarted(
12961299
new CallInfo<>(method, Attributes.EMPTY, null));

Diff for: gcp-observability/build.gradle

+9-2
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@ description = "gRPC: Google Cloud Platform Observability"
2121

2222
dependencies {
2323
def cloudLoggingVersion = '3.6.1'
24+
def opencensusExporterVersion = '0.31.0'
2425

2526
annotationProcessor libraries.autovalue
2627
api project(':grpc-api')
27-
28+
2829
implementation project(':grpc-protobuf'),
2930
project(':grpc-stub'),
3031
project(':grpc-alts'),
32+
project(':grpc-census'),
3133
libraries.google_auth_oauth2_http,
3234
libraries.autovalue_annotation,
3335
libraries.perfmark,
36+
libraries.opencensus_contrib_grpc_metrics,
3437
('com.google.guava:guava:31.0.1-jre'),
3538
('com.google.errorprone:error_prone_annotations:2.11.0'),
3639
('com.google.auth:google-auth-library-credentials:1.4.0'),
@@ -39,7 +42,11 @@ dependencies {
3942
('com.google.http-client:google-http-client:1.41.0'),
4043
('com.google.http-client:google-http-client-gson:1.41.0'),
4144
('com.google.api.grpc:proto-google-common-protos:2.7.1'),
42-
("com.google.cloud:google-cloud-logging:${cloudLoggingVersion}")
45+
("com.google.cloud:google-cloud-logging:${cloudLoggingVersion}"),
46+
("io.opencensus:opencensus-exporter-stats-stackdriver:${opencensusExporterVersion}"),
47+
("io.opencensus:opencensus-exporter-trace-stackdriver:${opencensusExporterVersion}")
48+
49+
runtimeOnly libraries.opencensus_impl
4350

4451
testImplementation project(':grpc-testing'),
4552
project(':grpc-testing-proto'),

Diff for: interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
import io.opencensus.trace.Span;
101101
import io.opencensus.trace.SpanContext;
102102
import io.opencensus.trace.Tracing;
103-
import io.opencensus.trace.unsafe.ContextUtils;
104103
import java.io.ByteArrayInputStream;
105104
import java.io.ByteArrayOutputStream;
106105
import java.io.IOException;
@@ -1547,6 +1546,7 @@ public void customMetadata() throws Exception {
15471546
Collections.singleton(streamingRequest), Collections.singleton(goldenStreamingResponse));
15481547
}
15491548

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

1584-
Span span = ContextUtils.getValue(serverCtx);
1584+
Span span = io.opencensus.trace.unsafe.ContextUtils.getValue(serverCtx);
15851585
assertNotNull(span);
15861586
SpanContext spanContext = span.getContext();
15871587
assertEquals(clientParentSpan.getContext().getTraceId(), spanContext.getTraceId());

0 commit comments

Comments
 (0)