10
10
import com .google .cloud .spanner .Statement ;
11
11
12
12
import io .opencensus .common .Scope ;
13
+ import io .opencensus .contrib .grpc .metrics .RpcViews ;
13
14
import io .opencensus .contrib .zpages .ZPageHandlers ;
15
+ import io .opencensus .exporter .stats .stackdriver .StackdriverStatsExporter ;
14
16
import io .opencensus .exporter .trace .stackdriver .StackdriverExporter ;
15
17
import io .opencensus .trace .Tracing ;
16
18
import io .opencensus .trace .samplers .Samplers ;
17
19
18
20
public class TracingSample {
21
+
22
+ private static final String SAMPLE_SPAN = "CloudSpannerSample" ;
19
23
20
24
public static void main (String [] args ) throws Exception {
21
25
if (args .length != 2 ) {
@@ -27,10 +31,14 @@ public static void main(String[] args) throws Exception {
27
31
28
32
// Installs a handler for /tracez page.
29
33
ZPageHandlers .startHttpServerAndRegisterAll (8080 );
30
- // Installs an exporter for stack driver.
34
+ // Installs an exporter for stack driver traces .
31
35
StackdriverExporter .createAndRegister ();
32
- Tracing .getExportComponent ().getSampledSpanStore ().registerSpanNamesForCollection (Arrays .asList ("CloudSpannerSample" ));
36
+ Tracing .getExportComponent ().getSampledSpanStore ().registerSpanNamesForCollection (Arrays .asList (SAMPLE_SPAN ));
33
37
38
+ // Installs an exporter for stack driver stats.
39
+ StackdriverStatsExporter .createAndRegister ();
40
+ RpcViews .registerAllCumulativeViews ();
41
+
34
42
// Name of your instance & database.
35
43
String instanceId = args [0 ];
36
44
String databaseId = args [1 ];
@@ -40,7 +48,7 @@ public static void main(String[] args) throws Exception {
40
48
options .getProjectId (), instanceId , databaseId ));
41
49
// Queries the database
42
50
try (Scope ss = Tracing .getTracer ()
43
- .spanBuilderWithExplicitParent ("CloudSpannerSample" , null )
51
+ .spanBuilderWithExplicitParent (SAMPLE_SPAN , null )
44
52
.setSampler (Samplers .alwaysSample ())
45
53
.startScopedSpan ()) {
46
54
ResultSet resultSet = dbClient .singleUse ().executeQuery (Statement .of ("SELECT 1" ));
0 commit comments