-
Notifications
You must be signed in to change notification settings - Fork 11
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
TraceSegment can outlive Tracer #89
TraceSegment can outlive Tracer #89
Conversation
It looks like there's a typo at the beginning, and I couldn't think of a good way to describe `client_id` concisely, so probably best to omit the comment.
@@ -36,6 +36,7 @@ Tracer::Tracer(const FinalizedTracerConfig& config) | |||
Tracer::Tracer(const FinalizedTracerConfig& config, | |||
const std::shared_ptr<const IDGenerator>& generator) | |||
: logger_(config.logger), | |||
config_manager_(std::make_shared<ConfigManager>(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.
I moved this up so that it occurs before collector_
. This is not at all necessary, since we're talking about shared pointers, but it mirrors what we would do if the collector and the config manager were both held by value.
BenchmarksBenchmark execution time: 2024-01-12 20:07:58 Comparing candidate commit 8de1e1c in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics. |
@@ -44,15 +45,16 @@ class RemoteConfigurationManager { | |||
}; | |||
|
|||
TracerSignature tracer_signature_; | |||
ConfigManager& config_manager_; | |||
std::string client_id_; ///< Identifier a `RemoteConfigurationManager` |
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.
?
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 figured the comment contained a typo:
///< Identifier a `RemoteConfigurationManager`
I'm not sure what the extra /<
is doing, and "Identifier" should probably be "Identifies".
Ok, suppose the comment is "Identifies a RemoteConfigurationManager
." True enough, but that doesn't really help me understand what client_id_
is or is for. So, I thought about how best to describe client_id_
in a comment. I didn't think of anything that was better than nothing, so I went with nothing.
@@ -10,6 +10,9 @@ | |||
// obtained from a `TracerConfig` via the `finalize_config` function. See | |||
// `tracer_config.h`. | |||
|
|||
#include <cstddef> |
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.
no need
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.
Since we use std::size_t
explicitly, I figured to include a header for it. Could include string
as well, but I didn't notice that one.
Thanks for the review. I'll log off after this merge. It's a USA holiday today :D |
I was integrating the recent sampling delegation changes into the corresponding feature branch in nginx-datadog, and got some compiler errors. They're due to other changes on the dd-trace-cpp main branch.
In nginx-datadog, and in Envoy, the
Tracer
is stored as anOptional<Tracer>
. ATracer
instance is then moved into the variable.Since
Tracer
now has aConfigManager
data member, andConfigManager
has astd::mutex
data member,Tracer
can no longer be moved (becausestd::mutex
cannot be moved).One thing I could do is use
Optional::emplace
to construct theTracer
in place: no move required.Another thing I could do is make the
Tracer
'sConfigManager
astd::unique_ptr
, so that move semantics are preserved.Yet another thing I could do is use a
std::unique_ptr
in nginx-datadog and Envoy, so that theTracer
itself does not have to be moved.So, I went about thinking about this. Then, looking at the dd-trace-cpp code, I noticed something.
Tracer
hasConfigManager
data member. A reference (pointer) to theConfigManager
is then passed into theDatadogAgent
, which is held byshared_ptr
inTracer
. TheDatadogAgent
has aRemoteConfigurationManager
data member, which holds a reference (pointer) to theConfigManager
.My initial design of dd-trace-cpp was such that a
TraceSegment
could safely outlive theTracer
that created it. The idea was that an application might have aTracer
that gets reassigned when reconfiguration occurs, and this would not affect any traces in flight.The recent remote configuration changes violate this property, because the lifetime of the
ConfigManager
is limited to the lifetime of theTracer
that holds it, even though theConfigManager
is referred to by objects that can outlive theTracer
.This pull request makes the
Tracer
'sConfigManager
astd::shared_ptr
, and passes it as ashared_ptr
throughDatadogAgent
and intoRemoteConfigurationManager
. This way, even if theTracer
is destroyed, theRemoteConfigurationManager
still has a valid handle to theConfigManager
.