Make the EnvironmentResource public. (#3200)

This commit is contained in:
John Watson 2021-05-06 16:50:07 -07:00 committed by GitHub
parent 940ebf0a34
commit 2a002f20fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 3 deletions

View File

@ -9,11 +9,23 @@ import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.sdk.resources.Resource;
final class EnvironmentResource {
/**
* Factory for a {@link Resource} which parses the standard "otel.resource.attributes" system
* property or OTEL_RESOURCE_ATTRIBUTES environment variable.
*/
public final class EnvironmentResource {
// Visible for testing
static final String ATTRIBUTE_PROPERTY = "otel.resource.attributes";
/**
* Returns a {@link Resource} which contains information from the standard
* "otel.resource.attributes" system property or OTEL_RESOURCE_ATTRIBUTES environment variable.
*/
public static Resource get() {
return create(ConfigProperties.get());
}
static Resource create(ConfigProperties config) {
return Resource.create(getAttributes(config));
}

View File

@ -16,6 +16,11 @@ import org.junit.jupiter.api.Test;
class EnvironmentResourceTest {
@Test
void get() {
assertThat(EnvironmentResource.get()).isNotNull();
}
@Test
void resourceFromConfig_empty() {
Attributes attributes =

View File

@ -12,12 +12,12 @@ import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import java.net.InetAddress;
import java.net.UnknownHostException;
/** Factory of a {@link Resource} which provides information about the host info. */
/** Factory for a {@link Resource} which provides information about the host info. */
public final class HostResource {
private static final Resource INSTANCE = buildResource();
/** Returns a factory for a {@link Resource} which provides information about host. */
/** Returns a {@link Resource} which provides information about host. */
public static Resource get() {
return INSTANCE;
}