NVIDIA DeepStream SDK API Reference

9.2 Release
includes/opentelemetry/sdk/instrumentationscope/scope_configurator.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 #include <functional>
6 
7 #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
8 #include "opentelemetry/version.h"
9 
11 namespace sdk
12 {
13 namespace instrumentationscope
14 {
19 template <typename T>
21 {
22 public:
26  class Builder
27  {
28  public:
36  explicit Builder(T default_scope_config) noexcept : default_scope_config_(default_scope_config)
37  {}
38 
48  Builder &AddCondition(std::function<bool(const InstrumentationScope &)> scope_matcher,
49  T scope_config)
50  {
51  conditions_.emplace_back(scope_matcher, scope_config);
52  return *this;
53  }
54 
63  Builder &AddConditionNameEquals(nostd::string_view scope_name, T scope_config)
64  {
65  std::function<bool(const InstrumentationScope &)> name_equals_matcher =
66  [scope_name = std::string(scope_name)](const InstrumentationScope &scope_info) {
67  return scope_info.GetName() == scope_name;
68  };
69  conditions_.emplace_back(name_equals_matcher, scope_config);
70  return *this;
71  }
72 
79  {
80  if (conditions_.size() == 0)
81  {
82  return ScopeConfigurator<T>(
83  [default_scope_config_ = this->default_scope_config_](const InstrumentationScope &) {
84  return default_scope_config_;
85  });
86  }
87 
88  // Return a configurator that processes all the conditions
89  return ScopeConfigurator<T>(
90  [conditions_ = this->conditions_, default_scope_config_ = this->default_scope_config_](
91  const InstrumentationScope &scope_info) {
92  for (Condition condition : conditions_)
93  {
94  if (condition.scope_matcher(scope_info))
95  {
96  return condition.scope_config;
97  }
98  }
99  return default_scope_config_;
100  });
101  }
102 
103  private:
109  struct Condition
110  {
111  std::function<bool(const InstrumentationScope &)> scope_matcher;
112  T scope_config;
113 
114  Condition(const std::function<bool(const InstrumentationScope &)> &matcher, const T &config)
115  : scope_matcher(matcher), scope_config(config)
116  {}
117  };
118 
119  T default_scope_config_;
120  std::vector<Condition> conditions_;
121  };
122 
123  // Public methods for ScopeConfigurator
124 
130  T ComputeConfig(const InstrumentationScope &scope_info) const
131  {
132  return this->configurator_(scope_info);
133  }
134 
135 private:
136  // Prevent direct initialization of ScopeConfigurator objects.
137  explicit ScopeConfigurator(std::function<T(const InstrumentationScope &)> configurator)
138  : configurator_(configurator)
139  {}
140 
141  std::function<T(const InstrumentationScope &)> configurator_;
142 };
143 } // namespace instrumentationscope
144 } // namespace sdk
sdk::instrumentationscope::ScopeConfigurator::Builder::AddCondition
Builder & AddCondition(std::function< bool(const InstrumentationScope &)> scope_matcher, T scope_config)
Allows the user to pass a generic function that evaluates an instrumentation scope through a boolean ...
Definition: includes/opentelemetry/sdk/instrumentationscope/scope_configurator.h:48
sdk::instrumentationscope::InstrumentationScope
Definition: includes/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h:26
sdk::instrumentationscope::ScopeConfigurator::Builder::Builder
Builder(T default_scope_config) noexcept
Constructor for a builder object that cam be used to create a scope configurator.
Definition: includes/opentelemetry/sdk/instrumentationscope/scope_configurator.h:36
OPENTELEMETRY_BEGIN_NAMESPACE
#define OPENTELEMETRY_BEGIN_NAMESPACE
Definition: includes/opentelemetry/version.h:21
sdk::instrumentationscope::ScopeConfigurator::Builder::Build
ScopeConfigurator< T > Build() const
Constructs the scope configurator object that can be used to retrieve scope config depending on the i...
Definition: includes/opentelemetry/sdk/instrumentationscope/scope_configurator.h:78
OPENTELEMETRY_END_NAMESPACE
#define OPENTELEMETRY_END_NAMESPACE
Definition: includes/opentelemetry/version.h:24
sdk::instrumentationscope::ScopeConfigurator::Builder
A builder class for the ScopeConfigurator that facilitates the creation of ScopeConfigurators.
Definition: includes/opentelemetry/sdk/instrumentationscope/scope_configurator.h:26
sdk::instrumentationscope::ScopeConfigurator::ComputeConfig
T ComputeConfig(const InstrumentationScope &scope_info) const
Invokes the underlying configurator function to get a valid scope configuration.
Definition: includes/opentelemetry/sdk/instrumentationscope/scope_configurator.h:130
sdk::instrumentationscope::ScopeConfigurator::Builder::AddConditionNameEquals
Builder & AddConditionNameEquals(nostd::string_view scope_name, T scope_config)
A convenience condition that specifically matches the scope name of the scope being evaluated.
Definition: includes/opentelemetry/sdk/instrumentationscope/scope_configurator.h:63
sdk::instrumentationscope::ScopeConfigurator
A scope configurator is a function that returns the scope config for a given instrumentation scope.
Definition: includes/opentelemetry/sdk/instrumentationscope/scope_configurator.h:20
sdk
Definition: includes/opentelemetry/sdk/common/atomic_shared_ptr.h:13
nostd::string_view
Back port of std::string_view to work with pre-cpp-17 compilers.
Definition: includes/opentelemetry/nostd/string_view.h:37