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 39
39
* This sample demonstrates how to enable opencensus tracing and stats in cloud spanner client.
40
40
*
41
41
* @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.
43
45
*/
44
46
public class TracingSample {
45
47
@@ -95,10 +97,18 @@ public static void main(String[] args) throws Exception {
95
97
}
96
98
}
97
99
} 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
101
101
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
102
112
System .exit (0 );
103
113
}
104
114
}
You can’t perform that action at this time.
0 commit comments