Package io.opentelemetry.sdk.resources
Class Resource
- java.lang.Object
-
- io.opentelemetry.sdk.resources.Resource
-
- Direct Known Subclasses:
AutoValue_Resource
@Immutable public abstract class Resource extends java.lang.ObjectResourcerepresents a resource, which capture identifying information about the entities for which signals (stats or traces) are reported.
-
-
Field Summary
Fields Modifier and Type Field Description private static ResourceDEFAULTprivate static ResourceEMPTYprivate static java.lang.StringERROR_MESSAGE_INVALID_CHARSprivate static java.lang.StringERROR_MESSAGE_INVALID_VALUEprivate static java.util.logging.Loggerloggerprivate static ResourceMANDATORYThe MANDATORY Resource instance contains the mandatory attributes that must be used if they are not provided by the Resource that is given to an SDK signal provider.private static intMAX_LENGTHprivate static AttributeKey<java.lang.String>SERVICE_NAMEprivate static ResourceTELEMETRY_SDKprivate static AttributeKey<java.lang.String>TELEMETRY_SDK_LANGUAGEprivate static AttributeKey<java.lang.String>TELEMETRY_SDK_NAMEprivate static AttributeKey<java.lang.String>TELEMETRY_SDK_VERSION
-
Constructor Summary
Constructors Constructor Description Resource()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static ResourceBuilderbuilder()Returns a newResourceBuilderinstance for creating arbitraryResource.private static voidcheckAttributes(Attributes attributes)static Resourcecreate(Attributes attributes)Returns aResource.static Resourcecreate(Attributes attributes, java.lang.String schemaUrl)Returns aResource.static Resourceempty()Returns an emptyResource.<T> TgetAttribute(AttributeKey<T> key)Returns the value for a given resource attribute key.abstract AttributesgetAttributes()Returns a map of attributes that describe the resource.static ResourcegetDefault()Returns the defaultResource.abstract java.lang.StringgetSchemaUrl()Returns the URL of the OpenTelemetry schema used by this resource.private static booleanisValid(java.lang.String name)Determines whether the givenStringis a valid printable ASCII string with a length not exceedMAX_LENGTHcharacters.private static booleanisValidAndNotEmpty(AttributeKey<?> name)Determines whether the givenStringis a valid printable ASCII string with a length greater than 0 and not exceedMAX_LENGTHcharacters.Resourcemerge(Resource other)ResourceBuildertoBuilder()Returns a newResourceBuilderinstance populated with the data of thisResource.
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
SERVICE_NAME
private static final AttributeKey<java.lang.String> SERVICE_NAME
-
TELEMETRY_SDK_LANGUAGE
private static final AttributeKey<java.lang.String> TELEMETRY_SDK_LANGUAGE
-
TELEMETRY_SDK_NAME
private static final AttributeKey<java.lang.String> TELEMETRY_SDK_NAME
-
TELEMETRY_SDK_VERSION
private static final AttributeKey<java.lang.String> TELEMETRY_SDK_VERSION
-
MAX_LENGTH
private static final int MAX_LENGTH
- See Also:
- Constant Field Values
-
ERROR_MESSAGE_INVALID_CHARS
private static final java.lang.String ERROR_MESSAGE_INVALID_CHARS
- See Also:
- Constant Field Values
-
ERROR_MESSAGE_INVALID_VALUE
private static final java.lang.String ERROR_MESSAGE_INVALID_VALUE
- See Also:
- Constant Field Values
-
EMPTY
private static final Resource EMPTY
-
TELEMETRY_SDK
private static final Resource TELEMETRY_SDK
-
MANDATORY
private static final Resource MANDATORY
The MANDATORY Resource instance contains the mandatory attributes that must be used if they are not provided by the Resource that is given to an SDK signal provider.
-
DEFAULT
private static final Resource DEFAULT
-
-
Method Detail
-
getDefault
public static Resource getDefault()
Returns the defaultResource. This resource contains the default attributes provided by the SDK.- Returns:
- a
Resource.
-
empty
public static Resource empty()
Returns an emptyResource. When creating aResource, it is strongly recommended to start withgetDefault()instead of this method to include SDK required attributes.- Returns:
- an empty
Resource.
-
create
public static Resource create(Attributes attributes)
Returns aResource.- Parameters:
attributes- a map of attributes that describe the resource.- Returns:
- a
Resource. - Throws:
java.lang.NullPointerException- ifattributesis null.java.lang.IllegalArgumentException- if attribute key or attribute value is not a valid printable ASCII string or exceedMAX_LENGTHcharacters.
-
create
public static Resource create(Attributes attributes, @Nullable java.lang.String schemaUrl)
Returns aResource.- Parameters:
attributes- a map ofAttributesthat describe the resource.schemaUrl- The URL of the OpenTelemetry schema used to create this Resource.- Returns:
- a
Resource. - Throws:
java.lang.NullPointerException- ifattributesis null.java.lang.IllegalArgumentException- if attribute key or attribute value is not a valid printable ASCII string or exceedMAX_LENGTHcharacters.
-
getSchemaUrl
@Nullable public abstract java.lang.String getSchemaUrl()
Returns the URL of the OpenTelemetry schema used by this resource. May be null.- Returns:
- An OpenTelemetry schema URL.
- Since:
- 1.4.0
-
getAttributes
public abstract Attributes getAttributes()
Returns a map of attributes that describe the resource.- Returns:
- a map of attributes.
-
getAttribute
@Nullable public <T> T getAttribute(AttributeKey<T> key)
Returns the value for a given resource attribute key.- Returns:
- the value of the attribute with the given key
-
merge
public Resource merge(@Nullable Resource other)
Returns a new, mergedResourceby merging the currentResourcewith theotherResource. In case of a collision, the "other"Resourcetakes precedence.- Parameters:
other- theResourcethat will be merged withthis.- Returns:
- the newly merged
Resource.
-
checkAttributes
private static void checkAttributes(Attributes attributes)
-
isValid
private static boolean isValid(java.lang.String name)
Determines whether the givenStringis a valid printable ASCII string with a length not exceedMAX_LENGTHcharacters.- Parameters:
name- the name to be validated.- Returns:
- whether the name is valid.
-
isValidAndNotEmpty
private static boolean isValidAndNotEmpty(AttributeKey<?> name)
Determines whether the givenStringis a valid printable ASCII string with a length greater than 0 and not exceedMAX_LENGTHcharacters.- Parameters:
name- the name to be validated.- Returns:
- whether the name is valid.
-
builder
public static ResourceBuilder builder()
Returns a newResourceBuilderinstance for creating arbitraryResource.- Since:
- 1.1.0
-
toBuilder
public ResourceBuilder toBuilder()
Returns a newResourceBuilderinstance populated with the data of thisResource.- Since:
- 1.1.0
-
-