|
16 | 16 |
|
17 | 17 | package com.google.cloud.spanner; |
18 | 18 |
|
19 | | -import static com.google.cloud.opentelemetry.detection.GCPPlatformDetector.SupportedPlatform.GOOGLE_KUBERNETES_ENGINE; |
20 | 19 | import static com.google.cloud.spanner.BuiltInMetricsConstant.CLIENT_HASH_KEY; |
21 | 20 | import static com.google.cloud.spanner.BuiltInMetricsConstant.CLIENT_NAME_KEY; |
22 | 21 | import static com.google.cloud.spanner.BuiltInMetricsConstant.CLIENT_UID_KEY; |
|
29 | 28 | import com.google.api.gax.core.GaxProperties; |
30 | 29 | import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; |
31 | 30 | import com.google.auth.Credentials; |
32 | | -import com.google.cloud.opentelemetry.detection.AttributeKeys; |
33 | | -import com.google.cloud.opentelemetry.detection.DetectedPlatform; |
34 | | -import com.google.cloud.opentelemetry.detection.GCPPlatformDetector; |
35 | 31 | import com.google.common.annotations.VisibleForTesting; |
36 | 32 | import com.google.common.base.Strings; |
37 | 33 | import com.google.common.hash.HashFunction; |
38 | 34 | import com.google.common.hash.Hashing; |
39 | 35 | import io.grpc.ManagedChannelBuilder; |
40 | 36 | import io.grpc.opentelemetry.GrpcOpenTelemetry; |
41 | 37 | import io.opentelemetry.api.OpenTelemetry; |
| 38 | +import io.opentelemetry.api.common.AttributeKey; |
42 | 39 | import io.opentelemetry.api.common.Attributes; |
43 | 40 | import io.opentelemetry.api.common.AttributesBuilder; |
| 41 | +import io.opentelemetry.contrib.gcp.resource.GCPResourceProvider; |
44 | 42 | import io.opentelemetry.sdk.OpenTelemetrySdk; |
45 | 43 | import io.opentelemetry.sdk.metrics.SdkMeterProvider; |
46 | 44 | import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder; |
@@ -264,12 +262,14 @@ static String detectClientLocation() { |
264 | 262 | if (location == null) { |
265 | 263 | location = default_location; |
266 | 264 | if (quickCheckIsRunningOnGcp()) { |
267 | | - GCPPlatformDetector detector = GCPPlatformDetector.DEFAULT_INSTANCE; |
268 | | - DetectedPlatform detectedPlatform = detector.detectPlatform(); |
269 | | - // All platform except GKE uses "cloud_region" for region attribute. |
270 | | - String region = detectedPlatform.getAttributes().get("cloud_region"); |
271 | | - if (detectedPlatform.getSupportedPlatform() == GOOGLE_KUBERNETES_ENGINE) { |
272 | | - region = detectedPlatform.getAttributes().get(AttributeKeys.GKE_CLUSTER_LOCATION); |
| 265 | + Attributes detectedResourceAttributes = new GCPResourceProvider().getAttributes(); |
| 266 | + // All platform except GKE uses "cloud.region" for region attribute. |
| 267 | + // GKE could either use "cloud.region" or "cloud.availability_zone" for region attribute. |
| 268 | + String region = detectedResourceAttributes.get(AttributeKey.stringKey("cloud.region")); |
| 269 | + String gkeZonalClusterLocation = |
| 270 | + detectedResourceAttributes.get(AttributeKey.stringKey("cloud.availability_zone")); |
| 271 | + if (region == null && gkeZonalClusterLocation != null) { |
| 272 | + region = gkeZonalClusterLocation; |
273 | 273 | } |
274 | 274 | location = region == null ? location : region; |
275 | 275 | } |
|
0 commit comments