2323import io .opencensus .common .Function ;
2424import io .opencensus .common .Functions ;
2525import io .opencensus .common .Timestamp ;
26+ import io .opencensus .proto .agent .trace .v1 .UpdatedLibraryConfig ;
2627import io .opencensus .proto .trace .v1 .AttributeValue ;
2728import io .opencensus .proto .trace .v1 .ConstantSampler ;
2829import io .opencensus .proto .trace .v1 .ProbabilitySampler ;
5859import org.checkerframework.checker.nullness.qual.Nullable;
5960*/
6061
61- /**
62- * Utilities for converting the Tracing data models in OpenCensus Java to/from OpenCensus Proto.
63- *
64- * @since 0.17
65- */
66- public final class TraceProtoUtils {
62+ /** Utilities for converting the Tracing data models in OpenCensus Java to/from OpenCensus Proto. */
63+ final class TraceProtoUtils {
6764
6865 // Constant functions for AttributeValue.
6966 private static final Function <String , /*@Nullable*/ AttributeValue > stringAttributeValueFunction =
@@ -106,10 +103,8 @@ public AttributeValue apply(Double doubleValue) {
106103 *
107104 * @param spanData the {@code SpanData}.
108105 * @return proto representation of {@code Span}.
109- * @since 0.17
110106 */
111- @ SuppressWarnings ("DefaultCharset" )
112- public static Span toSpanProto (SpanData spanData ) {
107+ static Span toSpanProto (SpanData spanData ) {
113108 SpanContext spanContext = spanData .getContext ();
114109 TraceId traceId = spanContext .getTraceId ();
115110 SpanId spanId = spanContext .getSpanId ();
@@ -298,7 +293,6 @@ private static Link.Type toLinkTypeProto(io.opencensus.trace.Link.Type type) {
298293 }
299294 }
300295
301- @ SuppressWarnings ("DefaultCharset" )
302296 private static Link toLinkProto (io .opencensus .trace .Link link ) {
303297 return Link .newBuilder ()
304298 .setTraceId (toByteString (link .getTraceId ().getBytes ()))
@@ -322,9 +316,8 @@ private static Links toLinksProto(io.opencensus.trace.export.SpanData.Links link
322316 *
323317 * @param traceParams the {@code TraceParams}.
324318 * @return {@code TraceConfig}.
325- * @since 0.17
326319 */
327- public static TraceConfig toTraceConfigProto (TraceParams traceParams ) {
320+ static TraceConfig toTraceConfigProto (TraceParams traceParams ) {
328321 TraceConfig .Builder traceConfigProtoBuilder = TraceConfig .newBuilder ();
329322 Sampler librarySampler = traceParams .getSampler ();
330323
@@ -360,7 +353,7 @@ private static double parseSamplingProbability(Sampler sampler) {
360353 * @return updated {@code TraceParams}.
361354 * @since 0.17
362355 */
363- public static TraceParams fromTraceConfigProto (
356+ static TraceParams fromTraceConfigProto (
364357 TraceConfig traceConfigProto , TraceParams currentTraceParams ) {
365358 TraceParams .Builder builder = currentTraceParams .toBuilder ();
366359 if (traceConfigProto .hasConstantSampler ()) {
@@ -378,5 +371,20 @@ public static TraceParams fromTraceConfigProto(
378371 return builder .build ();
379372 }
380373
374+ // Creates a TraceConfig proto message with current TraceParams.
375+ static TraceConfig getCurrentTraceConfig (io .opencensus .trace .config .TraceConfig traceConfig ) {
376+ TraceParams traceParams = traceConfig .getActiveTraceParams ();
377+ return toTraceConfigProto (traceParams );
378+ }
379+
380+ // Creates an updated TraceParams with the given UpdatedLibraryConfig message and current
381+ // TraceParams, then applies the updated TraceParams.
382+ static TraceParams getUpdatedTraceParams (
383+ UpdatedLibraryConfig config , io .opencensus .trace .config .TraceConfig traceConfig ) {
384+ TraceParams currentParams = traceConfig .getActiveTraceParams ();
385+ TraceConfig traceConfigProto = config .getConfig ();
386+ return fromTraceConfigProto (traceConfigProto , currentParams );
387+ }
388+
381389 private TraceProtoUtils () {}
382390}
0 commit comments