NVIDIA DeepStream SDK API Reference

9.2 Release
9.2/includes/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h
Go to the documentation of this file.
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 #include <string>
7 #include <type_traits>
8 
9 #include "opentelemetry/common/key_value_iterable_view.h"
10 #include "opentelemetry/nostd/string_view.h"
11 #include "opentelemetry/nostd/type_traits.h"
12 #include "opentelemetry/nostd/unique_ptr.h"
13 #include "opentelemetry/nostd/variant.h"
14 #include "opentelemetry/sdk/common/attribute_utils.h"
15 #include "opentelemetry/version.h"
16 
18 
19 namespace sdk
20 {
21 namespace instrumentationscope
22 {
23 
24 using InstrumentationScopeAttributes = opentelemetry::sdk::common::AttributeMap;
25 
26 class InstrumentationScope
27 {
28 public:
29  InstrumentationScope(const InstrumentationScope &) = default;
30 
40  nostd::string_view name,
42  nostd::string_view schema_url = "",
43  InstrumentationScopeAttributes &&attributes = {})
44  {
46  new InstrumentationScope{name, version, schema_url, std::move(attributes)});
47  }
48 
58  nostd::string_view name,
60  nostd::string_view schema_url,
61  const InstrumentationScopeAttributes &attributes)
62  {
64  name, version, schema_url, InstrumentationScopeAttributes(attributes)});
65  }
66 
75  template <
76  class ArgumentType,
78  * = nullptr>
81  nostd::string_view schema_url,
82  const ArgumentType &arg)
83  {
85  new InstrumentationScope{name, version, schema_url});
86 
87  // Do not construct a KeyValueIterable, so it has better performance.
88  result->attributes_.reserve(opentelemetry::nostd::size(arg));
89  for (auto &argv : arg)
90  {
91  result->SetAttribute(argv.first, argv.second);
92  }
93 
94  return result;
95  }
96 
97  std::size_t HashCode() const noexcept { return hash_code_; }
98 
104  bool operator==(const InstrumentationScope &other) const noexcept
105  {
106  return this->name_ == other.name_ && this->version_ == other.version_ &&
107  this->schema_url_ == other.schema_url_ && this->attributes_ == other.attributes_;
108  }
109 
120  bool equal(const nostd::string_view name,
122  const nostd::string_view schema_url = "",
123  const opentelemetry::common::KeyValueIterable *attributes = nullptr) const noexcept
124  {
125 
126  if (this->name_ != name || this->version_ != version || this->schema_url_ != schema_url)
127  {
128  return false;
129  }
130 
131  if (attributes == nullptr)
132  {
133  if (attributes_.empty())
134  {
135  return true;
136  }
137  return false;
138  }
139 
140  return attributes_.EqualTo(*attributes);
141  }
142 
143  const std::string &GetName() const noexcept { return name_; }
144  const std::string &GetVersion() const noexcept { return version_; }
145  const std::string &GetSchemaURL() const noexcept { return schema_url_; }
146  const InstrumentationScopeAttributes &GetAttributes() const noexcept { return attributes_; }
147 
149  const opentelemetry::common::AttributeValue &value) noexcept
150  {
151  attributes_[std::string(key)] =
152  nostd::visit(opentelemetry::sdk::common::AttributeConverter(), value);
153  }
154 
155 private:
158  nostd::string_view schema_url = "",
159  InstrumentationScopeAttributes &&attributes = {})
160  : name_(name), version_(version), schema_url_(schema_url), attributes_(std::move(attributes))
161  {
162  std::string hash_data;
163  hash_data.reserve(name_.size() + version_.size() + schema_url_.size());
164  hash_data += name_;
165  hash_data += version_;
166  hash_data += schema_url_;
167  hash_code_ = std::hash<std::string>{}(hash_data);
168  }
169 
170 private:
171  std::string name_;
172  std::string version_;
173  std::string schema_url_;
174  std::size_t hash_code_;
175 
176  InstrumentationScopeAttributes attributes_;
177 };
178 
179 } // namespace instrumentationscope
180 } // namespace sdk
181 
sdk::instrumentationscope::InstrumentationScope::operator==
bool operator==(const InstrumentationScope &other) const noexcept
Compare 2 instrumentation libraries.
Definition: 9.2/includes/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h:104
sdk::instrumentationscope::InstrumentationScope
Definition: includes/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h:26
nostd::unique_ptr
Provide a simplified port of std::unique_ptr that has ABI stability.
Definition: includes/opentelemetry/nostd/unique_ptr.h:45
version
int version
Definition: sources/libs/nvll_batch_jpeg_encode/oss/jpeglib.h:908
OPENTELEMETRY_BEGIN_NAMESPACE
#define OPENTELEMETRY_BEGIN_NAMESPACE
Definition: includes/opentelemetry/version.h:21
sdk::instrumentationscope::InstrumentationScope::GetName
const std::string & GetName() const noexcept
Definition: 9.2/includes/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h:143
sdk::instrumentationscope::InstrumentationScope::InstrumentationScope
InstrumentationScope(const InstrumentationScope &)=default
common::AttributeValue
nostd::variant< bool, int32_t, int64_t, uint32_t, double, const char *, nostd::string_view, nostd::span< const bool >, nostd::span< const int32_t >, nostd::span< const int64_t >, nostd::span< const uint32_t >, nostd::span< const double >, nostd::span< const nostd::string_view >, uint64_t, nostd::span< const uint64_t >, nostd::span< const uint8_t > > AttributeValue
OpenTelemetry signals can be enriched by adding attributes.
Definition: includes/opentelemetry/common/attribute_value.h:58
sdk::instrumentationscope::InstrumentationScopeAttributes
opentelemetry::sdk::common::AttributeMap InstrumentationScopeAttributes
Definition: includes/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h:24
OPENTELEMETRY_END_NAMESPACE
#define OPENTELEMETRY_END_NAMESPACE
Definition: includes/opentelemetry/version.h:24
absl::move
constexpr absl::OTABSL_OPTION_NAMESPACE_NAME::remove_reference_t< T > && move(T &&t) noexcept
Definition: includes/opentelemetry/nostd/internal/absl/utility/utility.h:199
pydeepstreamdoc::tensor::TensorDoc::size
constexpr const char * size
Definition: service-maker/sources/python/src/bindings/docstrings/tensordoc.h:46
sdk::instrumentationscope::InstrumentationScope::GetSchemaURL
const std::string & GetSchemaURL() const noexcept
Definition: 9.2/includes/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h:145
nostd::visit
constexpr auto visit(_Callable &&_Obj, _Variants &&..._Args)
Definition: includes/opentelemetry/std/variant.h:196
nostd::enable_if_t
typename std::enable_if< B, T >::type enable_if_t
Back port of std::enable_if_t.
Definition: includes/opentelemetry/nostd/type_traits.h:40
sdk::instrumentationscope::InstrumentationScope::Create
static nostd::unique_ptr< InstrumentationScope > Create(nostd::string_view name, nostd::string_view version, nostd::string_view schema_url, const ArgumentType &arg)
Returns a newly created InstrumentationScope with the specified library name and version.
Definition: 9.2/includes/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h:79
sdk
Definition: includes/opentelemetry/sdk/common/atomic_shared_ptr.h:13
sdk::instrumentationscope::InstrumentationScope::Create
static nostd::unique_ptr< InstrumentationScope > Create(nostd::string_view name, nostd::string_view version, nostd::string_view schema_url, const InstrumentationScopeAttributes &attributes)
Returns a newly created InstrumentationScope with the specified library name and version.
Definition: 9.2/includes/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h:57
sdk::instrumentationscope::InstrumentationScope::GetAttributes
const InstrumentationScopeAttributes & GetAttributes() const noexcept
Definition: 9.2/includes/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h:146
sdk::instrumentationscope::InstrumentationScope::Create
static nostd::unique_ptr< InstrumentationScope > Create(nostd::string_view name, nostd::string_view version="", nostd::string_view schema_url="", InstrumentationScopeAttributes &&attributes={})
Returns a newly created InstrumentationScope with the specified library name and version.
Definition: 9.2/includes/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h:39
sdk::instrumentationscope::InstrumentationScope::HashCode
std::size_t HashCode() const noexcept
Definition: 9.2/includes/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h:97
sdk::instrumentationscope::InstrumentationScope::equal
bool equal(const nostd::string_view name, const nostd::string_view version, const nostd::string_view schema_url="", const opentelemetry::common::KeyValueIterable *attributes=nullptr) const noexcept
Check whether the instrumentation scope has given name and version.
Definition: 9.2/includes/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h:120
sdk::instrumentationscope::InstrumentationScope::GetVersion
const std::string & GetVersion() const noexcept
Definition: 9.2/includes/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h:144
nostd::string_view
Back port of std::string_view to work with pre-cpp-17 compilers.
Definition: includes/opentelemetry/nostd/string_view.h:37
sdk::instrumentationscope::InstrumentationScope::SetAttribute
void SetAttribute(nostd::string_view key, const opentelemetry::common::AttributeValue &value) noexcept
Definition: 9.2/includes/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h:148