NVIDIA DeepStream SDK API Reference

9.2 Release
includes/opentelemetry/sdk/metrics/view/attributes_processor.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 <cstring>
7 #include <string>
8 #include <unordered_map>
9 #include <utility>
10 
11 #include "opentelemetry/common/attribute_value.h"
12 #include "opentelemetry/common/key_value_iterable.h"
13 #include "opentelemetry/nostd/string_view.h"
14 #include "opentelemetry/sdk/common/custom_hash_equality.h"
15 #include "opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h"
16 #include "opentelemetry/version.h"
17 
19 namespace sdk
20 {
21 namespace metrics
22 {
23 
24 using MetricAttributes = opentelemetry::sdk::metrics::FilteredOrderedAttributeMap;
25 
26 typedef std::unordered_map<std::string,
27  bool,
28  opentelemetry::sdk::common::StringViewHash,
29  opentelemetry::sdk::common::StringViewEqual>
31 
38 {
39 public:
40  // Process the metric instrument attributes.
41  // @returns integer with individual bits set if they are to be filtered.
42 
43  virtual MetricAttributes process(
44  const opentelemetry::common::KeyValueIterable &attributes) const noexcept = 0;
45 
46  virtual bool isPresent(nostd::string_view key) const noexcept = 0;
47 
48  virtual ~AttributesProcessor() = default;
49 };
50 
57 {
58 public:
60  const opentelemetry::common::KeyValueIterable &attributes) const noexcept override
61  {
62  MetricAttributes result(attributes);
63  return result;
64  }
65 
66  bool isPresent(nostd::string_view /*key*/) const noexcept override { return true; }
67 };
68 
75 {
76 public:
77  FilteringAttributesProcessor(FilterAttributeMap &&allowed_attribute_keys = {})
78  : allowed_attribute_keys_(std::move(allowed_attribute_keys))
79  {}
80 
81  FilteringAttributesProcessor(const FilterAttributeMap &allowed_attribute_keys = {})
82  : allowed_attribute_keys_(allowed_attribute_keys)
83  {}
84 
86  const opentelemetry::common::KeyValueIterable &attributes) const noexcept override
87  {
88  MetricAttributes result;
89  attributes.ForEachKeyValue(
91  if (opentelemetry::sdk::common::find_heterogeneous(allowed_attribute_keys_, key) !=
92  allowed_attribute_keys_.end())
93  {
94  result.SetAttribute(key, value);
95  return true;
96  }
97  return true;
98  });
99 
100  result.UpdateHash();
101  return result;
102  }
103 
104  bool isPresent(nostd::string_view key) const noexcept override
105  {
106  return (opentelemetry::sdk::common::find_heterogeneous(allowed_attribute_keys_, key) !=
107  allowed_attribute_keys_.end());
108  }
109 
110 private:
111  FilterAttributeMap allowed_attribute_keys_;
112 };
113 
120 {
121 public:
123  : exclude_list_(std::move(exclude_list))
124  {}
125 
127  : exclude_list_(exclude_list)
128  {}
129 
131  const opentelemetry::common::KeyValueIterable &attributes) const noexcept override
132  {
133  MetricAttributes result;
134  attributes.ForEachKeyValue([&](nostd::string_view key,
135  opentelemetry::common::AttributeValue value) noexcept {
136  if (opentelemetry::sdk::common::find_heterogeneous(exclude_list_, key) == exclude_list_.end())
137  {
138  result.SetAttribute(key, value);
139  return true;
140  }
141  return true;
142  });
143 
144  result.UpdateHash();
145  return result;
146  }
147 
148  bool isPresent(nostd::string_view key) const noexcept override
149  {
150  return (opentelemetry::sdk::common::find_heterogeneous(exclude_list_, key) ==
151  exclude_list_.end());
152  }
153 
154 private:
155  FilterAttributeMap exclude_list_;
156 };
157 
158 } // namespace metrics
159 } // namespace sdk
sdk::metrics::AttributesProcessor::process
virtual MetricAttributes process(const opentelemetry::common::KeyValueIterable &attributes) const noexcept=0
sdk::metrics::DefaultAttributesProcessor
DefaultAttributesProcessor returns copy of input instrument attributes without any modification.
Definition: includes/opentelemetry/sdk/metrics/view/attributes_processor.h:56
sdk::metrics::FilteringExcludeAttributesProcessor::process
MetricAttributes process(const opentelemetry::common::KeyValueIterable &attributes) const noexcept override
Definition: includes/opentelemetry/sdk/metrics/view/attributes_processor.h:130
sdk::metrics::FilteringExcludeAttributesProcessor
FilteringExcludeAttributeProcessor filters by exclude attribute list and drops names if they are pres...
Definition: includes/opentelemetry/sdk/metrics/view/attributes_processor.h:119
sdk::metrics::FilteringAttributesProcessor
FilteringAttributesProcessor filters by allowed attribute names and drops any names that are not in t...
Definition: includes/opentelemetry/sdk/metrics/view/attributes_processor.h:74
OPENTELEMETRY_BEGIN_NAMESPACE
#define OPENTELEMETRY_BEGIN_NAMESPACE
Definition: includes/opentelemetry/version.h:21
sdk::metrics::FilteringExcludeAttributesProcessor::FilteringExcludeAttributesProcessor
FilteringExcludeAttributesProcessor(const FilterAttributeMap &exclude_list={})
Definition: includes/opentelemetry/sdk/metrics/view/attributes_processor.h:126
sdk::metrics::FilteringExcludeAttributesProcessor::isPresent
bool isPresent(nostd::string_view key) const noexcept override
Definition: includes/opentelemetry/sdk/metrics/view/attributes_processor.h:148
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::metrics::MetricAttributes
opentelemetry::sdk::metrics::FilteredOrderedAttributeMap MetricAttributes
Definition: includes/opentelemetry/sdk/metrics/instruments.h:216
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
sdk::metrics::FilterAttributeMap
std::unordered_map< std::string, bool, opentelemetry::sdk::common::StringViewHash, opentelemetry::sdk::common::StringViewEqual > FilterAttributeMap
Definition: includes/opentelemetry/sdk/metrics/view/attributes_processor.h:30
sdk::metrics::FilteringAttributesProcessor::process
MetricAttributes process(const opentelemetry::common::KeyValueIterable &attributes) const noexcept override
Definition: includes/opentelemetry/sdk/metrics/view/attributes_processor.h:85
sdk::metrics::AttributesProcessor::isPresent
virtual bool isPresent(nostd::string_view key) const noexcept=0
sdk::metrics::AttributesProcessor
The AttributesProcessor is responsible for customizing which attribute(s) are to be reported as metri...
Definition: includes/opentelemetry/sdk/metrics/view/attributes_processor.h:37
sdk::metrics::DefaultAttributesProcessor::isPresent
bool isPresent(nostd::string_view) const noexcept override
Definition: includes/opentelemetry/sdk/metrics/view/attributes_processor.h:66
sdk::metrics::FilteringAttributesProcessor::FilteringAttributesProcessor
FilteringAttributesProcessor(const FilterAttributeMap &allowed_attribute_keys={})
Definition: includes/opentelemetry/sdk/metrics/view/attributes_processor.h:81
sdk
Definition: includes/opentelemetry/sdk/common/atomic_shared_ptr.h:13
sdk::common::find_heterogeneous
auto find_heterogeneous(MapType &&map, opentelemetry::nostd::string_view key)
Cross-platform heterogeneous lookup wrapper.
Definition: includes/opentelemetry/sdk/common/custom_hash_equality.h:145
sdk::metrics::FilteringAttributesProcessor::isPresent
bool isPresent(nostd::string_view key) const noexcept override
Definition: includes/opentelemetry/sdk/metrics/view/attributes_processor.h:104
metrics
Definition: includes/opentelemetry/metrics/async_instruments.h:10
sdk::metrics::FilteringExcludeAttributesProcessor::FilteringExcludeAttributesProcessor
FilteringExcludeAttributesProcessor(FilterAttributeMap &&exclude_list={})
Definition: includes/opentelemetry/sdk/metrics/view/attributes_processor.h:122
sdk::metrics::DefaultAttributesProcessor::process
MetricAttributes process(const opentelemetry::common::KeyValueIterable &attributes) const noexcept override
Definition: includes/opentelemetry/sdk/metrics/view/attributes_processor.h:59
sdk::metrics::FilteringAttributesProcessor::FilteringAttributesProcessor
FilteringAttributesProcessor(FilterAttributeMap &&allowed_attribute_keys={})
Definition: includes/opentelemetry/sdk/metrics/view/attributes_processor.h:77
sdk::metrics::AttributesProcessor::~AttributesProcessor
virtual ~AttributesProcessor()=default
nostd::string_view
Back port of std::string_view to work with pre-cpp-17 compilers.
Definition: includes/opentelemetry/nostd/string_view.h:37