Program Listing for File resource.h

Return to documentation for file (/home/docs/checkouts/readthedocs.org/user_builds/opentelemetry-cpp/checkouts/v1.4.1/sdk/include/opentelemetry/sdk/resource/resource.h)

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/common/key_value_iterable_view.h"

#include "opentelemetry/sdk/common/attribute_utils.h"
#include "opentelemetry/sdk/resource/resource_detector.h"
#include "opentelemetry/sdk/version/version.h"
#include "opentelemetry/version.h"

#include <memory>
#include <sstream>
#include <unordered_map>

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace resource
{

using ResourceAttributes = opentelemetry::sdk::common::AttributeMap;

class Resource
{
public:
  Resource(const Resource &) = default;

  const ResourceAttributes &GetAttributes() const noexcept;
  const std::string &GetSchemaURL() const noexcept;

  Resource Merge(const Resource &other) noexcept;

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

  static Resource &GetEmpty();

  static Resource &GetDefault();

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

private:
  ResourceAttributes attributes_;
  std::string schema_url_;

  friend class OTELResourceDetector;
};

}  // namespace resource
}  // namespace sdk
OPENTELEMETRY_END_NAMESPACE