Class Resource

Class Documentation

class Resource

Public Functions

Resource(const Resource&) = default
const ResourceAttributes &GetAttributes() const noexcept
const std::string &GetSchemaURL() const noexcept
Resource Merge(const Resource &other) const noexcept

Returns a new, merged Resource by merging the current Resource with the other Resource. In case of a collision, the other Resource takes precedence.

The specification notes that if schema urls collide, the resulting schema url is implementation-defined. In the C++ implementation, the schema url of

Parameters:
  • other – is picked.

  • other – the Resource that will be merged with this.

Returns:

the newly merged Resource.

Public Static Functions

static Resource Create(const ResourceAttributes &attributes, const std::string &schema_url = std::string{})

Returns a newly created Resource with the specified attributes. It adds (merge) SDK attributes and OTEL attributes before returning.

Parameters:

attributes – for this resource

Returns:

the newly created Resource.

static Resource &GetEmpty()

Returns an Empty resource.

static Resource &GetDefault()

Returns a Resource that indentifies the SDK in use.

Protected Functions

Resource(const ResourceAttributes &attributes = ResourceAttributes(), const std::string &schema_url = std::string{}) noexcept

The constructor is protected and only for use internally by the class and inside ResourceDetector class. Users should use the Create factory method to obtain a Resource instance.