-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SDK] Add tracer scope configurator #3137
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for opentelemetry-cpp-api-docs canceled.
|
6e15bc3
to
75d84d8
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3137 +/- ##
==========================================
- Coverage 87.83% 87.81% -0.02%
==========================================
Files 195 197 +2
Lines 6146 6176 +30
==========================================
+ Hits 5398 5423 +25
- Misses 748 753 +5
|
75d84d8
to
fd0178c
Compare
ec4209e
to
606ae37
Compare
f5a5673
to
fbfd3de
Compare
fee7f7c
to
15274c0
Compare
15274c0
to
e02d1c5
Compare
28aae45
to
a8a04e5
Compare
5517d8a
to
79c32f3
Compare
fc6e563
to
85ce799
Compare
c8640fb
to
6e8a308
Compare
402ba99
to
93950bf
Compare
93950bf
to
c77065e
Compare
@@ -103,8 +105,10 @@ class Tracer final : public opentelemetry::trace::Tracer, | |||
private: | |||
// order of declaration is important here - instrumentation scope should destroy after | |||
// tracer-context. | |||
std::unique_ptr<TracerConfig> tracer_config_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with:
TracerConfig tracer_config_;
There is no need to allocate memory and use a unique pointer, the tracer can own it's own configuration directly.
const std::shared_ptr<opentelemetry::trace::NoopTracer> Tracer::kNoopTracer = | ||
std::make_shared<opentelemetry::trace::NoopTracer>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a shared_ptr ?
This memory will never be reclaimed.
This should be enough:
opentelemetry::trace::NoopTracer kNoopTracer();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to avoid making multiple copies of NoopTracer, but looking at it again, shared_ptr might actually have more overhead due to ref counts.
/** | ||
* Returns a ScopeConfigurator that can be used to get the default tracer configurator. | ||
* A tracer configurator computes TracerConfig based on the InstrumentationScope. The default | ||
* tracer configurator unconditionally computes the default TracerConfig for all scopes. | ||
* | ||
* @return a static constant TracerConfig that represents a tracer configurator with default | ||
* behavior. | ||
*/ | ||
static const instrumentationscope::ScopeConfigurator<TracerConfig> &DefaultConfigurator(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To move in a separate class.
A TracerConfig represents a configuration.
This class should not know how / when / by whom a configuration is created, and should not even know of ScopeConfigurator.
bool disabled_; | ||
static const TracerConfig kDefaultConfig; | ||
static const TracerConfig kDisabledConfig; | ||
static const instrumentationscope::ScopeConfigurator<TracerConfig> kDefaultTracerConfigurator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove kDefaultTracerConfigurator.
template <class T> | ||
using ScopeConfigurator = std::function<T(const InstrumentationScope &)>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of comments.
(1)
ScopeConfigurator should be an abstract class, with a virtual configure() method.
This will help to define different kinds of configurators later, including the various builtins helpers.
(2)
One of the configurators is the always enabled one, so implement a AlwaysOnScopeConfigurator sub class.
Have a static AlwaysOnScopeConfigurator::Create() method, to return an instance.
(3)
Likewise, AlwaysOffScopeConfigurator::Create()
(4)
All this should be in dedicated headers, so instrumentation_scope.h should be unchanged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I had a class before, but removed since it was easily replaceable by a function. I was expecting to put the built-in helpers in a static utility class, but this approach might look better.
I will give this a try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the mean time, the spec configuration repository is defining the yaml bits for this:
Instead of "AlwaysOn" / "AlwaysOff", the following is probably better:
class ScopeConfigurator;
class DefaultScopeConfigurator : public ScopeConfigurator;
and later
class NamedScopeConfigurator : public ScopeConfigurator; (for name matching)
std::unique_ptr<instrumentationscope::ScopeConfigurator<TracerConfig>> tracer_configurator = | ||
std::make_unique<instrumentationscope::ScopeConfigurator<TracerConfig>>( | ||
TracerConfig::DefaultConfigurator())) noexcept; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with (assuming the default is enabled):
tracer_configurator = AlwaysOnScopeConfigurator::Create();
Likewise in other places.
@@ -77,6 +83,8 @@ class TracerContext | |||
*/ | |||
const opentelemetry::sdk::resource::Resource &GetResource() const noexcept; | |||
|
|||
instrumentationscope::ScopeConfigurator<TracerConfig> &GetTracerConfigurator() const noexcept; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type should probably be a const reference, not just a reference.
if (!tracer_config_->IsEnabled()) | ||
{ | ||
return kNoopTracer->StartSpan(name, attributes, links, options); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my understanding, this should be moved earlier, not done only for the SpanContext alternative.
If the tracer is disabled, it is disabled for all types of spans.
static const instrumentationscope::ScopeConfigurator<TracerConfig> &DefaultConfigurator(); | ||
|
||
private: | ||
explicit TracerConfig(const bool disabled = false) : disabled_(disabled) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use default values = false
.
The choice of the default value should not be nested deep in the code, but bubble up in the call stack, up to where the decision is made to use a default.
This will be in the tracer provider factory, when no scope configurator is provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a private constructor, so it cannot be called externally and the value of the default is dictated by the spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch.
This is a very good start, see comments to refine the structure around TracerConfig + ScopeConfigurator.
Thanks for the detailed review, I will go over the suggestions and make necessary changes. |
Re #2641
Adds scope configurator for Tracers.
Changes
Some optional, good-to-have convenience functions were recommended by the spec to accommodate common use-cases - these have not been added in this PR.
See the TracerConfigurator spec for these recommendations. They should be added in a future PR.
For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes