Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 19 additions & 0 deletions instrumentation/resources/library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,22 @@ tasks {
)
}
}

testing {
suites {
// Security Manager tests involve setup that can poison the environment for other tests
val testSecurityManager by registering(JvmTestSuite::class) {
dependencies {
implementation(project(":instrumentation:resources:library"))
implementation("io.opentelemetry:opentelemetry-sdk-common")
implementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating")
}
}
}
}

tasks {
check {
dependsOn(testing.suites)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
public final class HostResource {

// copied from HostIncubatingAttributes
public static final AttributeKey<String> HOST_ARCH = AttributeKey.stringKey("host.arch");
public static final AttributeKey<String> HOST_NAME = AttributeKey.stringKey("host.name");
private static final AttributeKey<String> HOST_ARCH = AttributeKey.stringKey("host.arch");
private static final AttributeKey<String> HOST_NAME = AttributeKey.stringKey("host.name");

private static final Resource INSTANCE = buildResource();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.SchemaUrls;
import io.opentelemetry.semconv.incubating.HostIncubatingAttributes;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;

class HostResourceTest {
@Test
Expand All @@ -30,18 +25,4 @@ void shouldCreateRuntimeAttributes() {
assertThat(attributes.get(HostIncubatingAttributes.HOST_NAME)).isNotBlank();
assertThat(attributes.get(HostIncubatingAttributes.HOST_ARCH)).isNotBlank();
}

@Nested
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ExtendWith(SecurityManagerExtension.class)
@EnabledOnJre(
value = {JRE.JAVA_8, JRE.JAVA_11, JRE.JAVA_16},
disabledReason = "Java 17 deprecates security manager for removal")
static class SecurityManagerEnabled {
@Test
void empty() {
Attributes attributes = HostResource.buildResource().getAttributes();
assertThat(attributes.asMap()).containsOnlyKeys(HostIncubatingAttributes.HOST_NAME);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.SchemaUrls;
import io.opentelemetry.semconv.incubating.OsIncubatingAttributes;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junitpioneer.jupiter.SetSystemProperty;

class OsResourceTest {
Expand Down Expand Up @@ -138,17 +133,4 @@ void unknown() {
assertThat(resource.getAttribute(OsIncubatingAttributes.OS_TYPE)).isNull();
assertThat(resource.getAttribute(OsIncubatingAttributes.OS_DESCRIPTION)).isNotEmpty();
}

@Nested
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ExtendWith(SecurityManagerExtension.class)
@EnabledOnJre(
value = {JRE.JAVA_8, JRE.JAVA_11, JRE.JAVA_16},
disabledReason = "Java 17 deprecates security manager for removal")
static class SecurityManagerEnabled {
@Test
void empty() {
assertThat(OsResource.buildResource()).isEqualTo(Resource.empty());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.SchemaUrls;
import io.opentelemetry.semconv.incubating.ProcessIncubatingAttributes;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junitpioneer.jupiter.SetSystemProperty;

class ProcessResourceTest {
Expand Down Expand Up @@ -52,18 +47,4 @@ void windows() {
// With Java 9+ and a compiled jar, ResourceAttributes.PROCESS_COMMAND_ARGS
// will be set instead of ResourceAttributes.PROCESS_COMMAND_LINE
}

@Nested
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ExtendWith(SecurityManagerExtension.class)
@EnabledOnJre(
value = {JRE.JAVA_8, JRE.JAVA_11, JRE.JAVA_16},
disabledReason = "Java 17 deprecates security manager for removal")
static class SecurityManagerEnabled {
@Test
void empty() {
Attributes attributes = ProcessResource.buildResource().getAttributes();
assertThat(attributes.asMap()).containsOnlyKeys(ProcessIncubatingAttributes.PROCESS_PID);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.SchemaUrls;
import io.opentelemetry.semconv.incubating.ProcessIncubatingAttributes;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;

class ProcessRuntimeResourceTest {
@Test
Expand All @@ -32,17 +27,4 @@ void shouldCreateRuntimeAttributes() {
assertThat(attributes.get(ProcessIncubatingAttributes.PROCESS_RUNTIME_DESCRIPTION))
.isNotBlank();
}

@Nested
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ExtendWith(SecurityManagerExtension.class)
@EnabledOnJre(
value = {JRE.JAVA_8, JRE.JAVA_11, JRE.JAVA_16},
disabledReason = "Java 17 deprecates security manager for removal")
static class SecurityManagerEnabled {
@Test
void empty() {
assertThat(ProcessRuntimeResource.buildResource()).isEqualTo(Resource.empty());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.resources;

import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.incubating.HostIncubatingAttributes;
import io.opentelemetry.semconv.incubating.ProcessIncubatingAttributes;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ExtendWith(SecurityManagerExtension.class)
@EnabledOnJre(
value = {JRE.JAVA_8, JRE.JAVA_11},
disabledReason = "Java 17 deprecates security manager for removal")
class SecurityManagerResourceTest {

@Test
void hostResourceTestEmpty() {
Attributes attributes = HostResource.buildResource().getAttributes();
assertThat(attributes.asMap()).containsOnlyKeys(HostIncubatingAttributes.HOST_NAME);
}

@Test
void osResourceEmpty() {
assertThat(OsResource.buildResource()).isEqualTo(Resource.empty());
}

@Test
void processResourceEmpty() {
Attributes attributes = ProcessResource.buildResource().getAttributes();
assertThat(attributes.asMap()).containsOnlyKeys(ProcessIncubatingAttributes.PROCESS_PID);
}

@Test
void processRuntimeResourceEmpty() {
assertThat(ProcessRuntimeResource.buildResource()).isEqualTo(Resource.empty());
}
}
Loading