3939import io .opencensus .trace .Status ;
4040import io .opencensus .trace .Tracer ;
4141import io .opencensus .trace .Tracing ;
42+ import io .opencensus .trace .config .TraceConfig ;
4243import io .opencensus .trace .samplers .Samplers ;
4344import io .prometheus .client .exporter .HTTPServer ;
4445import java .io .IOException ;
@@ -60,10 +61,7 @@ private HelloWorldServer(int serverPort) {
6061 // A helper function that performs some work in its own Span.
6162 private static void performWork (Span parent ) {
6263 SpanBuilder spanBuilder =
63- tracer
64- .spanBuilderWithExplicitParent ("internal_work" , parent )
65- .setRecordEvents (true )
66- .setSampler (Samplers .alwaysSample ());
64+ tracer .spanBuilderWithExplicitParent ("internal_work" , parent ).setRecordEvents (true );
6765 try (Scope scope = spanBuilder .startScopedSpan ()) {
6866 Span span = tracer .getCurrentSpan ();
6967 span .putAttribute ("my_attribute" , AttributeValue .stringAttributeValue ("blue" ));
@@ -120,6 +118,11 @@ public static void main(String[] args) throws IOException, InterruptedException
120118 final int zPagePort = getPortOrDefaultFromArgs (args , 2 , 3000 );
121119 final int prometheusPort = getPortOrDefaultFromArgs (args , 3 , 9090 );
122120
121+ // For demo purposes, always sample
122+ TraceConfig traceConfig = Tracing .getTraceConfig ();
123+ traceConfig .updateActiveTraceParams (
124+ traceConfig .getActiveTraceParams ().toBuilder ().setSampler (Samplers .alwaysSample ()).build ());
125+
123126 // Registers all RPC views. For demonstration all views are registered. You may want to
124127 // start with registering basic views and register other views as needed for your application.
125128 RpcViews .registerAllViews ();
@@ -138,7 +141,7 @@ public static void main(String[] args) throws IOException, InterruptedException
138141 StackdriverStatsExporter .createAndRegister (
139142 StackdriverStatsConfiguration .builder ()
140143 .setProjectId (cloudProjectId )
141- .setExportInterval (Duration .create (60 , 0 ))
144+ .setExportInterval (Duration .create (5 , 0 ))
142145 .build ());
143146 }
144147
0 commit comments