Skip to content

Commit

Permalink
Update dependency io.opentelemetry.instrumentation:opentelemetry-inst…
Browse files Browse the repository at this point in the history
…rumentation-bom-alpha to v2.3.0-alpha (#1267)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
  • Loading branch information
renovate[bot] and trask committed Apr 16, 2024
1 parent 425bfb9 commit baf0eaa
Show file tree
Hide file tree
Showing 39 changed files with 383 additions and 309 deletions.
1 change: 1 addition & 0 deletions aws-resources/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
api("io.opentelemetry:opentelemetry-sdk")

implementation("io.opentelemetry.semconv:opentelemetry-semconv")
implementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating:1.25.0-alpha")

compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@

package io.opentelemetry.contrib.aws.resource;

import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_VERSION;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_PLATFORM;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_PROVIDER;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CloudPlatformValues.AWS_ELASTIC_BEANSTALK;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CloudProviderValues.AWS;
import static io.opentelemetry.semconv.incubating.ServiceIncubatingAttributes.SERVICE_INSTANCE_ID;
import static io.opentelemetry.semconv.incubating.ServiceIncubatingAttributes.SERVICE_NAMESPACE;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.ResourceAttributes;
import io.opentelemetry.semconv.SchemaUrls;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
Expand Down Expand Up @@ -58,21 +66,21 @@ static Resource buildResource(String configPath) {

if (!parser.isExpectedStartObjectToken()) {
logger.log(Level.WARNING, "Invalid Beanstalk config: ", configPath);
return Resource.create(attrBuilders.build(), ResourceAttributes.SCHEMA_URL);
return Resource.create(attrBuilders.build(), SchemaUrls.V1_25_0);
}

while (parser.nextToken() != JsonToken.END_OBJECT) {
parser.nextValue();
String value = parser.getText();
switch (parser.currentName()) {
case DEVELOPMENT_ID:
attrBuilders.put(ResourceAttributes.SERVICE_INSTANCE_ID, value);
attrBuilders.put(SERVICE_INSTANCE_ID, value);
break;
case VERSION_LABEL:
attrBuilders.put(ResourceAttributes.SERVICE_VERSION, value);
attrBuilders.put(SERVICE_VERSION, value);
break;
case ENVIRONMENT_NAME:
attrBuilders.put(ResourceAttributes.SERVICE_NAMESPACE, value);
attrBuilders.put(SERVICE_NAMESPACE, value);
break;
default:
parser.skipChildren();
Expand All @@ -83,12 +91,10 @@ static Resource buildResource(String configPath) {
return Resource.empty();
}

attrBuilders.put(ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.AWS);
attrBuilders.put(
ResourceAttributes.CLOUD_PLATFORM,
ResourceAttributes.CloudPlatformValues.AWS_ELASTIC_BEANSTALK);
attrBuilders.put(CLOUD_PROVIDER, AWS);
attrBuilders.put(CLOUD_PLATFORM, AWS_ELASTIC_BEANSTALK);

return Resource.create(attrBuilders.build(), ResourceAttributes.SCHEMA_URL);
return Resource.create(attrBuilders.build(), SchemaUrls.V1_25_0);
}

private BeanstalkResource() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@

package io.opentelemetry.contrib.aws.resource;

import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_ACCOUNT_ID;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_AVAILABILITY_ZONE;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_PLATFORM;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_PROVIDER;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_REGION;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CloudPlatformValues.AWS_EC2;
import static io.opentelemetry.semconv.incubating.HostIncubatingAttributes.HOST_ID;
import static io.opentelemetry.semconv.incubating.HostIncubatingAttributes.HOST_IMAGE_ID;
import static io.opentelemetry.semconv.incubating.HostIncubatingAttributes.HOST_NAME;
import static io.opentelemetry.semconv.incubating.HostIncubatingAttributes.HOST_TYPE;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.ResourceAttributes;
import io.opentelemetry.semconv.SchemaUrls;
import io.opentelemetry.semconv.incubating.CloudIncubatingAttributes;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -78,9 +90,8 @@ static Resource buildResource(String endpoint) {
String hostname = fetchHostname(hostnameUrl, token);

AttributesBuilder attrBuilders = Attributes.builder();
attrBuilders.put(ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.AWS);
attrBuilders.put(
ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EC2);
attrBuilders.put(CLOUD_PROVIDER, CloudIncubatingAttributes.CloudProviderValues.AWS);
attrBuilders.put(CLOUD_PLATFORM, AWS_EC2);

try (JsonParser parser = JSON_FACTORY.createParser(identity)) {
parser.nextToken();
Expand All @@ -93,22 +104,22 @@ static Resource buildResource(String endpoint) {
String value = parser.nextTextValue();
switch (parser.currentName()) {
case "instanceId":
attrBuilders.put(ResourceAttributes.HOST_ID, value);
attrBuilders.put(HOST_ID, value);
break;
case "availabilityZone":
attrBuilders.put(ResourceAttributes.CLOUD_AVAILABILITY_ZONE, value);
attrBuilders.put(CLOUD_AVAILABILITY_ZONE, value);
break;
case "instanceType":
attrBuilders.put(ResourceAttributes.HOST_TYPE, value);
attrBuilders.put(HOST_TYPE, value);
break;
case "imageId":
attrBuilders.put(ResourceAttributes.HOST_IMAGE_ID, value);
attrBuilders.put(HOST_IMAGE_ID, value);
break;
case "accountId":
attrBuilders.put(ResourceAttributes.CLOUD_ACCOUNT_ID, value);
attrBuilders.put(CLOUD_ACCOUNT_ID, value);
break;
case "region":
attrBuilders.put(ResourceAttributes.CLOUD_REGION, value);
attrBuilders.put(CLOUD_REGION, value);
break;
default:
parser.skipChildren();
Expand All @@ -119,9 +130,9 @@ static Resource buildResource(String endpoint) {
return Resource.empty();
}

attrBuilders.put(ResourceAttributes.HOST_NAME, hostname);
attrBuilders.put(HOST_NAME, hostname);

return Resource.create(attrBuilders.build(), ResourceAttributes.SCHEMA_URL);
return Resource.create(attrBuilders.build(), SchemaUrls.V1_25_0);
}

private static String fetchToken(URL tokenUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,34 @@

package io.opentelemetry.contrib.aws.resource;

import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_ECS_CONTAINER_ARN;
import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_ECS_LAUNCHTYPE;
import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_ECS_TASK_ARN;
import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_ECS_TASK_FAMILY;
import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_ECS_TASK_REVISION;
import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_LOG_GROUP_ARNS;
import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_LOG_GROUP_NAMES;
import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_LOG_STREAM_ARNS;
import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_LOG_STREAM_NAMES;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_ACCOUNT_ID;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_AVAILABILITY_ZONE;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_PLATFORM;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_PROVIDER;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_REGION;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_RESOURCE_ID;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CloudPlatformValues.AWS_ECS;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CloudProviderValues.AWS;
import static io.opentelemetry.semconv.incubating.ContainerIncubatingAttributes.CONTAINER_ID;
import static io.opentelemetry.semconv.incubating.ContainerIncubatingAttributes.CONTAINER_IMAGE_NAME;
import static io.opentelemetry.semconv.incubating.ContainerIncubatingAttributes.CONTAINER_NAME;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.ResourceAttributes;
import io.opentelemetry.semconv.SchemaUrls;
import java.io.IOException;
import java.util.Collections;
import java.util.Locale;
Expand Down Expand Up @@ -58,7 +79,7 @@ static Resource buildResource(Map<String, String> sysEnv, SimpleHttpClient httpC
// For TaskARN, Family, Revision.
// May put the same attribute twice but that shouldn't matter.
fetchMetadata(httpClient, ecsMetadataUrl + "/task", attrBuilders);
return Resource.create(attrBuilders.build(), ResourceAttributes.SCHEMA_URL);
return Resource.create(attrBuilders.build(), SchemaUrls.V1_25_0);
}
// Not running on ECS
return Resource.empty();
Expand All @@ -70,9 +91,8 @@ static void fetchMetadata(
if (json.isEmpty()) {
return;
}
attrBuilders.put(ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.AWS);
attrBuilders.put(
ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_ECS);
attrBuilders.put(CLOUD_PROVIDER, AWS);
attrBuilders.put(CLOUD_PLATFORM, AWS_ECS);
try (JsonParser parser = JSON_FACTORY.createParser(json)) {
parser.nextToken();
LogArnBuilder logArnBuilder = new LogArnBuilder();
Expand All @@ -82,17 +102,14 @@ static void fetchMetadata(
.getLogGroupArn()
.ifPresent(
logGroupArn -> {
attrBuilders.put(
ResourceAttributes.AWS_LOG_GROUP_ARNS, Collections.singletonList(logGroupArn));
attrBuilders.put(AWS_LOG_GROUP_ARNS, Collections.singletonList(logGroupArn));
});

logArnBuilder
.getLogStreamArn()
.ifPresent(
logStreamArn -> {
attrBuilders.put(
ResourceAttributes.AWS_LOG_STREAM_ARNS,
Collections.singletonList(logStreamArn));
attrBuilders.put(AWS_LOG_STREAM_ARNS, Collections.singletonList(logStreamArn));
});
} catch (IOException e) {
logger.log(Level.WARNING, "Can't get ECS metadata", e);
Expand Down Expand Up @@ -151,26 +168,28 @@ static void parseResponse(
String value = parser.nextTextValue();
switch (parser.currentName()) {
case "AvailabilityZone":
attrBuilders.put(ResourceAttributes.CLOUD_AVAILABILITY_ZONE, value);
attrBuilders.put(CLOUD_AVAILABILITY_ZONE, value);
break;
case "DockerId":
attrBuilders.put(ResourceAttributes.CONTAINER_ID, value);
attrBuilders.put(CONTAINER_ID, value);
break;
case "DockerName":
attrBuilders.put(ResourceAttributes.CONTAINER_NAME, value);
attrBuilders.put(CONTAINER_NAME, value);
break;
case "ContainerARN":
arn = value;
attrBuilders.put(ResourceAttributes.AWS_ECS_CONTAINER_ARN, value);
attrBuilders.put(ResourceAttributes.CLOUD_RESOURCE_ID, value);
attrBuilders.put(AWS_ECS_CONTAINER_ARN, value);
attrBuilders.put(CLOUD_RESOURCE_ID, value);
logArnBuilder.setContainerArn(value);
break;
case "Image":
DockerImage parsedImage = DockerImage.parse(value);
if (parsedImage != null) {
attrBuilders.put(ResourceAttributes.CONTAINER_IMAGE_NAME, parsedImage.getRepository());
attrBuilders.put(CONTAINER_IMAGE_NAME, parsedImage.getRepository());
// TODO: CONTAINER_IMAGE_TAG has been replaced with CONTAINER_IMAGE_TAGS
attrBuilders.put(ResourceAttributes.CONTAINER_IMAGE_TAG, parsedImage.getTag());
attrBuilders.put(
io.opentelemetry.semconv.ResourceAttributes.CONTAINER_IMAGE_TAG,
parsedImage.getTag());
}
break;
case "ImageID":
Expand All @@ -181,38 +200,37 @@ static void parseResponse(
parseResponse(parser, attrBuilders, logArnBuilder);
break;
case "awslogs-group":
attrBuilders.put(ResourceAttributes.AWS_LOG_GROUP_NAMES, value);
attrBuilders.put(AWS_LOG_GROUP_NAMES, value);
logArnBuilder.setLogGroupName(value);
break;
case "awslogs-stream":
attrBuilders.put(ResourceAttributes.AWS_LOG_STREAM_NAMES, value);
attrBuilders.put(AWS_LOG_STREAM_NAMES, value);
logArnBuilder.setLogStreamName(value);
break;
case "awslogs-region":
logArnBuilder.setRegion(value);
break;
case "TaskARN":
arn = value;
attrBuilders.put(ResourceAttributes.AWS_ECS_TASK_ARN, value);
attrBuilders.put(AWS_ECS_TASK_ARN, value);
break;
case "LaunchType":
attrBuilders.put(ResourceAttributes.AWS_ECS_LAUNCHTYPE, value.toLowerCase(Locale.ROOT));
attrBuilders.put(AWS_ECS_LAUNCHTYPE, value.toLowerCase(Locale.ROOT));
break;
case "Family":
attrBuilders.put(ResourceAttributes.AWS_ECS_TASK_FAMILY, value);
attrBuilders.put(AWS_ECS_TASK_FAMILY, value);
break;
case "Revision":
attrBuilders.put(ResourceAttributes.AWS_ECS_TASK_REVISION, value);
attrBuilders.put(AWS_ECS_TASK_REVISION, value);
break;
default:
parser.skipChildren();
break;
}
}

getRegion(arn).ifPresent(region -> attrBuilders.put(ResourceAttributes.CLOUD_REGION, region));
getAccountId(arn)
.ifPresent(accountId -> attrBuilders.put(ResourceAttributes.CLOUD_ACCOUNT_ID, accountId));
getRegion(arn).ifPresent(region -> attrBuilders.put(CLOUD_REGION, region));
getAccountId(arn).ifPresent(accountId -> attrBuilders.put(CLOUD_ACCOUNT_ID, accountId));
}

private EcsResource() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@

package io.opentelemetry.contrib.aws.resource;

import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_PLATFORM;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_PROVIDER;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CloudPlatformValues.AWS_EKS;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CloudProviderValues.AWS;
import static io.opentelemetry.semconv.incubating.ContainerIncubatingAttributes.CONTAINER_ID;
import static io.opentelemetry.semconv.incubating.K8sIncubatingAttributes.K8S_CLUSTER_NAME;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.ResourceAttributes;
import io.opentelemetry.semconv.SchemaUrls;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -65,21 +72,20 @@ static Resource buildResource(
}

AttributesBuilder attrBuilders = Attributes.builder();
attrBuilders.put(ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.AWS);
attrBuilders.put(
ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EKS);
attrBuilders.put(CLOUD_PROVIDER, AWS);
attrBuilders.put(CLOUD_PLATFORM, AWS_EKS);

String clusterName = getClusterName(httpClient);
if (clusterName != null && !clusterName.isEmpty()) {
attrBuilders.put(ResourceAttributes.K8S_CLUSTER_NAME, clusterName);
attrBuilders.put(K8S_CLUSTER_NAME, clusterName);
}

String containerId = dockerHelper.getContainerId();
if (containerId != null && !containerId.isEmpty()) {
attrBuilders.put(ResourceAttributes.CONTAINER_ID, containerId);
attrBuilders.put(CONTAINER_ID, containerId);
}

return Resource.create(attrBuilders.build(), ResourceAttributes.SCHEMA_URL);
return Resource.create(attrBuilders.build(), SchemaUrls.V1_25_0);
}

private static boolean isEks(
Expand Down

0 comments on commit baf0eaa

Please sign in to comment.