Skip to content

Commit 3c969e3

Browse files
committed
add comments and reorder ops
1 parent 7be099f commit 3c969e3

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

samples/snippets/src/main/java/com/example/spanner/TracingSample.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
* This sample demonstrates how to enable opencensus tracing and stats in cloud spanner client.
4040
*
4141
* @deprecated The OpenCensus project is deprecated. Use OpenTelemetry to enable metrics and stats
42-
* with cloud spanner client.
42+
* with cloud spanner client.
43+
* <p>Note: This sample uses System.exit(0) to ensure clean termination due to OpenCensus
44+
* background threads.
4345
*/
4446
public class TracingSample {
4547

@@ -95,10 +97,18 @@ public static void main(String[] args) throws Exception {
9597
}
9698
}
9799
} finally {
98-
// Closes the client which will free up the resources used
99-
spanner.close();
100-
StackdriverExporter.unregister();
100+
// First, shutdown the stats/metrics exporters
101101
StackdriverStatsExporter.unregister();
102+
103+
// Shutdown tracing components
104+
StackdriverExporter.unregister();
105+
Tracing.getExportComponent().shutdown();
106+
107+
// Close the spanner client
108+
spanner.close();
109+
110+
// Force immediate exit since this is a sample application and OpenCensus
111+
// background threads might prevent clean shutdown
102112
System.exit(0);
103113
}
104114
}

0 commit comments

Comments
 (0)