Package io.opentelemetry.sdk.resources
Class Resource
java.lang.Object
io.opentelemetry.sdk.resources.Resource
- Direct Known Subclasses:
AutoValue_Resource
Resource
represents a resource, which capture identifying information about the entities
for which signals (stats or traces) are reported.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Resource
private static final Resource
private static final String
private static final String
private static final Logger
private static final Resource
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.private static final int
private static final AttributeKey
<String> private static final Resource
private static final AttributeKey
<String> private static final AttributeKey
<String> private static final AttributeKey
<String> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ResourceBuilder
builder()
Returns a newResourceBuilder
instance for creating arbitraryResource
.private static void
checkAttributes
(Attributes attributes) static Resource
create
(Attributes attributes) Returns aResource
.static Resource
create
(Attributes attributes, String schemaUrl) Returns aResource
.static Resource
empty()
Returns an emptyResource
.<T> T
getAttribute
(AttributeKey<T> key) Returns the value for a given resource attribute key.abstract Attributes
Returns a map of attributes that describe the resource.static Resource
Returns the defaultResource
.abstract String
Returns the URL of the OpenTelemetry schema used by this resource.private static boolean
Determines whether the givenString
is a valid printable ASCII string with a length not exceedMAX_LENGTH
characters.private static boolean
isValidAndNotEmpty
(AttributeKey<?> name) Determines whether the givenString
is a valid printable ASCII string with a length greater than 0 and not exceedMAX_LENGTH
characters.Returns a newResourceBuilder
instance populated with the data of thisResource
.
-
Field Details
-
logger
-
SERVICE_NAME
-
TELEMETRY_SDK_LANGUAGE
-
TELEMETRY_SDK_NAME
-
TELEMETRY_SDK_VERSION
-
MAX_LENGTH
private static final int MAX_LENGTH- See Also:
-
ERROR_MESSAGE_INVALID_CHARS
- See Also:
-
ERROR_MESSAGE_INVALID_VALUE
- See Also:
-
EMPTY
-
TELEMETRY_SDK
-
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
-
-
Constructor Details
-
Resource
Resource()
-
-
Method Details
-
getDefault
Returns the defaultResource
. This resource contains the default attributes provided by the SDK.- Returns:
- a
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
Returns aResource
.- Parameters:
attributes
- a map of attributes that describe the resource.- Returns:
- a
Resource
. - Throws:
NullPointerException
- ifattributes
is null.IllegalArgumentException
- if attribute key or attribute value is not a valid printable ASCII string or exceedMAX_LENGTH
characters.
-
create
Returns aResource
.- Parameters:
attributes
- a map ofAttributes
that describe the resource.schemaUrl
- The URL of the OpenTelemetry schema used to create this Resource.- Returns:
- a
Resource
. - Throws:
NullPointerException
- ifattributes
is null.IllegalArgumentException
- if attribute key or attribute value is not a valid printable ASCII string or exceedMAX_LENGTH
characters.
-
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
Returns a map of attributes that describe the resource.- Returns:
- a map of attributes.
-
getAttribute
Returns the value for a given resource attribute key.- Returns:
- the value of the attribute with the given key
-
merge
Returns a new, mergedResource
by merging the currentResource
with theother
Resource
. In case of a collision, the "other"Resource
takes precedence.- Parameters:
other
- theResource
that will be merged withthis
.- Returns:
- the newly merged
Resource
.
-
checkAttributes
-
isValid
Determines whether the givenString
is a valid printable ASCII string with a length not exceedMAX_LENGTH
characters.- Parameters:
name
- the name to be validated.- Returns:
- whether the name is valid.
-
isValidAndNotEmpty
Determines whether the givenString
is a valid printable ASCII string with a length greater than 0 and not exceedMAX_LENGTH
characters.- Parameters:
name
- the name to be validated.- Returns:
- whether the name is valid.
-
builder
Returns a newResourceBuilder
instance for creating arbitraryResource
.- Since:
- 1.1.0
-
toBuilder
Returns a newResourceBuilder
instance populated with the data of thisResource
.- Since:
- 1.1.0
-