Class Resource

java.lang.Object
io.opencensus.resource.Resource
Direct Known Subclasses:
AutoValue_Resource

@Immutable @ExperimentalApi 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. It further provides a framework for detection of resource information from the environment and progressive population as signals propagate from the core instrumentation library to a backend's exporter.
Since:
0.18
  • Field Details

  • Constructor Details

    • Resource

      Resource()
  • Method Details

    • getType

      @Nullable public abstract String getType()
      Returns the type identifier for the resource.
      Returns:
      the type identifier for the resource.
      Since:
      0.18
    • getLabels

      public abstract Map<String,String> getLabels()
      Returns a map of labels that describe the resource.
      Returns:
      a map of labels.
      Since:
      0.18
    • createFromEnvironmentVariables

      public static Resource createFromEnvironmentVariables()
      Returns a Resource. This resource information is loaded from the OC_RESOURCE_TYPE and OC_RESOURCE_LABELS environment variables.
      Returns:
      a Resource.
      Since:
      0.18
    • create

      public static Resource create(@Nullable String type, Map<String,String> labels)
      Returns a Resource.
      Parameters:
      type - the type identifier for the resource.
      labels - a map of labels that describe the resource.
      Returns:
      a Resource.
      Throws:
      NullPointerException - if labels is null.
      IllegalArgumentException - if type or label key or label value is not a valid printable ASCII string or exceed MAX_LENGTH characters.
      Since:
      0.18
    • mergeResources

      @Nullable public static Resource mergeResources(List<Resource> resources)
      Returns a Resource that runs all input resources sequentially and merges their results. In case a type of label key is already set, the first set value takes precedence.
      Parameters:
      resources - a list of resources.
      Returns:
      a Resource.
      Since:
      0.18
    • createInternal

      private static Resource createInternal(@Nullable String type, Map<String,String> labels)
    • parseResourceType

      @Nullable static String parseResourceType(@Nullable String rawEnvType)
      Creates a resource type from the OC_RESOURCE_TYPE environment variable.

      OC_RESOURCE_TYPE: A string that describes the type of the resource prefixed by a domain namespace, e.g. “kubernetes.io/container”.

    • parseResourceLabels

      static Map<String,String> parseResourceLabels(@Nullable String rawEnvLabels)
    • merge

      @Nullable private static Resource merge(@Nullable Resource resource, @Nullable Resource otherResource)
      Returns a new, merged Resource by merging two resources. In case of a collision, first resource takes precedence.
    • isValid

      private static boolean isValid(String name)
      Determines whether the given String is a valid printable ASCII string with a length not exceed MAX_LENGTH characters.
      Parameters:
      name - the name to be validated.
      Returns:
      whether the name is valid.
    • isValidAndNotEmpty

      private static boolean isValidAndNotEmpty(String name)
      Determines whether the given String is a valid printable ASCII string with a length greater than 0 and not exceed MAX_LENGTH characters.
      Parameters:
      name - the name to be validated.
      Returns:
      whether the name is valid.