Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ subprojects {
googleTraceVersion = '2.51.0'
googleCloudBomVersion = '26.48.0'
cloudMonitoringVersion = '3.52.0'
openTelemetryBomVersion = '1.47.0'
openTelemetryVersion = '1.47.0'
openTelemetryInstrumentationBomVersion = '2.12.0'
openTelemetryInstrumentationVersion = '2.12.0'
openTelemetrySemconvVersion = '1.29.0'
openTelemetryContribVersion = '1.44.0'
openTelemetryBomVersion = '1.49.0'
openTelemetryVersion = '1.49.0'
openTelemetryInstrumentationBomVersion = '2.15.0'
openTelemetryInstrumentationVersion = '2.15.0'
openTelemetrySemconvVersion = '1.32.0'
openTelemetryContribVersion = '1.46.0'
junitVersion = '4.13'
junit5Version = '5.10.0'
mockitoVersion = '5.2.0'
Expand Down Expand Up @@ -204,7 +204,8 @@ subprojects {
opentelemetry_context : "io.opentelemetry:opentelemetry-context:${openTelemetryVersion}",
opentelemetry_sdk : "io.opentelemetry:opentelemetry-sdk:${openTelemetryVersion}",
opentelemetry_sdk_common : "io.opentelemetry:opentelemetry-sdk-common:${openTelemetryVersion}",
opentelemetry_semconv : "io.opentelemetry.semconv:opentelemetry-semconv:${openTelemetrySemconvVersion}-alpha",
opentelemetry_semconv : "io.opentelemetry.semconv:opentelemetry-semconv:${openTelemetrySemconvVersion}",
opentelemetry_semconv_incubating : "io.opentelemetry.semconv:opentelemetry-semconv-incubating:${openTelemetrySemconvVersion}-alpha",
opentelemetry_sdk_metrics : "io.opentelemetry:opentelemetry-sdk-metrics:${openTelemetryVersion}",
opentelemetry_sdk_autoconf : "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:${openTelemetryVersion}",
opentelemetry_autoconfigure_spi : "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:${openTelemetryVersion}",
Expand Down
1 change: 1 addition & 0 deletions detectors/resources/build.gradle
Comment thread
tschut marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
implementation(libraries.opentelemetry_sdk)
implementation(libraries.opentelemetry_sdk_autoconf)
implementation(libraries.opentelemetry_semconv)
implementation(libraries.opentelemetry_semconv_incubating)
implementation platform(libraries.opentelemetry_bom)
implementation project(':detector-resources-support')
testImplementation(testLibraries.junit5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
package com.google.cloud.opentelemetry.detectors;

import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.semconv.ResourceAttributes;
import io.opentelemetry.semconv.incubating.CloudIncubatingAttributes;
import io.opentelemetry.semconv.incubating.FaasIncubatingAttributes;

/**
* A utility class that contains method that facilitate extraction of attributes from environment
* variables and metadata configurations.
*
* <p>This class only adds helper methods to extract {@link ResourceAttributes} that are common
* <p>This class only adds helper methods to extract {@link CloudIncubatingAttributes}
* and {@link FaasIncubatingAttributes} that are common
* across all the supported compute environments.
*
* @deprecated Not for public use. This class is expected to be retained only as package private.
Expand All @@ -37,7 +39,7 @@ public class AttributesExtractorUtil {
*
* <ul>
* <li>If the availability zone cannot be found, calling this method has no effect.
* <li>Calling this method will update {@link ResourceAttributes#CLOUD_AVAILABILITY_ZONE}
* <li>Calling this method will update {@link CloudIncubatingAttributes#CLOUD_AVAILABILITY_ZONE}
* attribute.
* </ul>
*
Expand All @@ -52,7 +54,7 @@ public static void addAvailabilityZoneFromMetadata(
AttributesBuilder attributesBuilder, GCPMetadataConfig metadataConfig) {
String zone = metadataConfig.getZone();
if (zone != null) {
attributesBuilder.put(ResourceAttributes.CLOUD_AVAILABILITY_ZONE, zone);
attributesBuilder.put(CloudIncubatingAttributes.CLOUD_AVAILABILITY_ZONE, zone);
}
}

Expand All @@ -62,7 +64,7 @@ public static void addAvailabilityZoneFromMetadata(
*
* <ul>
* <li>If the cloud region cannot be found, calling this method has no effect.
* <li>Calling this method will update {@link ResourceAttributes#CLOUD_REGION} attribute.
* <li>Calling this method will update {@link CloudIncubatingAttributes#CLOUD_REGION} attribute.
* <li>This method uses zone attribute to parse region from it.
* </ul>
*
Expand All @@ -80,7 +82,7 @@ public static void addCloudRegionFromMetadataUsingZone(
// Parsing required to scope up to a region
String[] splitArr = zone.split("-");
if (splitArr.length > 2) {
attributesBuilder.put(ResourceAttributes.CLOUD_REGION, splitArr[0] + "-" + splitArr[1]);
attributesBuilder.put(CloudIncubatingAttributes.CLOUD_REGION, splitArr[0] + "-" + splitArr[1]);
}
}
}
Expand All @@ -91,7 +93,7 @@ public static void addCloudRegionFromMetadataUsingZone(
*
* <ul>
* <li>If the cloud region cannot be found, calling this method has no effect.
* <li>Calling this method will update {@link ResourceAttributes#CLOUD_REGION} attribute.
* <li>Calling this method will update {@link CloudIncubatingAttributes#CLOUD_REGION} attribute.
* <li>This method directly uses the region attribute from the metadata config.
* </ul>
*
Expand All @@ -106,7 +108,7 @@ public static void addCloudRegionFromMetadataUsingRegion(
AttributesBuilder attributesBuilder, GCPMetadataConfig metadataConfig) {
String region = metadataConfig.getRegion();
if (region != null) {
attributesBuilder.put(ResourceAttributes.CLOUD_REGION, region);
attributesBuilder.put(CloudIncubatingAttributes.CLOUD_REGION, region);
}
}

Expand All @@ -117,7 +119,7 @@ public static void addCloudRegionFromMetadataUsingRegion(
*
* <ul>
* <li>If the instance ID cannot be found, calling this method has no effect.
* <li>Calling this method will update {@link ResourceAttributes#FAAS_INSTANCE} attribute.
* <li>Calling this method will update {@link FaasIncubatingAttributes#FAAS_INSTANCE} attribute.
* </ul>
*
* @param attributesBuilder The {@link AttributesBuilder} to which the extracted property needs to
Expand All @@ -129,7 +131,7 @@ public static void addInstanceIdFromMetadata(
AttributesBuilder attributesBuilder, GCPMetadataConfig metadataConfig) {
String instanceId = metadataConfig.getInstanceId();
if (instanceId != null) {
attributesBuilder.put(ResourceAttributes.FAAS_INSTANCE, instanceId);
attributesBuilder.put(FaasIncubatingAttributes.FAAS_INSTANCE, instanceId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.ResourceAttributes;
import io.opentelemetry.semconv.incubating.*;

import java.util.Map;
import java.util.Optional;
import java.util.logging.Logger;
Expand Down Expand Up @@ -68,8 +69,8 @@ public Attributes getAttributes() {

// This is running on some sort of GCPCompute - figure out the platform
AttributesBuilder attrBuilder = Attributes.builder();
attrBuilder.put(ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP);
attrBuilder.put(ResourceAttributes.CLOUD_ACCOUNT_ID, detectedPlatform.getProjectId());
attrBuilder.put(CloudIncubatingAttributes.CLOUD_PROVIDER, CloudIncubatingAttributes.CloudProviderIncubatingValues.GCP);
attrBuilder.put(CloudIncubatingAttributes.CLOUD_ACCOUNT_ID, detectedPlatform.getProjectId());

switch (detectedPlatform.getSupportedPlatform()) {
case GOOGLE_KUBERNETES_ENGINE:
Expand Down Expand Up @@ -107,27 +108,27 @@ public Resource createResource(ConfigProperties config) {
*/
private void addGCEAttributes(AttributesBuilder attrBuilder, Map<String, String> attributesMap) {
attrBuilder.put(
ResourceAttributes.CLOUD_PLATFORM,
ResourceAttributes.CloudPlatformValues.GCP_COMPUTE_ENGINE);
CloudIncubatingAttributes.CLOUD_PLATFORM,
CloudIncubatingAttributes.CloudPlatformIncubatingValues.GCP_COMPUTE_ENGINE);

Optional.ofNullable(attributesMap.get(GCE_AVAILABILITY_ZONE))
.ifPresent(zone -> attrBuilder.put(ResourceAttributes.CLOUD_AVAILABILITY_ZONE, zone));
.ifPresent(zone -> attrBuilder.put(CloudIncubatingAttributes.CLOUD_AVAILABILITY_ZONE, zone));
Optional.ofNullable(attributesMap.get(GCE_CLOUD_REGION))
.ifPresent(region -> attrBuilder.put(ResourceAttributes.CLOUD_REGION, region));
.ifPresent(region -> attrBuilder.put(CloudIncubatingAttributes.CLOUD_REGION, region));
Optional.ofNullable(attributesMap.get(GCE_INSTANCE_ID))
.ifPresent(instanceId -> attrBuilder.put(ResourceAttributes.HOST_ID, instanceId));
.ifPresent(instanceId -> attrBuilder.put(HostIncubatingAttributes.HOST_ID, instanceId));
Optional.ofNullable(attributesMap.get(GCE_INSTANCE_NAME))
.ifPresent(
instanceName -> {
attrBuilder.put(ResourceAttributes.HOST_NAME, instanceName);
attrBuilder.put(ResourceAttributes.GCP_GCE_INSTANCE_NAME, instanceName);
attrBuilder.put(HostIncubatingAttributes.HOST_NAME, instanceName);
attrBuilder.put(GcpIncubatingAttributes.GCP_GCE_INSTANCE_NAME, instanceName);
});
Optional.ofNullable(attributesMap.get(GCE_INSTANCE_HOSTNAME))
.ifPresent(
instanceHostname ->
attrBuilder.put(ResourceAttributes.GCP_GCE_INSTANCE_HOSTNAME, instanceHostname));
attrBuilder.put(GcpIncubatingAttributes.GCP_GCE_INSTANCE_HOSTNAME, instanceHostname));
Optional.ofNullable(attributesMap.get(GCE_MACHINE_TYPE))
.ifPresent(machineType -> attrBuilder.put(ResourceAttributes.HOST_TYPE, machineType));
.ifPresent(machineType -> attrBuilder.put(HostIncubatingAttributes.HOST_TYPE, machineType));
}

/**
Expand All @@ -139,26 +140,26 @@ private void addGCEAttributes(AttributesBuilder attrBuilder, Map<String, String>
*/
private void addGKEAttributes(AttributesBuilder attrBuilder, Map<String, String> attributesMap) {
attrBuilder.put(
ResourceAttributes.CLOUD_PLATFORM,
ResourceAttributes.CloudPlatformValues.GCP_KUBERNETES_ENGINE);
CloudIncubatingAttributes.CLOUD_PLATFORM,
CloudIncubatingAttributes.CloudPlatformIncubatingValues.GCP_KUBERNETES_ENGINE);

Optional.ofNullable(attributesMap.get(GKE_CLUSTER_NAME))
.ifPresent(
clusterName -> attrBuilder.put(ResourceAttributes.K8S_CLUSTER_NAME, clusterName));
clusterName -> attrBuilder.put(K8sIncubatingAttributes.K8S_CLUSTER_NAME, clusterName));
Optional.ofNullable(attributesMap.get(GKE_HOST_ID))
.ifPresent(hostId -> attrBuilder.put(ResourceAttributes.HOST_ID, hostId));
.ifPresent(hostId -> attrBuilder.put(HostIncubatingAttributes.HOST_ID, hostId));
Optional.ofNullable(attributesMap.get(GKE_CLUSTER_LOCATION_TYPE))
.ifPresent(
locationType -> {
if (attributesMap.get(GKE_CLUSTER_LOCATION) != null) {
switch (locationType) {
case GKE_LOCATION_TYPE_REGION:
attrBuilder.put(
ResourceAttributes.CLOUD_REGION, attributesMap.get(GKE_CLUSTER_LOCATION));
CloudIncubatingAttributes.CLOUD_REGION, attributesMap.get(GKE_CLUSTER_LOCATION));
break;
case GKE_LOCATION_TYPE_ZONE:
attrBuilder.put(
ResourceAttributes.CLOUD_AVAILABILITY_ZONE,
CloudIncubatingAttributes.CLOUD_AVAILABILITY_ZONE,
attributesMap.get(GKE_CLUSTER_LOCATION));
default:
// TODO: Figure out how to handle unexpected conditions like this - Issue #183
Expand All @@ -180,7 +181,7 @@ private void addGKEAttributes(AttributesBuilder attrBuilder, Map<String, String>
*/
private void addGCRAttributes(AttributesBuilder attrBuilder, Map<String, String> attributesMap) {
attrBuilder.put(
ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.GCP_CLOUD_RUN);
CloudIncubatingAttributes.CLOUD_PLATFORM, CloudIncubatingAttributes.CloudPlatformIncubatingValues.GCP_CLOUD_RUN);
addCommonAttributesForServerlessCompute(attrBuilder, attributesMap);
}

Expand All @@ -193,8 +194,8 @@ private void addGCRAttributes(AttributesBuilder attrBuilder, Map<String, String>
*/
private void addGCFAttributes(AttributesBuilder attrBuilder, Map<String, String> attributesMap) {
attrBuilder.put(
ResourceAttributes.CLOUD_PLATFORM,
ResourceAttributes.CloudPlatformValues.GCP_CLOUD_FUNCTIONS);
CloudIncubatingAttributes.CLOUD_PLATFORM,
CloudIncubatingAttributes.CloudPlatformIncubatingValues.GCP_CLOUD_FUNCTIONS);
addCommonAttributesForServerlessCompute(attrBuilder, attributesMap);
}

Expand All @@ -207,20 +208,20 @@ private void addGCFAttributes(AttributesBuilder attrBuilder, Map<String, String>
*/
private void addGAEAttributes(AttributesBuilder attrBuilder, Map<String, String> attributesMap) {
attrBuilder.put(
ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.GCP_APP_ENGINE);
CloudIncubatingAttributes.CLOUD_PLATFORM, CloudIncubatingAttributes.CloudPlatformIncubatingValues.GCP_APP_ENGINE);
Optional.ofNullable(attributesMap.get(GAE_MODULE_NAME))
.ifPresent(appName -> attrBuilder.put(ResourceAttributes.FAAS_NAME, appName));
.ifPresent(appName -> attrBuilder.put(FaasIncubatingAttributes.FAAS_NAME, appName));
Optional.ofNullable(attributesMap.get(GAE_APP_VERSION))
.ifPresent(appVersion -> attrBuilder.put(ResourceAttributes.FAAS_VERSION, appVersion));
.ifPresent(appVersion -> attrBuilder.put(FaasIncubatingAttributes.FAAS_VERSION, appVersion));
Optional.ofNullable(attributesMap.get(GAE_INSTANCE_ID))
.ifPresent(
appInstanceId -> attrBuilder.put(ResourceAttributes.FAAS_INSTANCE, appInstanceId));
appInstanceId -> attrBuilder.put(FaasIncubatingAttributes.FAAS_INSTANCE, appInstanceId));
Optional.ofNullable(attributesMap.get(GAE_CLOUD_REGION))
.ifPresent(cloudRegion -> attrBuilder.put(ResourceAttributes.CLOUD_REGION, cloudRegion));
.ifPresent(cloudRegion -> attrBuilder.put(CloudIncubatingAttributes.CLOUD_REGION, cloudRegion));
Optional.ofNullable(attributesMap.get(GAE_AVAILABILITY_ZONE))
.ifPresent(
cloudAvailabilityZone ->
attrBuilder.put(ResourceAttributes.CLOUD_AVAILABILITY_ZONE, cloudAvailabilityZone));
attrBuilder.put(CloudIncubatingAttributes.CLOUD_AVAILABILITY_ZONE, cloudAvailabilityZone));
}

/**
Expand All @@ -233,14 +234,14 @@ private void addGAEAttributes(AttributesBuilder attrBuilder, Map<String, String>
private void addCommonAttributesForServerlessCompute(
AttributesBuilder attrBuilder, Map<String, String> attributesMap) {
Optional.ofNullable(attributesMap.get(SERVERLESS_COMPUTE_NAME))
.ifPresent(name -> attrBuilder.put(ResourceAttributes.FAAS_NAME, name));
.ifPresent(name -> attrBuilder.put(FaasIncubatingAttributes.FAAS_NAME, name));
Optional.ofNullable(attributesMap.get(SERVERLESS_COMPUTE_REVISION))
.ifPresent(revision -> attrBuilder.put(ResourceAttributes.FAAS_VERSION, revision));
.ifPresent(revision -> attrBuilder.put(FaasIncubatingAttributes.FAAS_VERSION, revision));
Optional.ofNullable(attributesMap.get(SERVERLESS_COMPUTE_INSTANCE_ID))
.ifPresent(instanceId -> attrBuilder.put(ResourceAttributes.FAAS_INSTANCE, instanceId));
.ifPresent(instanceId -> attrBuilder.put(FaasIncubatingAttributes.FAAS_INSTANCE, instanceId));
Optional.ofNullable(attributesMap.get(SERVERLESS_COMPUTE_AVAILABILITY_ZONE))
.ifPresent(zone -> attrBuilder.put(ResourceAttributes.CLOUD_AVAILABILITY_ZONE, zone));
.ifPresent(zone -> attrBuilder.put(CloudIncubatingAttributes.CLOUD_AVAILABILITY_ZONE, zone));
Optional.ofNullable(attributesMap.get(SERVERLESS_COMPUTE_CLOUD_REGION))
.ifPresent(region -> attrBuilder.put(ResourceAttributes.CLOUD_REGION, region));
.ifPresent(region -> attrBuilder.put(CloudIncubatingAttributes.CLOUD_REGION, region));
}
}
Loading
Loading