Skip to content

Commit e546d0b

Browse files
authored
Update OpenTelemetry dependencies (#413)
* Update OpenTelemetry dependencies (cherry picked from commit b7c0dc1) * Run `./gradlew spotlessApply` * Remove * imports * More `./gradlew spotlessApply`
1 parent c671829 commit e546d0b

File tree

14 files changed

+387
-320
lines changed

14 files changed

+387
-320
lines changed

build.gradle

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,12 @@ subprojects {
160160
googleTraceVersion = '2.51.0'
161161
googleCloudBomVersion = '26.48.0'
162162
cloudMonitoringVersion = '3.52.0'
163-
openTelemetryBomVersion = '1.47.0'
164-
openTelemetryVersion = '1.47.0'
165-
openTelemetryInstrumentationBomVersion = '2.12.0'
166-
openTelemetryInstrumentationVersion = '2.12.0'
167-
openTelemetrySemconvVersion = '1.29.0'
168-
openTelemetryContribVersion = '1.44.0'
163+
openTelemetryBomVersion = '1.49.0'
164+
openTelemetryVersion = '1.49.0'
165+
openTelemetryInstrumentationBomVersion = '2.15.0'
166+
openTelemetryInstrumentationVersion = '2.15.0'
167+
openTelemetrySemconvVersion = '1.32.0'
168+
openTelemetryContribVersion = '1.46.0'
169169
junitVersion = '4.13'
170170
junit5Version = '5.10.0'
171171
mockitoVersion = '5.2.0'
@@ -204,7 +204,8 @@ subprojects {
204204
opentelemetry_context : "io.opentelemetry:opentelemetry-context:${openTelemetryVersion}",
205205
opentelemetry_sdk : "io.opentelemetry:opentelemetry-sdk:${openTelemetryVersion}",
206206
opentelemetry_sdk_common : "io.opentelemetry:opentelemetry-sdk-common:${openTelemetryVersion}",
207-
opentelemetry_semconv : "io.opentelemetry.semconv:opentelemetry-semconv:${openTelemetrySemconvVersion}-alpha",
207+
opentelemetry_semconv : "io.opentelemetry.semconv:opentelemetry-semconv:${openTelemetrySemconvVersion}",
208+
opentelemetry_semconv_incubating : "io.opentelemetry.semconv:opentelemetry-semconv-incubating:${openTelemetrySemconvVersion}-alpha",
208209
opentelemetry_sdk_metrics : "io.opentelemetry:opentelemetry-sdk-metrics:${openTelemetryVersion}",
209210
opentelemetry_sdk_autoconf : "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:${openTelemetryVersion}",
210211
opentelemetry_autoconfigure_spi : "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:${openTelemetryVersion}",

detectors/resources/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dependencies {
2020
implementation(libraries.opentelemetry_sdk)
2121
implementation(libraries.opentelemetry_sdk_autoconf)
2222
implementation(libraries.opentelemetry_semconv)
23+
implementation(libraries.opentelemetry_semconv_incubating)
2324
implementation platform(libraries.opentelemetry_bom)
2425
implementation project(':detector-resources-support')
2526
testImplementation(testLibraries.junit5)

detectors/resources/src/main/java/com/google/cloud/opentelemetry/detectors/AttributesExtractorUtil.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
package com.google.cloud.opentelemetry.detectors;
1717

1818
import io.opentelemetry.api.common.AttributesBuilder;
19-
import io.opentelemetry.semconv.ResourceAttributes;
19+
import io.opentelemetry.semconv.incubating.CloudIncubatingAttributes;
20+
import io.opentelemetry.semconv.incubating.FaasIncubatingAttributes;
2021

2122
/**
2223
* A utility class that contains method that facilitate extraction of attributes from environment
2324
* variables and metadata configurations.
2425
*
25-
* <p>This class only adds helper methods to extract {@link ResourceAttributes} that are common
26-
* across all the supported compute environments.
26+
* <p>This class only adds helper methods to extract {@link CloudIncubatingAttributes} and {@link
27+
* FaasIncubatingAttributes} that are common across all the supported compute environments.
2728
*
2829
* @deprecated Not for public use. This class is expected to be retained only as package private.
2930
*/
@@ -37,7 +38,7 @@ public class AttributesExtractorUtil {
3738
*
3839
* <ul>
3940
* <li>If the availability zone cannot be found, calling this method has no effect.
40-
* <li>Calling this method will update {@link ResourceAttributes#CLOUD_AVAILABILITY_ZONE}
41+
* <li>Calling this method will update {@link CloudIncubatingAttributes#CLOUD_AVAILABILITY_ZONE}
4142
* attribute.
4243
* </ul>
4344
*
@@ -52,7 +53,7 @@ public static void addAvailabilityZoneFromMetadata(
5253
AttributesBuilder attributesBuilder, GCPMetadataConfig metadataConfig) {
5354
String zone = metadataConfig.getZone();
5455
if (zone != null) {
55-
attributesBuilder.put(ResourceAttributes.CLOUD_AVAILABILITY_ZONE, zone);
56+
attributesBuilder.put(CloudIncubatingAttributes.CLOUD_AVAILABILITY_ZONE, zone);
5657
}
5758
}
5859

@@ -62,7 +63,7 @@ public static void addAvailabilityZoneFromMetadata(
6263
*
6364
* <ul>
6465
* <li>If the cloud region cannot be found, calling this method has no effect.
65-
* <li>Calling this method will update {@link ResourceAttributes#CLOUD_REGION} attribute.
66+
* <li>Calling this method will update {@link CloudIncubatingAttributes#CLOUD_REGION} attribute.
6667
* <li>This method uses zone attribute to parse region from it.
6768
* </ul>
6869
*
@@ -80,7 +81,8 @@ public static void addCloudRegionFromMetadataUsingZone(
8081
// Parsing required to scope up to a region
8182
String[] splitArr = zone.split("-");
8283
if (splitArr.length > 2) {
83-
attributesBuilder.put(ResourceAttributes.CLOUD_REGION, splitArr[0] + "-" + splitArr[1]);
84+
attributesBuilder.put(
85+
CloudIncubatingAttributes.CLOUD_REGION, splitArr[0] + "-" + splitArr[1]);
8486
}
8587
}
8688
}
@@ -91,7 +93,7 @@ public static void addCloudRegionFromMetadataUsingZone(
9193
*
9294
* <ul>
9395
* <li>If the cloud region cannot be found, calling this method has no effect.
94-
* <li>Calling this method will update {@link ResourceAttributes#CLOUD_REGION} attribute.
96+
* <li>Calling this method will update {@link CloudIncubatingAttributes#CLOUD_REGION} attribute.
9597
* <li>This method directly uses the region attribute from the metadata config.
9698
* </ul>
9799
*
@@ -106,7 +108,7 @@ public static void addCloudRegionFromMetadataUsingRegion(
106108
AttributesBuilder attributesBuilder, GCPMetadataConfig metadataConfig) {
107109
String region = metadataConfig.getRegion();
108110
if (region != null) {
109-
attributesBuilder.put(ResourceAttributes.CLOUD_REGION, region);
111+
attributesBuilder.put(CloudIncubatingAttributes.CLOUD_REGION, region);
110112
}
111113
}
112114

@@ -117,7 +119,7 @@ public static void addCloudRegionFromMetadataUsingRegion(
117119
*
118120
* <ul>
119121
* <li>If the instance ID cannot be found, calling this method has no effect.
120-
* <li>Calling this method will update {@link ResourceAttributes#FAAS_INSTANCE} attribute.
122+
* <li>Calling this method will update {@link FaasIncubatingAttributes#FAAS_INSTANCE} attribute.
121123
* </ul>
122124
*
123125
* @param attributesBuilder The {@link AttributesBuilder} to which the extracted property needs to
@@ -129,7 +131,7 @@ public static void addInstanceIdFromMetadata(
129131
AttributesBuilder attributesBuilder, GCPMetadataConfig metadataConfig) {
130132
String instanceId = metadataConfig.getInstanceId();
131133
if (instanceId != null) {
132-
attributesBuilder.put(ResourceAttributes.FAAS_INSTANCE, instanceId);
134+
attributesBuilder.put(FaasIncubatingAttributes.FAAS_INSTANCE, instanceId);
133135
}
134136
}
135137
}

detectors/resources/src/main/java/com/google/cloud/opentelemetry/detectors/GCPResource.java

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
2525
import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider;
2626
import io.opentelemetry.sdk.resources.Resource;
27-
import io.opentelemetry.semconv.ResourceAttributes;
27+
import io.opentelemetry.semconv.incubating.CloudIncubatingAttributes;
28+
import io.opentelemetry.semconv.incubating.FaasIncubatingAttributes;
29+
import io.opentelemetry.semconv.incubating.GcpIncubatingAttributes;
30+
import io.opentelemetry.semconv.incubating.HostIncubatingAttributes;
31+
import io.opentelemetry.semconv.incubating.K8sIncubatingAttributes;
2832
import java.util.Map;
2933
import java.util.Optional;
3034
import java.util.logging.Logger;
@@ -68,8 +72,10 @@ public Attributes getAttributes() {
6872

6973
// This is running on some sort of GCPCompute - figure out the platform
7074
AttributesBuilder attrBuilder = Attributes.builder();
71-
attrBuilder.put(ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP);
72-
attrBuilder.put(ResourceAttributes.CLOUD_ACCOUNT_ID, detectedPlatform.getProjectId());
75+
attrBuilder.put(
76+
CloudIncubatingAttributes.CLOUD_PROVIDER,
77+
CloudIncubatingAttributes.CloudProviderIncubatingValues.GCP);
78+
attrBuilder.put(CloudIncubatingAttributes.CLOUD_ACCOUNT_ID, detectedPlatform.getProjectId());
7379

7480
switch (detectedPlatform.getSupportedPlatform()) {
7581
case GOOGLE_KUBERNETES_ENGINE:
@@ -107,27 +113,29 @@ public Resource createResource(ConfigProperties config) {
107113
*/
108114
private void addGCEAttributes(AttributesBuilder attrBuilder, Map<String, String> attributesMap) {
109115
attrBuilder.put(
110-
ResourceAttributes.CLOUD_PLATFORM,
111-
ResourceAttributes.CloudPlatformValues.GCP_COMPUTE_ENGINE);
116+
CloudIncubatingAttributes.CLOUD_PLATFORM,
117+
CloudIncubatingAttributes.CloudPlatformIncubatingValues.GCP_COMPUTE_ENGINE);
112118

113119
Optional.ofNullable(attributesMap.get(GCE_AVAILABILITY_ZONE))
114-
.ifPresent(zone -> attrBuilder.put(ResourceAttributes.CLOUD_AVAILABILITY_ZONE, zone));
120+
.ifPresent(
121+
zone -> attrBuilder.put(CloudIncubatingAttributes.CLOUD_AVAILABILITY_ZONE, zone));
115122
Optional.ofNullable(attributesMap.get(GCE_CLOUD_REGION))
116-
.ifPresent(region -> attrBuilder.put(ResourceAttributes.CLOUD_REGION, region));
123+
.ifPresent(region -> attrBuilder.put(CloudIncubatingAttributes.CLOUD_REGION, region));
117124
Optional.ofNullable(attributesMap.get(GCE_INSTANCE_ID))
118-
.ifPresent(instanceId -> attrBuilder.put(ResourceAttributes.HOST_ID, instanceId));
125+
.ifPresent(instanceId -> attrBuilder.put(HostIncubatingAttributes.HOST_ID, instanceId));
119126
Optional.ofNullable(attributesMap.get(GCE_INSTANCE_NAME))
120127
.ifPresent(
121128
instanceName -> {
122-
attrBuilder.put(ResourceAttributes.HOST_NAME, instanceName);
123-
attrBuilder.put(ResourceAttributes.GCP_GCE_INSTANCE_NAME, instanceName);
129+
attrBuilder.put(HostIncubatingAttributes.HOST_NAME, instanceName);
130+
attrBuilder.put(GcpIncubatingAttributes.GCP_GCE_INSTANCE_NAME, instanceName);
124131
});
125132
Optional.ofNullable(attributesMap.get(GCE_INSTANCE_HOSTNAME))
126133
.ifPresent(
127134
instanceHostname ->
128-
attrBuilder.put(ResourceAttributes.GCP_GCE_INSTANCE_HOSTNAME, instanceHostname));
135+
attrBuilder.put(
136+
GcpIncubatingAttributes.GCP_GCE_INSTANCE_HOSTNAME, instanceHostname));
129137
Optional.ofNullable(attributesMap.get(GCE_MACHINE_TYPE))
130-
.ifPresent(machineType -> attrBuilder.put(ResourceAttributes.HOST_TYPE, machineType));
138+
.ifPresent(machineType -> attrBuilder.put(HostIncubatingAttributes.HOST_TYPE, machineType));
131139
}
132140

133141
/**
@@ -139,26 +147,27 @@ private void addGCEAttributes(AttributesBuilder attrBuilder, Map<String, String>
139147
*/
140148
private void addGKEAttributes(AttributesBuilder attrBuilder, Map<String, String> attributesMap) {
141149
attrBuilder.put(
142-
ResourceAttributes.CLOUD_PLATFORM,
143-
ResourceAttributes.CloudPlatformValues.GCP_KUBERNETES_ENGINE);
150+
CloudIncubatingAttributes.CLOUD_PLATFORM,
151+
CloudIncubatingAttributes.CloudPlatformIncubatingValues.GCP_KUBERNETES_ENGINE);
144152

145153
Optional.ofNullable(attributesMap.get(GKE_CLUSTER_NAME))
146154
.ifPresent(
147-
clusterName -> attrBuilder.put(ResourceAttributes.K8S_CLUSTER_NAME, clusterName));
155+
clusterName -> attrBuilder.put(K8sIncubatingAttributes.K8S_CLUSTER_NAME, clusterName));
148156
Optional.ofNullable(attributesMap.get(GKE_HOST_ID))
149-
.ifPresent(hostId -> attrBuilder.put(ResourceAttributes.HOST_ID, hostId));
157+
.ifPresent(hostId -> attrBuilder.put(HostIncubatingAttributes.HOST_ID, hostId));
150158
Optional.ofNullable(attributesMap.get(GKE_CLUSTER_LOCATION_TYPE))
151159
.ifPresent(
152160
locationType -> {
153161
if (attributesMap.get(GKE_CLUSTER_LOCATION) != null) {
154162
switch (locationType) {
155163
case GKE_LOCATION_TYPE_REGION:
156164
attrBuilder.put(
157-
ResourceAttributes.CLOUD_REGION, attributesMap.get(GKE_CLUSTER_LOCATION));
165+
CloudIncubatingAttributes.CLOUD_REGION,
166+
attributesMap.get(GKE_CLUSTER_LOCATION));
158167
break;
159168
case GKE_LOCATION_TYPE_ZONE:
160169
attrBuilder.put(
161-
ResourceAttributes.CLOUD_AVAILABILITY_ZONE,
170+
CloudIncubatingAttributes.CLOUD_AVAILABILITY_ZONE,
162171
attributesMap.get(GKE_CLUSTER_LOCATION));
163172
default:
164173
// TODO: Figure out how to handle unexpected conditions like this - Issue #183
@@ -180,7 +189,8 @@ private void addGKEAttributes(AttributesBuilder attrBuilder, Map<String, String>
180189
*/
181190
private void addGCRAttributes(AttributesBuilder attrBuilder, Map<String, String> attributesMap) {
182191
attrBuilder.put(
183-
ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.GCP_CLOUD_RUN);
192+
CloudIncubatingAttributes.CLOUD_PLATFORM,
193+
CloudIncubatingAttributes.CloudPlatformIncubatingValues.GCP_CLOUD_RUN);
184194
addCommonAttributesForServerlessCompute(attrBuilder, attributesMap);
185195
}
186196

@@ -193,8 +203,8 @@ private void addGCRAttributes(AttributesBuilder attrBuilder, Map<String, String>
193203
*/
194204
private void addGCFAttributes(AttributesBuilder attrBuilder, Map<String, String> attributesMap) {
195205
attrBuilder.put(
196-
ResourceAttributes.CLOUD_PLATFORM,
197-
ResourceAttributes.CloudPlatformValues.GCP_CLOUD_FUNCTIONS);
206+
CloudIncubatingAttributes.CLOUD_PLATFORM,
207+
CloudIncubatingAttributes.CloudPlatformIncubatingValues.GCP_CLOUD_FUNCTIONS);
198208
addCommonAttributesForServerlessCompute(attrBuilder, attributesMap);
199209
}
200210

@@ -207,20 +217,25 @@ private void addGCFAttributes(AttributesBuilder attrBuilder, Map<String, String>
207217
*/
208218
private void addGAEAttributes(AttributesBuilder attrBuilder, Map<String, String> attributesMap) {
209219
attrBuilder.put(
210-
ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.GCP_APP_ENGINE);
220+
CloudIncubatingAttributes.CLOUD_PLATFORM,
221+
CloudIncubatingAttributes.CloudPlatformIncubatingValues.GCP_APP_ENGINE);
211222
Optional.ofNullable(attributesMap.get(GAE_MODULE_NAME))
212-
.ifPresent(appName -> attrBuilder.put(ResourceAttributes.FAAS_NAME, appName));
223+
.ifPresent(appName -> attrBuilder.put(FaasIncubatingAttributes.FAAS_NAME, appName));
213224
Optional.ofNullable(attributesMap.get(GAE_APP_VERSION))
214-
.ifPresent(appVersion -> attrBuilder.put(ResourceAttributes.FAAS_VERSION, appVersion));
225+
.ifPresent(
226+
appVersion -> attrBuilder.put(FaasIncubatingAttributes.FAAS_VERSION, appVersion));
215227
Optional.ofNullable(attributesMap.get(GAE_INSTANCE_ID))
216228
.ifPresent(
217-
appInstanceId -> attrBuilder.put(ResourceAttributes.FAAS_INSTANCE, appInstanceId));
229+
appInstanceId ->
230+
attrBuilder.put(FaasIncubatingAttributes.FAAS_INSTANCE, appInstanceId));
218231
Optional.ofNullable(attributesMap.get(GAE_CLOUD_REGION))
219-
.ifPresent(cloudRegion -> attrBuilder.put(ResourceAttributes.CLOUD_REGION, cloudRegion));
232+
.ifPresent(
233+
cloudRegion -> attrBuilder.put(CloudIncubatingAttributes.CLOUD_REGION, cloudRegion));
220234
Optional.ofNullable(attributesMap.get(GAE_AVAILABILITY_ZONE))
221235
.ifPresent(
222236
cloudAvailabilityZone ->
223-
attrBuilder.put(ResourceAttributes.CLOUD_AVAILABILITY_ZONE, cloudAvailabilityZone));
237+
attrBuilder.put(
238+
CloudIncubatingAttributes.CLOUD_AVAILABILITY_ZONE, cloudAvailabilityZone));
224239
}
225240

226241
/**
@@ -233,14 +248,16 @@ private void addGAEAttributes(AttributesBuilder attrBuilder, Map<String, String>
233248
private void addCommonAttributesForServerlessCompute(
234249
AttributesBuilder attrBuilder, Map<String, String> attributesMap) {
235250
Optional.ofNullable(attributesMap.get(SERVERLESS_COMPUTE_NAME))
236-
.ifPresent(name -> attrBuilder.put(ResourceAttributes.FAAS_NAME, name));
251+
.ifPresent(name -> attrBuilder.put(FaasIncubatingAttributes.FAAS_NAME, name));
237252
Optional.ofNullable(attributesMap.get(SERVERLESS_COMPUTE_REVISION))
238-
.ifPresent(revision -> attrBuilder.put(ResourceAttributes.FAAS_VERSION, revision));
253+
.ifPresent(revision -> attrBuilder.put(FaasIncubatingAttributes.FAAS_VERSION, revision));
239254
Optional.ofNullable(attributesMap.get(SERVERLESS_COMPUTE_INSTANCE_ID))
240-
.ifPresent(instanceId -> attrBuilder.put(ResourceAttributes.FAAS_INSTANCE, instanceId));
255+
.ifPresent(
256+
instanceId -> attrBuilder.put(FaasIncubatingAttributes.FAAS_INSTANCE, instanceId));
241257
Optional.ofNullable(attributesMap.get(SERVERLESS_COMPUTE_AVAILABILITY_ZONE))
242-
.ifPresent(zone -> attrBuilder.put(ResourceAttributes.CLOUD_AVAILABILITY_ZONE, zone));
258+
.ifPresent(
259+
zone -> attrBuilder.put(CloudIncubatingAttributes.CLOUD_AVAILABILITY_ZONE, zone));
243260
Optional.ofNullable(attributesMap.get(SERVERLESS_COMPUTE_CLOUD_REGION))
244-
.ifPresent(region -> attrBuilder.put(ResourceAttributes.CLOUD_REGION, region));
261+
.ifPresent(region -> attrBuilder.put(CloudIncubatingAttributes.CLOUD_REGION, region));
245262
}
246263
}

0 commit comments

Comments
 (0)