Class Resource


  • @Immutable
    public abstract class Resource
    extends Object
    Resource represents a resource, which capture identifying information about the entities for which signals (stats or traces) are reported.
    • Method Detail

      • getDefault

        public static Resource getDefault()
        Returns the default Resource. This resource contains the default attributes provided by the SDK.
        Returns:
        a Resource.
      • empty

        public static Resource empty()
        Returns an empty Resource. When creating a Resource, it is strongly recommended to start with getDefault() 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 a Resource.
        Parameters:
        attributes - a map of attributes that describe the resource.
        Returns:
        a Resource.
        Throws:
        NullPointerException - if attributes is null.
        IllegalArgumentException - if attribute key or attribute value is not a valid printable ASCII string or exceed MAX_LENGTH characters.
      • create

        public static Resource create​(io.opentelemetry.api.common.Attributes attributes,
                                      @Nullable
                                      String schemaUrl)
        Returns a Resource.
        Parameters:
        attributes - a map of Attributes that describe the resource.
        schemaUrl - The URL of the OpenTelemetry schema used to create this Resource.
        Returns:
        a Resource.
        Throws:
        NullPointerException - if attributes is null.
        IllegalArgumentException - if attribute key or attribute value is not a valid printable ASCII string or exceed MAX_LENGTH characters.
      • 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, merged Resource by merging the current Resource with the other Resource. In case of a collision, the "other" Resource takes precedence.
        Parameters:
        other - the Resource that will be merged with this.
        Returns:
        the newly merged Resource.