diff --git a/exporters/zipkin/src/main/java/io/opentelemetry/exporters/zipkin/ZipkinSpanExporter.java b/exporters/zipkin/src/main/java/io/opentelemetry/exporters/zipkin/ZipkinSpanExporter.java index 29e017d3040..cf116abc952 100644 --- a/exporters/zipkin/src/main/java/io/opentelemetry/exporters/zipkin/ZipkinSpanExporter.java +++ b/exporters/zipkin/src/main/java/io/opentelemetry/exporters/zipkin/ZipkinSpanExporter.java @@ -24,7 +24,7 @@ import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.common.export.CompletableResultCode; import io.opentelemetry.sdk.common.export.ConfigBuilder; -import io.opentelemetry.sdk.resources.ResourceConstants; +import io.opentelemetry.sdk.resources.ResourceAttributes; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.sdk.trace.data.SpanData.Event; import io.opentelemetry.sdk.trace.export.SpanExporter; @@ -187,7 +187,7 @@ private static Endpoint chooseEndpoint(SpanData spanData, Endpoint localEndpoint ReadableAttributes resourceAttributes = spanData.getResource().getAttributes(); // use the service.name from the Resource, if it's been set. - AttributeValue serviceNameValue = resourceAttributes.get(ResourceConstants.SERVICE_NAME); + AttributeValue serviceNameValue = resourceAttributes.get(ResourceAttributes.SERVICE_NAME.key()); if (serviceNameValue == null) { return localEndpoint; } @@ -311,7 +311,7 @@ public static final class Builder extends ConfigBuilder { * consistent. Many use a name from service discovery. * *

Note: this value, will be superseded by the value of {@link - * io.opentelemetry.sdk.resources.ResourceConstants#SERVICE_NAME} if it has been set in the + * io.opentelemetry.sdk.resources.ResourceAttributes#SERVICE_NAME} if it has been set in the * {@link io.opentelemetry.sdk.resources.Resource} associated with the Tracer that created the * spans. * @@ -320,7 +320,7 @@ public static final class Builder extends ConfigBuilder { * @param serviceName The service name. It defaults to "unknown". * @return this. * @see io.opentelemetry.sdk.resources.Resource - * @see io.opentelemetry.sdk.resources.ResourceConstants + * @see io.opentelemetry.sdk.resources.ResourceAttributes * @since 0.4.0 */ public Builder setServiceName(String serviceName) { diff --git a/exporters/zipkin/src/test/java/io/opentelemetry/exporters/zipkin/ZipkinSpanExporterTest.java b/exporters/zipkin/src/test/java/io/opentelemetry/exporters/zipkin/ZipkinSpanExporterTest.java index 259bf23ed40..014c5179129 100644 --- a/exporters/zipkin/src/test/java/io/opentelemetry/exporters/zipkin/ZipkinSpanExporterTest.java +++ b/exporters/zipkin/src/test/java/io/opentelemetry/exporters/zipkin/ZipkinSpanExporterTest.java @@ -28,7 +28,7 @@ import io.opentelemetry.sdk.common.export.CompletableResultCode; import io.opentelemetry.sdk.common.export.ConfigBuilder; import io.opentelemetry.sdk.resources.Resource; -import io.opentelemetry.sdk.resources.ResourceConstants; +import io.opentelemetry.sdk.resources.ResourceAttributes; import io.opentelemetry.sdk.trace.TestSpanData; import io.opentelemetry.sdk.trace.data.EventImpl; import io.opentelemetry.sdk.trace.data.SpanData; @@ -126,7 +126,8 @@ void generateSpan_ResourceServiceNameMapping() { final Resource resource = Resource.create( Attributes.of( - ResourceConstants.SERVICE_NAME, stringAttributeValue("super-zipkin-service"))); + ResourceAttributes.SERVICE_NAME.key(), + stringAttributeValue("super-zipkin-service"))); SpanData data = buildStandardSpan().setResource(resource).build(); Endpoint expectedEndpoint = Endpoint.newBuilder().serviceName("super-zipkin-service").build(); diff --git a/sdk/common/src/main/java/io/opentelemetry/sdk/resources/ResourceAttributes.java b/sdk/common/src/main/java/io/opentelemetry/sdk/resources/ResourceAttributes.java new file mode 100644 index 00000000000..1a882d0ef00 --- /dev/null +++ b/sdk/common/src/main/java/io/opentelemetry/sdk/resources/ResourceAttributes.java @@ -0,0 +1,154 @@ +/* + * Copyright 2020, OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.opentelemetry.sdk.resources; + +import io.opentelemetry.trace.attributes.LongAttributeSetter; +import io.opentelemetry.trace.attributes.StringAttributeSetter; + +/** + * Provides constants for resource semantic conventions defined by the OpenTelemetry specification. + * + * @see Resource + * Conventions + */ +public final class ResourceAttributes { + + /** The operating system type, such as {@code "WINDOWS"}, {@code "DARWIN"}, {@code "LINUX"}. */ + public static final StringAttributeSetter OS_NAME = StringAttributeSetter.create("os.name"); + + /** + * Human readable information about the OS version, e.g. {@code "Microsoft Windows [Version + * 10.0.18363.778]"}, {@code "Ubuntu 18.04.1 LTS"}. + */ + public static final StringAttributeSetter OS_DESCRIPTION = + StringAttributeSetter.create("os.description"); + + /** Process identifier (PID). */ + public static final LongAttributeSetter PROCESS_PID = LongAttributeSetter.create("process.pid"); + + /** The name of the process executable. */ + public static final StringAttributeSetter PROCESS_EXECUTABLE_NAME = + StringAttributeSetter.create("process.executable.name"); + + /** The full path to the process executable. */ + public static final StringAttributeSetter PROCESS_EXECUTABLE_PATH = + StringAttributeSetter.create("process.executable.path"); + + /** The command used to launch the process (i.e. the command name). */ + public static final StringAttributeSetter PROCESS_COMMAND = + StringAttributeSetter.create("process.command"); + + /** + * The full command used to launch the process. The value can be either a list of strings + * representing the ordered list of arguments, or a single string representing the full command. + */ + public static final StringAttributeSetter PROCESS_COMMAND_LINE = + StringAttributeSetter.create("process.command_line"); + + /** The username of the user that owns the process. */ + public static final StringAttributeSetter PROCESS_OWNER = + StringAttributeSetter.create("process.owner"); + + /** + * Logical name of the service. MUST be the same for all instances of horizontally scaled + * services. + */ + public static final StringAttributeSetter SERVICE_NAME = + StringAttributeSetter.create("service.name"); + /** + * A namespace for `service.name`. A string value having a meaning that helps to distinguish a + * group of services, + */ + public static final StringAttributeSetter SERVICE_NAMESPACE = + StringAttributeSetter.create("service.namespace"); + /** + * The string ID of the service instance. MUST be unique for each instance of the same + * `service.namespace,service.name` pair. + */ + public static final StringAttributeSetter SERVICE_INSTANCE = + StringAttributeSetter.create("service.instance.id"); + /** The version string of the service API or implementation. */ + public static final StringAttributeSetter SERVICE_VERSION = + StringAttributeSetter.create("service.version"); + /** The name of the telemetry library. */ + public static final StringAttributeSetter LIBRARY_NAME = + StringAttributeSetter.create("library.name"); + /** The language of telemetry library and of the code instrumented with it. */ + public static final StringAttributeSetter LIBRARY_LANGUAGE = + StringAttributeSetter.create("library.language"); + /** The version string of the library. */ + public static final StringAttributeSetter LIBRARY_VERSION = + StringAttributeSetter.create("library.version"); + /** Container name. */ + public static final StringAttributeSetter CONTAINER_NAME = + StringAttributeSetter.create("container.name"); + /** Container id. */ + public static final StringAttributeSetter CONTAINER_ID = + StringAttributeSetter.create("container.id"); + /** Name of the image the container was built on. */ + public static final StringAttributeSetter CONTAINER_IMAGE_NAME = + StringAttributeSetter.create("container.image.name"); + /** Container image tag. */ + public static final StringAttributeSetter CONTAINER_IMAGE_TAG = + StringAttributeSetter.create("container.image.tag"); + /** The name of the cluster that the pod is running in. */ + public static final StringAttributeSetter K8S_CLUSTER = + StringAttributeSetter.create("k8s.cluster.name"); + /** The name of the namespace that the pod is running in. */ + public static final StringAttributeSetter K8S_NAMESPACE = + StringAttributeSetter.create("k8s.namespace.name"); + /** The name of the pod. */ + public static final StringAttributeSetter K8S_POD = StringAttributeSetter.create("k8s.pod.name"); + /** The name of the deployment. */ + public static final StringAttributeSetter K8S_DEPLOYMENT = + StringAttributeSetter.create("k8s.deployment.name"); + /** Hostname of the host. It contains what the `hostname` command returns on the host machine. */ + public static final StringAttributeSetter HOST_HOSTNAME = + StringAttributeSetter.create("host.hostname"); + /** Unique host id. For Cloud this must be the instance_id assigned by the cloud provider. */ + public static final StringAttributeSetter HOST_ID = StringAttributeSetter.create("host.id"); + /** + * Name of the host. It may contain what `hostname` returns on Unix systems, the fully qualified, + * or a name specified by the user. + */ + public static final StringAttributeSetter HOST_NAME = StringAttributeSetter.create("host.name"); + /** Type of host. For Cloud this must be the machine type. */ + public static final StringAttributeSetter HOST_TYPE = StringAttributeSetter.create("host.type"); + /** Name of the VM image or OS install the host was instantiated from. */ + public static final StringAttributeSetter HOST_IMAGE_NAME = + StringAttributeSetter.create("host.image.name"); + /** VM image id. For Cloud, this value is from the provider. */ + public static final StringAttributeSetter HOST_IMAGE_ID = + StringAttributeSetter.create("host.image.id"); + /** The version string of the VM image. */ + public static final StringAttributeSetter HOST_IMAGE_VERSION = + StringAttributeSetter.create("host.image.version"); + /** Name of the cloud provider. */ + public static final StringAttributeSetter CLOUD_PROVIDER = + StringAttributeSetter.create("cloud.provider"); + /** The cloud account id used to identify different entities. */ + public static final StringAttributeSetter CLOUD_ACCOUNT = + StringAttributeSetter.create("cloud.account.id"); + /** A specific geographical location where different entities can run. */ + public static final StringAttributeSetter CLOUD_REGION = + StringAttributeSetter.create("cloud.region"); + /** Zones are a sub set of the region connected through low-latency links. */ + public static final StringAttributeSetter CLOUD_ZONE = StringAttributeSetter.create("cloud.zone"); + + private ResourceAttributes() {} +} diff --git a/sdk/common/src/main/java/io/opentelemetry/sdk/resources/ResourceConstants.java b/sdk/common/src/main/java/io/opentelemetry/sdk/resources/ResourceConstants.java deleted file mode 100644 index 59ad0fa316b..00000000000 --- a/sdk/common/src/main/java/io/opentelemetry/sdk/resources/ResourceConstants.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2020, OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.opentelemetry.sdk.resources; - -/** - * Provides constants for resource semantic conventions defined by the OpenTelemetry specification. - * - * @see Resource - * Conventions - */ -public class ResourceConstants { - - /** The operating system type, such as {@code "WINDOWS"}, {@code "DARWIN"}, {@code "LINUX"}. */ - public static final String OS_NAME = "os.name"; - - /** - * Human readable information about the OS version, e.g. {@code "Microsoft Windows [Version - * 10.0.18363.778]"}, {@code "Ubuntu 18.04.1 LTS"}. - */ - public static final String OS_DESCRIPTION = "os.description"; - - /** Process identifier (PID). */ - public static final String PROCESS_PID = "process.pid"; - - /** The name of the process executable. */ - public static final String PROCESS_EXECUTABLE_NAME = "process.executable.name"; - - /** The full path to the process executable. */ - public static final String PROCESS_EXECUTABLE_PATH = "process.executable.path"; - - /** The command used to launch the process (i.e. the command name). */ - public static final String PROCESS_COMMAND = "process.command"; - - /** - * The full command used to launch the process. The value can be either a list of strings - * representing the ordered list of arguments, or a single string representing the full command. - */ - public static final String PROCESS_COMMAND_LINE = "process.command_line"; - - /** The username of the user that owns the process. */ - public static final String PROCESS_OWNER = "process.owner"; - - /** - * Logical name of the service. MUST be the same for all instances of horizontally scaled - * services. - */ - public static final String SERVICE_NAME = "service.name"; - /** - * A namespace for `service.name`. A string value having a meaning that helps to distinguish a - * group of services, - */ - public static final String SERVICE_NAMESPACE = "service.namespace"; - /** - * The string ID of the service instance. MUST be unique for each instance of the same - * `service.namespace,service.name` pair. - */ - public static final String SERVICE_INSTANCE = "service.instance.id"; - /** The version string of the service API or implementation. */ - public static final String SERVICE_VERSION = "service.version"; - /** The name of the telemetry library. */ - public static final String LIBRARY_NAME = "library.name"; - /** The language of telemetry library and of the code instrumented with it. */ - public static final String LIBRARY_LANGUAGE = "library.language"; - /** The version string of the library. */ - public static final String LIBRARY_VERSION = "library.version"; - /** Container name. */ - public static final String CONTAINER_NAME = "container.name"; - /** Container id. */ - public static final String CONTAINER_ID = "container.id"; - /** Name of the image the container was built on. */ - public static final String CONTAINER_IMAGE_NAME = "container.image.name"; - /** Container image tag. */ - public static final String CONTAINER_IMAGE_TAG = "container.image.tag"; - /** The name of the cluster that the pod is running in. */ - public static final String K8S_CLUSTER = "k8s.cluster.name"; - /** The name of the namespace that the pod is running in. */ - public static final String K8S_NAMESPACE = "k8s.namespace.name"; - /** The name of the pod. */ - public static final String K8S_POD = "k8s.pod.name"; - /** The name of the deployment. */ - public static final String K8S_DEPLOYMENT = "k8s.deployment.name"; - /** Hostname of the host. It contains what the `hostname` command returns on the host machine. */ - public static final String HOST_HOSTNAME = "host.hostname"; - /** Unique host id. For Cloud this must be the instance_id assigned by the cloud provider. */ - public static final String HOST_ID = "host.id"; - /** - * Name of the host. It may contain what `hostname` returns on Unix systems, the fully qualified, - * or a name specified by the user. - */ - public static final String HOST_NAME = "host.name"; - /** Type of host. For Cloud this must be the machine type. */ - public static final String HOST_TYPE = "host.type"; - /** Name of the VM image or OS install the host was instantiated from. */ - public static final String HOST_IMAGE_NAME = "host.image.name"; - /** VM image id. For Cloud, this value is from the provider. */ - public static final String HOST_IMAGE_ID = "host.image.id"; - /** The version string of the VM image. */ - public static final String HOST_IMAGE_VERSION = "host.image.version"; - /** Name of the cloud provider. */ - public static final String CLOUD_PROVIDER = "cloud.provider"; - /** The cloud account id used to identify different entities. */ - public static final String CLOUD_ACCOUNT = "cloud.account.id"; - /** A specific geographical location where different entities can run. */ - public static final String CLOUD_REGION = "cloud.region"; - /** Zones are a sub set of the region connected through low-latency links. */ - public static final String CLOUD_ZONE = "cloud.zone"; - - private ResourceConstants() {} -} diff --git a/sdk_extensions/aws_v1_support/src/main/java/io/opentelemetry/sdk/extensions/trace/aws/resource/BeanstalkResource.java b/sdk_extensions/aws_v1_support/src/main/java/io/opentelemetry/sdk/extensions/trace/aws/resource/BeanstalkResource.java index ec728754f6b..ffc87b519c0 100644 --- a/sdk_extensions/aws_v1_support/src/main/java/io/opentelemetry/sdk/extensions/trace/aws/resource/BeanstalkResource.java +++ b/sdk_extensions/aws_v1_support/src/main/java/io/opentelemetry/sdk/extensions/trace/aws/resource/BeanstalkResource.java @@ -21,7 +21,7 @@ import com.fasterxml.jackson.core.JsonToken; import com.google.common.annotations.VisibleForTesting; import io.opentelemetry.common.Attributes; -import io.opentelemetry.sdk.resources.ResourceConstants; +import io.opentelemetry.sdk.resources.ResourceAttributes; import io.opentelemetry.sdk.resources.ResourceProvider; import java.io.File; import java.io.IOException; @@ -78,13 +78,13 @@ public Attributes getAttributes() { String value = parser.getText(); switch (parser.getCurrentName()) { case DEVELOPMENT_ID: - attrBuilders.setAttribute(ResourceConstants.SERVICE_INSTANCE, value); + ResourceAttributes.SERVICE_INSTANCE.set(attrBuilders, value); break; case VERSION_LABEL: - attrBuilders.setAttribute(ResourceConstants.SERVICE_VERSION, value); + ResourceAttributes.SERVICE_VERSION.set(attrBuilders, value); break; case ENVIRONMENT_NAME: - attrBuilders.setAttribute(ResourceConstants.SERVICE_NAMESPACE, value); + ResourceAttributes.SERVICE_NAMESPACE.set(attrBuilders, value); break; default: parser.skipChildren(); diff --git a/sdk_extensions/aws_v1_support/src/main/java/io/opentelemetry/sdk/extensions/trace/aws/resource/Ec2Resource.java b/sdk_extensions/aws_v1_support/src/main/java/io/opentelemetry/sdk/extensions/trace/aws/resource/Ec2Resource.java index 8bf5ef88dd3..88c73677b5f 100644 --- a/sdk_extensions/aws_v1_support/src/main/java/io/opentelemetry/sdk/extensions/trace/aws/resource/Ec2Resource.java +++ b/sdk_extensions/aws_v1_support/src/main/java/io/opentelemetry/sdk/extensions/trace/aws/resource/Ec2Resource.java @@ -22,7 +22,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.io.ByteStreams; import io.opentelemetry.common.Attributes; -import io.opentelemetry.sdk.resources.ResourceConstants; +import io.opentelemetry.sdk.resources.ResourceAttributes; import io.opentelemetry.sdk.resources.ResourceProvider; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -172,22 +172,22 @@ public Attributes getAttributes() { String value = parser.nextTextValue(); switch (parser.getCurrentName()) { case "instanceId": - attrBuilders.setAttribute(ResourceConstants.HOST_ID, value); + ResourceAttributes.HOST_ID.set(attrBuilders, value); break; case "availabilityZone": - attrBuilders.setAttribute(ResourceConstants.CLOUD_ZONE, value); + ResourceAttributes.CLOUD_ZONE.set(attrBuilders, value); break; case "instanceType": - attrBuilders.setAttribute(ResourceConstants.HOST_TYPE, value); + ResourceAttributes.HOST_TYPE.set(attrBuilders, value); break; case "imageId": - attrBuilders.setAttribute(ResourceConstants.HOST_IMAGE_ID, value); + ResourceAttributes.HOST_IMAGE_ID.set(attrBuilders, value); break; case "accountId": - attrBuilders.setAttribute(ResourceConstants.CLOUD_ACCOUNT, value); + ResourceAttributes.CLOUD_ACCOUNT.set(attrBuilders, value); break; case "region": - attrBuilders.setAttribute(ResourceConstants.CLOUD_REGION, value); + ResourceAttributes.CLOUD_REGION.set(attrBuilders, value); break; default: parser.skipChildren(); @@ -198,8 +198,8 @@ public Attributes getAttributes() { return Attributes.empty(); } - attrBuilders.setAttribute(ResourceConstants.HOST_HOSTNAME, hostname); - attrBuilders.setAttribute(ResourceConstants.HOST_NAME, hostname); + ResourceAttributes.HOST_HOSTNAME.set(attrBuilders, hostname); + ResourceAttributes.HOST_NAME.set(attrBuilders, hostname); return attrBuilders.build(); } diff --git a/sdk_extensions/aws_v1_support/src/main/java/io/opentelemetry/sdk/extensions/trace/aws/resource/EcsResource.java b/sdk_extensions/aws_v1_support/src/main/java/io/opentelemetry/sdk/extensions/trace/aws/resource/EcsResource.java index 4c49afdb74c..d1788adb080 100644 --- a/sdk_extensions/aws_v1_support/src/main/java/io/opentelemetry/sdk/extensions/trace/aws/resource/EcsResource.java +++ b/sdk_extensions/aws_v1_support/src/main/java/io/opentelemetry/sdk/extensions/trace/aws/resource/EcsResource.java @@ -19,7 +19,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Strings; import io.opentelemetry.common.Attributes; -import io.opentelemetry.sdk.resources.ResourceConstants; +import io.opentelemetry.sdk.resources.ResourceAttributes; import io.opentelemetry.sdk.resources.ResourceProvider; import java.net.InetAddress; import java.net.UnknownHostException; @@ -64,14 +64,14 @@ public Attributes getAttributes() { Attributes.Builder attrBuilders = Attributes.newBuilder(); try { String hostName = InetAddress.getLocalHost().getHostName(); - attrBuilders.setAttribute(ResourceConstants.CONTAINER_NAME, hostName); + ResourceAttributes.CONTAINER_NAME.set(attrBuilders, hostName); } catch (UnknownHostException e) { logger.log(Level.WARNING, "Could not get docker container name from hostname.", e); } String containerId = dockerHelper.getContainerId(); if (!Strings.isNullOrEmpty(containerId)) { - attrBuilders.setAttribute(ResourceConstants.CONTAINER_ID, containerId); + ResourceAttributes.CONTAINER_ID.set(attrBuilders, containerId); } return attrBuilders.build(); diff --git a/sdk_extensions/aws_v1_support/src/test/java/io/opentelemetry/sdk/extensions/trace/aws/resource/BeanstalkResourceTest.java b/sdk_extensions/aws_v1_support/src/test/java/io/opentelemetry/sdk/extensions/trace/aws/resource/BeanstalkResourceTest.java index 6699fe2d367..9edb4f60dfe 100644 --- a/sdk_extensions/aws_v1_support/src/test/java/io/opentelemetry/sdk/extensions/trace/aws/resource/BeanstalkResourceTest.java +++ b/sdk_extensions/aws_v1_support/src/test/java/io/opentelemetry/sdk/extensions/trace/aws/resource/BeanstalkResourceTest.java @@ -22,7 +22,7 @@ import com.google.common.base.Charsets; import com.google.common.io.Files; import io.opentelemetry.common.Attributes; -import io.opentelemetry.sdk.resources.ResourceConstants; +import io.opentelemetry.sdk.resources.ResourceAttributes; import io.opentelemetry.sdk.resources.ResourceProvider; import java.io.File; import java.io.IOException; @@ -44,9 +44,10 @@ void testCreateAttributes(@TempDir File tempFolder) throws IOException { assertThat(attributes) .isEqualTo( Attributes.of( - ResourceConstants.SERVICE_INSTANCE, stringAttributeValue("4"), - ResourceConstants.SERVICE_VERSION, stringAttributeValue("2"), - ResourceConstants.SERVICE_NAMESPACE, stringAttributeValue("HttpSubscriber-env"))); + ResourceAttributes.SERVICE_INSTANCE.key(), stringAttributeValue("4"), + ResourceAttributes.SERVICE_VERSION.key(), stringAttributeValue("2"), + ResourceAttributes.SERVICE_NAMESPACE.key(), + stringAttributeValue("HttpSubscriber-env"))); } @Test diff --git a/sdk_extensions/aws_v1_support/src/test/java/io/opentelemetry/sdk/extensions/trace/aws/resource/Ec2ResourceTest.java b/sdk_extensions/aws_v1_support/src/test/java/io/opentelemetry/sdk/extensions/trace/aws/resource/Ec2ResourceTest.java index 44658174c7c..10727c049fa 100644 --- a/sdk_extensions/aws_v1_support/src/test/java/io/opentelemetry/sdk/extensions/trace/aws/resource/Ec2ResourceTest.java +++ b/sdk_extensions/aws_v1_support/src/test/java/io/opentelemetry/sdk/extensions/trace/aws/resource/Ec2ResourceTest.java @@ -32,7 +32,7 @@ import com.github.tomakehurst.wiremock.junit.WireMockClassRule; import io.opentelemetry.common.Attributes; -import io.opentelemetry.sdk.resources.ResourceConstants; +import io.opentelemetry.sdk.resources.ResourceAttributes; import io.opentelemetry.sdk.resources.ResourceProvider; import java.util.ServiceLoader; import org.junit.Before; @@ -81,14 +81,15 @@ public void imdsv2() { Attributes attributes = populator.getAttributes(); Attributes.Builder expectedAttrBuilders = Attributes.newBuilder(); - expectedAttrBuilders.setAttribute(ResourceConstants.HOST_ID, "i-1234567890abcdef0"); - expectedAttrBuilders.setAttribute(ResourceConstants.CLOUD_ZONE, "us-west-2b"); - expectedAttrBuilders.setAttribute(ResourceConstants.HOST_TYPE, "t2.micro"); - expectedAttrBuilders.setAttribute(ResourceConstants.HOST_IMAGE_ID, "ami-5fb8c835"); - expectedAttrBuilders.setAttribute(ResourceConstants.CLOUD_ACCOUNT, "123456789012"); - expectedAttrBuilders.setAttribute(ResourceConstants.CLOUD_REGION, "us-west-2"); - expectedAttrBuilders.setAttribute(ResourceConstants.HOST_HOSTNAME, "ec2-1-2-3-4"); - expectedAttrBuilders.setAttribute(ResourceConstants.HOST_NAME, "ec2-1-2-3-4"); + + ResourceAttributes.HOST_ID.set(expectedAttrBuilders, "i-1234567890abcdef0"); + ResourceAttributes.CLOUD_ZONE.set(expectedAttrBuilders, "us-west-2b"); + ResourceAttributes.HOST_TYPE.set(expectedAttrBuilders, "t2.micro"); + ResourceAttributes.HOST_IMAGE_ID.set(expectedAttrBuilders, "ami-5fb8c835"); + ResourceAttributes.CLOUD_ACCOUNT.set(expectedAttrBuilders, "123456789012"); + ResourceAttributes.CLOUD_REGION.set(expectedAttrBuilders, "us-west-2"); + ResourceAttributes.HOST_HOSTNAME.set(expectedAttrBuilders, "ec2-1-2-3-4"); + ResourceAttributes.HOST_NAME.set(expectedAttrBuilders, "ec2-1-2-3-4"); assertThat(attributes).isEqualTo(expectedAttrBuilders.build()); verify( @@ -112,14 +113,15 @@ public void imdsv1() { Attributes attributes = populator.getAttributes(); Attributes.Builder expectedAttrBuilders = Attributes.newBuilder(); - expectedAttrBuilders.setAttribute(ResourceConstants.HOST_ID, "i-1234567890abcdef0"); - expectedAttrBuilders.setAttribute(ResourceConstants.CLOUD_ZONE, "us-west-2b"); - expectedAttrBuilders.setAttribute(ResourceConstants.HOST_TYPE, "t2.micro"); - expectedAttrBuilders.setAttribute(ResourceConstants.HOST_IMAGE_ID, "ami-5fb8c835"); - expectedAttrBuilders.setAttribute(ResourceConstants.CLOUD_ACCOUNT, "123456789012"); - expectedAttrBuilders.setAttribute(ResourceConstants.CLOUD_REGION, "us-west-2"); - expectedAttrBuilders.setAttribute(ResourceConstants.HOST_HOSTNAME, "ec2-1-2-3-4"); - expectedAttrBuilders.setAttribute(ResourceConstants.HOST_NAME, "ec2-1-2-3-4"); + + ResourceAttributes.HOST_ID.set(expectedAttrBuilders, "i-1234567890abcdef0"); + ResourceAttributes.CLOUD_ZONE.set(expectedAttrBuilders, "us-west-2b"); + ResourceAttributes.HOST_TYPE.set(expectedAttrBuilders, "t2.micro"); + ResourceAttributes.HOST_IMAGE_ID.set(expectedAttrBuilders, "ami-5fb8c835"); + ResourceAttributes.CLOUD_ACCOUNT.set(expectedAttrBuilders, "123456789012"); + ResourceAttributes.CLOUD_REGION.set(expectedAttrBuilders, "us-west-2"); + ResourceAttributes.HOST_HOSTNAME.set(expectedAttrBuilders, "ec2-1-2-3-4"); + ResourceAttributes.HOST_NAME.set(expectedAttrBuilders, "ec2-1-2-3-4"); assertThat(attributes).isEqualTo(expectedAttrBuilders.build()); verify( diff --git a/sdk_extensions/aws_v1_support/src/test/java/io/opentelemetry/sdk/extensions/trace/aws/resource/EcsResourceTest.java b/sdk_extensions/aws_v1_support/src/test/java/io/opentelemetry/sdk/extensions/trace/aws/resource/EcsResourceTest.java index b933c1c3197..6ba3b44037c 100644 --- a/sdk_extensions/aws_v1_support/src/test/java/io/opentelemetry/sdk/extensions/trace/aws/resource/EcsResourceTest.java +++ b/sdk_extensions/aws_v1_support/src/test/java/io/opentelemetry/sdk/extensions/trace/aws/resource/EcsResourceTest.java @@ -21,7 +21,7 @@ import static org.mockito.Mockito.when; import io.opentelemetry.common.Attributes; -import io.opentelemetry.sdk.resources.ResourceConstants; +import io.opentelemetry.sdk.resources.ResourceAttributes; import io.opentelemetry.sdk.resources.ResourceProvider; import java.net.InetAddress; import java.net.UnknownHostException; @@ -50,9 +50,9 @@ void testCreateAttributes() throws UnknownHostException { assertThat(attributes) .isEqualTo( Attributes.of( - ResourceConstants.CONTAINER_NAME, + ResourceAttributes.CONTAINER_NAME.key(), stringAttributeValue(InetAddress.getLocalHost().getHostName()), - ResourceConstants.CONTAINER_ID, + ResourceAttributes.CONTAINER_ID.key(), stringAttributeValue("0123456789A"))); } @@ -76,7 +76,7 @@ void testContainerIdMissing() throws UnknownHostException { assertThat(attributes) .isEqualTo( Attributes.of( - ResourceConstants.CONTAINER_NAME, + ResourceAttributes.CONTAINER_NAME.key(), stringAttributeValue(InetAddress.getLocalHost().getHostName()))); } diff --git a/sdk_extensions/resources/src/main/java/io/opentelemetry/sdk/extensions/resources/OsResource.java b/sdk_extensions/resources/src/main/java/io/opentelemetry/sdk/extensions/resources/OsResource.java index 26ddfc25390..2ad74d7e808 100644 --- a/sdk_extensions/resources/src/main/java/io/opentelemetry/sdk/extensions/resources/OsResource.java +++ b/sdk_extensions/resources/src/main/java/io/opentelemetry/sdk/extensions/resources/OsResource.java @@ -17,7 +17,7 @@ package io.opentelemetry.sdk.extensions.resources; import io.opentelemetry.common.Attributes; -import io.opentelemetry.sdk.resources.ResourceConstants; +import io.opentelemetry.sdk.resources.ResourceAttributes; import io.opentelemetry.sdk.resources.ResourceProvider; import javax.annotation.Nullable; @@ -42,7 +42,7 @@ protected Attributes getAttributes() { String osName = getOs(os); if (osName != null) { - attributes.setAttribute(ResourceConstants.OS_NAME, osName); + attributes.setAttribute(ResourceAttributes.OS_NAME.key(), osName); } String version = null; @@ -52,7 +52,7 @@ protected Attributes getAttributes() { // Ignore } String osDescription = version != null ? os + ' ' + version : os; - attributes.setAttribute(ResourceConstants.OS_DESCRIPTION, osDescription); + attributes.setAttribute(ResourceAttributes.OS_DESCRIPTION.key(), osDescription); return attributes.build(); } diff --git a/sdk_extensions/resources/src/main/java/io/opentelemetry/sdk/extensions/resources/ProcessResource.java b/sdk_extensions/resources/src/main/java/io/opentelemetry/sdk/extensions/resources/ProcessResource.java index 113a3f91b23..d0ab1e4e44d 100644 --- a/sdk_extensions/resources/src/main/java/io/opentelemetry/sdk/extensions/resources/ProcessResource.java +++ b/sdk_extensions/resources/src/main/java/io/opentelemetry/sdk/extensions/resources/ProcessResource.java @@ -17,7 +17,7 @@ package io.opentelemetry.sdk.extensions.resources; import io.opentelemetry.common.Attributes; -import io.opentelemetry.sdk.resources.ResourceConstants; +import io.opentelemetry.sdk.resources.ResourceAttributes; import io.opentelemetry.sdk.resources.ResourceProvider; import java.io.File; import java.lang.management.ManagementFactory; @@ -46,7 +46,7 @@ protected Attributes getAttributes() { } if (pid >= 0) { - attributes.setAttribute(ResourceConstants.PROCESS_PID, pid); + ResourceAttributes.PROCESS_PID.set(attributes, pid); } String javaHome = null; @@ -68,13 +68,13 @@ protected Attributes getAttributes() { executablePath.append(".exe"); } - attributes.setAttribute(ResourceConstants.PROCESS_EXECUTABLE_PATH, executablePath.toString()); + ResourceAttributes.PROCESS_EXECUTABLE_PATH.set(attributes, executablePath.toString()); StringBuilder commandLine = new StringBuilder(executablePath); for (String arg : runtime.getInputArguments()) { commandLine.append(' ').append(arg); } - attributes.setAttribute(ResourceConstants.PROCESS_COMMAND_LINE, commandLine.toString()); + ResourceAttributes.PROCESS_COMMAND_LINE.set(attributes, commandLine.toString()); } return attributes.build(); diff --git a/sdk_extensions/resources/src/test/java/io/opentelemetry/sdk/extensions/resources/OsResourceTest.java b/sdk_extensions/resources/src/test/java/io/opentelemetry/sdk/extensions/resources/OsResourceTest.java index d19d1d735ec..cd8cf07e9b4 100644 --- a/sdk_extensions/resources/src/test/java/io/opentelemetry/sdk/extensions/resources/OsResourceTest.java +++ b/sdk_extensions/resources/src/test/java/io/opentelemetry/sdk/extensions/resources/OsResourceTest.java @@ -22,7 +22,7 @@ import io.opentelemetry.common.Attributes; import io.opentelemetry.common.ReadableAttributes; import io.opentelemetry.sdk.resources.Resource; -import io.opentelemetry.sdk.resources.ResourceConstants; +import io.opentelemetry.sdk.resources.ResourceAttributes; import org.junit.jupiter.api.Test; class OsResourceTest { @@ -33,30 +33,36 @@ class OsResourceTest { void linux() { assumeThat(System.getProperty("os.name").toLowerCase()).startsWith("linux"); Attributes attributes = RESOURCE.getAttributes(); - assertThat(attributes.get(ResourceConstants.OS_NAME).getStringValue()).isEqualTo("LINUX"); - assertThat(attributes.get(ResourceConstants.OS_DESCRIPTION).getStringValue()).isNotEmpty(); + assertThat(attributes.get(ResourceAttributes.OS_NAME.key()).getStringValue()) + .isEqualTo("LINUX"); + assertThat(attributes.get(ResourceAttributes.OS_DESCRIPTION.key()).getStringValue()) + .isNotEmpty(); } @Test void macos() { assumeThat(System.getProperty("os.name").toLowerCase()).startsWith("mac"); Attributes attributes = RESOURCE.getAttributes(); - assertThat(attributes.get(ResourceConstants.OS_NAME).getStringValue()).isEqualTo("DARWIN"); - assertThat(attributes.get(ResourceConstants.OS_DESCRIPTION).getStringValue()).isNotEmpty(); + assertThat(attributes.get(ResourceAttributes.OS_NAME.key()).getStringValue()) + .isEqualTo("DARWIN"); + assertThat(attributes.get(ResourceAttributes.OS_DESCRIPTION.key()).getStringValue()) + .isNotEmpty(); } @Test void windows() { assumeThat(System.getProperty("os.name").toLowerCase()).startsWith("windows"); Attributes attributes = RESOURCE.getAttributes(); - assertThat(attributes.get(ResourceConstants.OS_NAME).getStringValue()).isEqualTo("WINDOWS"); - assertThat(attributes.get(ResourceConstants.OS_DESCRIPTION).getStringValue()).isNotEmpty(); + assertThat(attributes.get(ResourceAttributes.OS_NAME.key()).getStringValue()) + .isEqualTo("WINDOWS"); + assertThat(attributes.get(ResourceAttributes.OS_DESCRIPTION.key()).getStringValue()) + .isNotEmpty(); } @Test void inDefault() { ReadableAttributes attributes = Resource.getDefault().getAttributes(); - assertThat(attributes.get(ResourceConstants.OS_NAME)).isNotNull(); - assertThat(attributes.get(ResourceConstants.OS_DESCRIPTION)).isNotNull(); + assertThat(attributes.get(ResourceAttributes.OS_NAME.key())).isNotNull(); + assertThat(attributes.get(ResourceAttributes.OS_DESCRIPTION.key())).isNotNull(); } } diff --git a/sdk_extensions/resources/src/test/java/io/opentelemetry/sdk/extensions/resources/ProcessResourceTest.java b/sdk_extensions/resources/src/test/java/io/opentelemetry/sdk/extensions/resources/ProcessResourceTest.java index 20ea5c30992..43946e139f9 100644 --- a/sdk_extensions/resources/src/test/java/io/opentelemetry/sdk/extensions/resources/ProcessResourceTest.java +++ b/sdk_extensions/resources/src/test/java/io/opentelemetry/sdk/extensions/resources/ProcessResourceTest.java @@ -21,7 +21,7 @@ import io.opentelemetry.common.Attributes; import io.opentelemetry.common.ReadableAttributes; import io.opentelemetry.sdk.resources.Resource; -import io.opentelemetry.sdk.resources.ResourceConstants; +import io.opentelemetry.sdk.resources.ResourceAttributes; import org.junit.jupiter.api.Test; class ProcessResourceTest { @@ -32,18 +32,20 @@ class ProcessResourceTest { void normal() { Attributes attributes = RESOURCE.getAttributes(); - assertThat(attributes.get(ResourceConstants.PROCESS_PID).getLongValue()).isGreaterThan(1); - assertThat(attributes.get(ResourceConstants.PROCESS_EXECUTABLE_PATH).getStringValue()) + assertThat(attributes.get(ResourceAttributes.PROCESS_PID.key()).getLongValue()) + .isGreaterThan(1); + assertThat(attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH.key()).getStringValue()) .contains("java"); - assertThat(attributes.get(ResourceConstants.PROCESS_COMMAND_LINE).getStringValue()) - .contains(attributes.get(ResourceConstants.PROCESS_EXECUTABLE_PATH).getStringValue()); + assertThat(attributes.get(ResourceAttributes.PROCESS_COMMAND_LINE.key()).getStringValue()) + .contains( + attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH.key()).getStringValue()); } @Test void inDefault() { ReadableAttributes attributes = Resource.getDefault().getAttributes(); - assertThat(attributes.get(ResourceConstants.PROCESS_PID)).isNotNull(); - assertThat(attributes.get(ResourceConstants.PROCESS_EXECUTABLE_PATH)).isNotNull(); - assertThat(attributes.get(ResourceConstants.PROCESS_COMMAND_LINE)).isNotNull(); + assertThat(attributes.get(ResourceAttributes.PROCESS_PID.key())).isNotNull(); + assertThat(attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH.key())).isNotNull(); + assertThat(attributes.get(ResourceAttributes.PROCESS_COMMAND_LINE.key())).isNotNull(); } }