File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
samples/snippets/src/main/java/com/example/spanner Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change 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 */
4446public 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 }
You can’t perform that action at this time.
0 commit comments