|
37 | 37 | * firestore.googleapis.com/Database} monitored resource. The {@code service} metric label is set to |
38 | 38 | * {@code datastore.googleapis.com} to distinguish Datastore traffic from Firestore. |
39 | 39 | * |
40 | | - * <p>No configuration is required to enable metrics — they are on by default. To disable them, set |
41 | | - * {@link DatastoreOpenTelemetryOptions#setExportBuiltinMetricsToGoogleCloudMonitoring(boolean)} to |
42 | | - * {@code false}, or set the environment variable {@code DATASTORE_ENABLE_METRICS=false}. |
| 40 | + * <p>Built-in metrics are currently disabled by default until the Cloud Monitoring namespace is |
| 41 | + * fully deployed. To enable them, set {@link |
| 42 | + * DatastoreOpenTelemetryOptions.Builder#setExportBuiltinMetricsToGoogleCloudMonitoring(boolean)} to |
| 43 | + * {@code true}, or set the environment variable {@code DATASTORE_ENABLE_METRICS=true}. |
43 | 44 | * |
44 | 45 | * <p>Metrics recorded by this sample: |
45 | 46 | * |
@@ -73,17 +74,23 @@ public static void main(String[] args) throws Exception { |
73 | 74 |
|
74 | 75 | static void runSample(String projectId, String databaseId, String kind) throws Exception { |
75 | 76 | // [START datastore_client_side_metrics_default] |
76 | | - // Built-in metrics are exported to Cloud Monitoring by default. |
77 | | - // No additional configuration is required. |
| 77 | + // Built-in metrics are disabled by default. Enable them explicitly. |
78 | 78 | DatastoreOptions options = |
79 | | - DatastoreOptions.newBuilder().setProjectId(projectId).setDatabaseId(databaseId).build(); |
| 79 | + DatastoreOptions.newBuilder() |
| 80 | + .setProjectId(projectId) |
| 81 | + .setDatabaseId(databaseId) |
| 82 | + .setOpenTelemetryOptions( |
| 83 | + DatastoreOpenTelemetryOptions.newBuilder() |
| 84 | + .setExportBuiltinMetricsToGoogleCloudMonitoring(true) |
| 85 | + .build()) |
| 86 | + .build(); |
80 | 87 | // [END datastore_client_side_metrics_default] |
81 | 88 |
|
82 | 89 | try (Datastore datastore = options.getService()) { |
83 | 90 | System.out.printf( |
84 | 91 | "Connected to project=%s database=%s%n", projectId, databaseId); |
85 | 92 | System.out.println( |
86 | | - "Built-in metrics are enabled by default and will be exported to" |
| 93 | + "Built-in metrics are explicitly enabled and will be exported to" |
87 | 94 | + " Google Cloud Monitoring under custom.googleapis.com/internal/client/*"); |
88 | 95 |
|
89 | 96 | runTransactionFlow(datastore, kind); |
|
0 commit comments