Make the EnvironmentResource public. (#3200)
This commit is contained in:
parent
940ebf0a34
commit
2a002f20fa
|
|
@ -9,11 +9,23 @@ import io.opentelemetry.api.common.Attributes;
|
||||||
import io.opentelemetry.api.common.AttributesBuilder;
|
import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
import io.opentelemetry.sdk.resources.Resource;
|
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
|
// Visible for testing
|
||||||
static final String ATTRIBUTE_PROPERTY = "otel.resource.attributes";
|
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) {
|
static Resource create(ConfigProperties config) {
|
||||||
return Resource.create(getAttributes(config));
|
return Resource.create(getAttributes(config));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,11 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
class EnvironmentResourceTest {
|
class EnvironmentResourceTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void get() {
|
||||||
|
assertThat(EnvironmentResource.get()).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void resourceFromConfig_empty() {
|
void resourceFromConfig_empty() {
|
||||||
Attributes attributes =
|
Attributes attributes =
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,12 @@ import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
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 {
|
public final class HostResource {
|
||||||
|
|
||||||
private static final Resource INSTANCE = buildResource();
|
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() {
|
public static Resource get() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue