|
96 | 96 | import java.time.Duration; |
97 | 97 | import java.util.ArrayList; |
98 | 98 | import java.util.Base64; |
| 99 | +import java.util.Collections; |
99 | 100 | import java.util.HashMap; |
100 | 101 | import java.util.List; |
101 | 102 | import java.util.Map; |
@@ -308,6 +309,9 @@ static GcpChannelPoolOptions mergeWithDefaultChannelPoolOptions( |
308 | 309 | private final String monitoringHost; |
309 | 310 | private final TransactionOptions defaultTransactionOptions; |
310 | 311 | private final RequestOptions.ClientContext clientContext; |
| 312 | + private final boolean autoTaggingEnabled; |
| 313 | + private final List<String> autoTaggingPackages; |
| 314 | + private final int autoTaggingTracerLimit; |
311 | 315 |
|
312 | 316 | enum TracingFramework { |
313 | 317 | OPEN_CENSUS, |
@@ -993,6 +997,9 @@ protected SpannerOptions(Builder builder) { |
993 | 997 | monitoringHost = builder.monitoringHost; |
994 | 998 | defaultTransactionOptions = builder.defaultTransactionOptions; |
995 | 999 | clientContext = builder.clientContext; |
| 1000 | + autoTaggingEnabled = builder.autoTaggingEnabled; |
| 1001 | + autoTaggingPackages = builder.autoTaggingPackages; |
| 1002 | + autoTaggingTracerLimit = builder.autoTaggingTracerLimit; |
996 | 1003 | } |
997 | 1004 |
|
998 | 1005 | private String getResolvedUniverseDomain() { |
@@ -1064,6 +1071,14 @@ default boolean isEnableLocationApi() { |
1064 | 1071 | return false; |
1065 | 1072 | } |
1066 | 1073 |
|
| 1074 | + default boolean isAutoTaggingDisabled() { |
| 1075 | + return false; |
| 1076 | + } |
| 1077 | + |
| 1078 | + default boolean isAutoTaggingEnabled() { |
| 1079 | + return false; |
| 1080 | + } |
| 1081 | + |
1067 | 1082 | @Deprecated |
1068 | 1083 | @ObsoleteApi( |
1069 | 1084 | "This will be removed in an upcoming version without a major version bump. You should use" |
@@ -1168,6 +1183,18 @@ public boolean isEnableLocationApi() { |
1168 | 1183 | return Boolean.parseBoolean(System.getenv(EXPERIMENTAL_LOCATION_API_ENV_VAR)); |
1169 | 1184 | } |
1170 | 1185 |
|
| 1186 | + @Override |
| 1187 | + public boolean isAutoTaggingDisabled() { |
| 1188 | + return Boolean.parseBoolean(System.getenv("SPANNER_DISABLE_AUTO_TAGGING")) |
| 1189 | + || Boolean.parseBoolean(System.getProperty("spanner.disable_auto_tagging")); |
| 1190 | + } |
| 1191 | + |
| 1192 | + @Override |
| 1193 | + public boolean isAutoTaggingEnabled() { |
| 1194 | + return Boolean.parseBoolean(System.getenv("SPANNER_ENABLE_AUTO_TAGGING")) |
| 1195 | + || Boolean.getBoolean("spanner.enable_auto_tagging"); |
| 1196 | + } |
| 1197 | + |
1171 | 1198 | @Override |
1172 | 1199 | public String getMonitoringHost() { |
1173 | 1200 | return System.getenv(SPANNER_MONITORING_HOST); |
@@ -1256,6 +1283,9 @@ public static class Builder |
1256 | 1283 | private boolean usePlainText = false; |
1257 | 1284 | private TransactionOptions defaultTransactionOptions = TransactionOptions.getDefaultInstance(); |
1258 | 1285 | private RequestOptions.ClientContext clientContext; |
| 1286 | + private boolean autoTaggingEnabled = false; |
| 1287 | + private List<String> autoTaggingPackages = Collections.emptyList(); |
| 1288 | + private int autoTaggingTracerLimit = 50; |
1259 | 1289 |
|
1260 | 1290 | private static String createCustomClientLibToken(String token) { |
1261 | 1291 | return token + " " + ServiceOptions.getGoogApiClientLibName(); |
@@ -1362,6 +1392,9 @@ protected Builder() { |
1362 | 1392 | this.monitoringHost = options.monitoringHost; |
1363 | 1393 | this.defaultTransactionOptions = options.defaultTransactionOptions; |
1364 | 1394 | this.clientContext = options.clientContext; |
| 1395 | + this.autoTaggingEnabled = options.autoTaggingEnabled; |
| 1396 | + this.autoTaggingPackages = options.autoTaggingPackages; |
| 1397 | + this.autoTaggingTracerLimit = options.autoTaggingTracerLimit; |
1365 | 1398 | } |
1366 | 1399 |
|
1367 | 1400 | @Override |
@@ -2120,6 +2153,36 @@ public Builder setDefaultClientContext(RequestOptions.ClientContext clientContex |
2120 | 2153 | return this; |
2121 | 2154 | } |
2122 | 2155 |
|
| 2156 | + public Builder enableAutoTagging() { |
| 2157 | + this.autoTaggingEnabled = true; |
| 2158 | + return this; |
| 2159 | + } |
| 2160 | + |
| 2161 | + public Builder disableAutoTagging() { |
| 2162 | + this.autoTaggingEnabled = false; |
| 2163 | + return this; |
| 2164 | + } |
| 2165 | + |
| 2166 | + public Builder setAutoTaggingPackages(String... autoTaggingPackages) { |
| 2167 | + this.autoTaggingPackages = |
| 2168 | + Collections.unmodifiableList( |
| 2169 | + new ArrayList<>( |
| 2170 | + java.util.Arrays.asList(Preconditions.checkNotNull(autoTaggingPackages)))); |
| 2171 | + return this; |
| 2172 | + } |
| 2173 | + |
| 2174 | + public Builder setAutoTaggingPackages(List<String> autoTaggingPackages) { |
| 2175 | + this.autoTaggingPackages = |
| 2176 | + Collections.unmodifiableList( |
| 2177 | + new ArrayList<>(Preconditions.checkNotNull(autoTaggingPackages))); |
| 2178 | + return this; |
| 2179 | + } |
| 2180 | + |
| 2181 | + public Builder setAutoTaggingTracerLimit(int autoTaggingTracerLimit) { |
| 2182 | + this.autoTaggingTracerLimit = autoTaggingTracerLimit; |
| 2183 | + return this; |
| 2184 | + } |
| 2185 | + |
2123 | 2186 | @SuppressWarnings("rawtypes") |
2124 | 2187 | @Override |
2125 | 2188 | public SpannerOptions build() { |
@@ -2547,6 +2610,25 @@ public TransactionOptions getDefaultTransactionOptions() { |
2547 | 2610 | return defaultTransactionOptions; |
2548 | 2611 | } |
2549 | 2612 |
|
| 2613 | + public boolean isAutoTaggingEnabled() { |
| 2614 | + if (environment.isAutoTaggingDisabled()) { |
| 2615 | + return false; |
| 2616 | + } |
| 2617 | + return autoTaggingEnabled || environment.isAutoTaggingEnabled(); |
| 2618 | + } |
| 2619 | + |
| 2620 | + public List<String> getAutoTaggingPackages() { |
| 2621 | + return autoTaggingPackages; |
| 2622 | + } |
| 2623 | + |
| 2624 | + public int getAutoTaggingTracerLimit() { |
| 2625 | + return autoTaggingTracerLimit; |
| 2626 | + } |
| 2627 | + |
| 2628 | + public boolean isAutoTaggingDisabled() { |
| 2629 | + return environment.isAutoTaggingDisabled(); |
| 2630 | + } |
| 2631 | + |
2550 | 2632 | @BetaApi |
2551 | 2633 | public boolean isUseVirtualThreads() { |
2552 | 2634 | return useVirtualThreads; |
|
0 commit comments