Package io.opentelemetry.sdk.resources
Class Resource
- java.lang.Object
-
- io.opentelemetry.sdk.resources.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.static Resourcecreate(io.opentelemetry.api.common.Attributes attributes)Returns aResource.static Resourcecreate(io.opentelemetry.api.common.Attributes attributes, String schemaUrl)Returns aResource.static Resourceempty()Returns an emptyResource.<T> TgetAttribute(io.opentelemetry.api.common.AttributeKey<T> key)Returns the value for a given resource attribute key.abstract io.opentelemetry.api.common.AttributesgetAttributes()Returns a map of attributes that describe the resource.static ResourcegetDefault()Returns the defaultResource.abstract StringgetSchemaUrl()Returns the URL of the OpenTelemetry schema used by this resource.Resourcemerge(Resource other)ResourceBuildertoBuilder()Returns a newResourceBuilderinstance populated with the data of thisResource.
-
-
-
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(io.opentelemetry.api.common.Attributes attributes)
Returns aResource.- Parameters:
attributes- a map of attributes that describe the resource.- Returns:
- a
Resource. - Throws:
NullPointerException- ifattributesis null.IllegalArgumentException- if attribute key or attribute value is not a valid printable ASCII string or exceedMAX_LENGTHcharacters.
-
create
public static Resource create(io.opentelemetry.api.common.Attributes attributes, @Nullable 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:
NullPointerException- ifattributesis null.IllegalArgumentException- if attribute key or attribute value is not a valid printable ASCII string or exceedMAX_LENGTHcharacters.
-
getSchemaUrl
@Nullable public abstract 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 io.opentelemetry.api.common.Attributes getAttributes()
Returns a map of attributes that describe the resource.- Returns:
- a map of attributes.
-
getAttribute
@Nullable public <T> T getAttribute(io.opentelemetry.api.common.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.
-
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
-
-