Java源码示例:io.opencensus.tags.propagation.TagContextBinarySerializer
示例1
/**
* Returns a {@link ClientInterceptor} with custom stats implementation.
*/
public static ClientInterceptor getClientInterceptor(
Tagger tagger,
TagContextBinarySerializer tagCtxSerializer,
StatsRecorder statsRecorder,
Supplier<Stopwatch> stopwatchSupplier,
boolean propagateTags,
boolean recordStartedRpcs,
boolean recordFinishedRpcs,
boolean recordRealTimeMetrics) {
CensusStatsModule censusStats =
new CensusStatsModule(
tagger, tagCtxSerializer, statsRecorder, stopwatchSupplier,
propagateTags, recordStartedRpcs, recordFinishedRpcs, recordRealTimeMetrics);
return censusStats.getClientInterceptor();
}
示例2
/**
* Returns a {@link ServerStreamTracer.Factory} with custom stats implementation.
*/
public static ServerStreamTracer.Factory getServerStreamTracerFactory(
Tagger tagger,
TagContextBinarySerializer tagCtxSerializer,
StatsRecorder statsRecorder,
Supplier<Stopwatch> stopwatchSupplier,
boolean propagateTags,
boolean recordStartedRpcs,
boolean recordFinishedRpcs,
boolean recordRealTimeMetrics) {
CensusStatsModule censusStats =
new CensusStatsModule(
tagger, tagCtxSerializer, statsRecorder, stopwatchSupplier,
propagateTags, recordStartedRpcs, recordFinishedRpcs, recordRealTimeMetrics);
return censusStats.getServerTracerFactory();
}
示例3
/** Extract opencensus context(if any) from environment. */
private static TagContext deserializeContext() {
String serializedContext = System.getenv("OPENCENSUS_STATS_CONTEXT");
if (serializedContext == null) {
return Tags.getTagger().empty();
}
TagContextBinarySerializer serializer = Tags.getTagPropagationComponent().getBinarySerializer();
try {
return serializer.fromByteArray(Base64.getDecoder().decode(serializedContext));
} catch (TagContextDeserializationException e) {
return Tags.getTagger().empty();
}
}
示例4
@Test
public void noopTagContextBinarySerializer_ToByteArray_DisallowsNull()
throws TagContextSerializationException {
TagContextBinarySerializer noopSerializer = NoopTags.getNoopTagContextBinarySerializer();
thrown.expect(NullPointerException.class);
noopSerializer.toByteArray(null);
}
示例5
@Test
public void noopTagContextBinarySerializer_FromByteArray_DisallowsNull()
throws TagContextDeserializationException {
TagContextBinarySerializer noopSerializer = NoopTags.getNoopTagContextBinarySerializer();
thrown.expect(NullPointerException.class);
noopSerializer.fromByteArray(null);
}
示例6
/** Gets the {@link TagContextBinarySerializer} for the specified 'implementation'. */
@VisibleForTesting
public static TagContextBinarySerializer getTagContextBinarySerializer(String implementation) {
if (implementation.equals("impl")) {
// We can return the global tracer here because if impl is linked the global tracer will be
// the impl one.
// TODO(bdrutu): Make everything not be a singleton (disruptor, etc.) and use a new
// TraceComponentImpl similar to TraceComponentImplLite.
return tagsComponentImplBase.getTagPropagationComponent().getBinarySerializer();
} else if (implementation.equals("impl-lite")) {
return tagsComponentImplLite.getTagPropagationComponent().getBinarySerializer();
} else {
throw new RuntimeException("Invalid binary serializer implementation specified.");
}
}
示例7
@Override
public TagContextBinarySerializer getBinarySerializer() {
return getNoopTagContextBinarySerializer();
}
示例8
@Override
public TagContextBinarySerializer getBinarySerializer() {
return tagContextBinarySerializer;
}
示例9
/**
* Returns a {@code TagContextBinarySerializer} that serializes all {@code TagContext}s to zero
* bytes and deserializes all inputs to empty {@code TagContext}s.
*/
static TagContextBinarySerializer getNoopTagContextBinarySerializer() {
return NoopTagContextBinarySerializer.INSTANCE;
}