Skip to content

Commit 8176f86

Browse files
committed
census: expose server tracer factories
1 parent 0d33c43 commit 8176f86

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

census/src/main/java/io/grpc/census/GrpcCensus.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import com.google.common.base.Stopwatch;
2020
import com.google.common.base.Supplier;
2121
import io.grpc.ClientInterceptor;
22+
import io.grpc.ServerBuilder;
23+
import io.grpc.ServerStreamTracer;
2224
import io.opencensus.stats.StatsRecorder;
2325
import io.opencensus.tags.Tagger;
2426
import io.opencensus.tags.propagation.TagContextBinarySerializer;
@@ -84,4 +86,63 @@ public static ClientInterceptor newClientTracingInterceptor() {
8486
return censusTracing.getClientInterceptor();
8587
}
8688

89+
/**
90+
* Returns a {@link ServerStreamTracer.Factory} with default stats implementation.
91+
*/
92+
public static ServerStreamTracer.Factory getServerStreamTracerFactory(
93+
boolean recordStartedRpcs,
94+
boolean recordFinishedRpcs,
95+
boolean recordRealTimeMetrics) {
96+
CensusStatsModule censusStats =
97+
new CensusStatsModule(
98+
STOPWATCH_SUPPLIER,
99+
true, /* propagateTags */
100+
recordStartedRpcs,
101+
recordFinishedRpcs,
102+
recordRealTimeMetrics,
103+
false);
104+
return censusStats.getServerTracerFactory();
105+
}
106+
107+
/**
108+
* Returns a {@link ServerStreamTracer.Factory} with custom stats implementation.
109+
*/
110+
public static ServerStreamTracer.Factory getServerStreamTracerFactory(
111+
Tagger tagger,
112+
TagContextBinarySerializer tagCtxSerializer,
113+
StatsRecorder statsRecorder,
114+
Supplier<Stopwatch> stopwatchSupplier,
115+
boolean propagateTags,
116+
boolean recordStartedRpcs,
117+
boolean recordFinishedRpcs,
118+
boolean recordRealTimeMetrics) {
119+
CensusStatsModule censusStats =
120+
new CensusStatsModule(
121+
tagger, tagCtxSerializer, statsRecorder, stopwatchSupplier,
122+
propagateTags, recordStartedRpcs, recordFinishedRpcs, recordRealTimeMetrics, false);
123+
return censusStats.getServerTracerFactory();
124+
}
125+
126+
/**
127+
* Returns a {@link ServerStreamTracer.Factory} with default tracing implementation.
128+
*/
129+
public static ServerStreamTracer.Factory getServerStreamTracerFactory() {
130+
CensusTracingModule censusTracing =
131+
new CensusTracingModule(
132+
Tracing.getTracer(),
133+
Tracing.getPropagationComponent().getBinaryFormat());
134+
return censusTracing.getServerTracerFactory();
135+
}
136+
137+
/**
138+
* Configures the given {@link ServerBuilder} with the provided serverStreamTracerFactory.
139+
*
140+
* @param serverBuilder the server builder to configure
141+
* @param serverStreamTracerFactory the server stream tracer factory to configure
142+
*/
143+
public static void configureServerBuilder(ServerBuilder<?> serverBuilder,
144+
ServerStreamTracer.Factory serverStreamTracerFactory) {
145+
serverBuilder.addStreamTracerFactory(serverStreamTracerFactory);
146+
}
147+
87148
}

0 commit comments

Comments
 (0)