Skip to content

Commit db05adc

Browse files
committed
Address comments in tracer: replace use of shared_ptr & fix logic
1 parent 2f1ee38 commit db05adc

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

sdk/include/opentelemetry/sdk/trace/tracer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ class Tracer final : public opentelemetry::trace::Tracer,
105105
private:
106106
// order of declaration is important here - instrumentation scope should destroy after
107107
// tracer-context.
108-
std::unique_ptr<TracerConfig> tracer_config_;
109108
std::shared_ptr<InstrumentationScope> instrumentation_scope_;
110109
std::shared_ptr<TracerContext> context_;
111-
static const std::shared_ptr<opentelemetry::trace::NoopTracer> kNoopTracer;
110+
TracerConfig tracer_config_;
111+
static opentelemetry::trace::NoopTracer kNoopTracer;
112112
};
113113
} // namespace trace
114114
} // namespace sdk

sdk/src/trace/tracer.cc

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,28 @@ namespace sdk
3838
{
3939
namespace trace
4040
{
41-
const std::shared_ptr<opentelemetry::trace::NoopTracer> Tracer::kNoopTracer =
42-
std::make_shared<opentelemetry::trace::NoopTracer>();
41+
opentelemetry::trace::NoopTracer Tracer::kNoopTracer = opentelemetry::trace::NoopTracer();
4342

4443
Tracer::Tracer(std::shared_ptr<TracerContext> context,
4544
std::unique_ptr<InstrumentationScope> instrumentation_scope) noexcept
46-
: instrumentation_scope_{std::move(instrumentation_scope)}, context_{std::move(context)}
47-
{
48-
tracer_config_ =
49-
std::make_unique<TracerConfig>(context_->GetTracerConfigurator()(*instrumentation_scope_));
50-
}
45+
: instrumentation_scope_{std::move(instrumentation_scope)},
46+
context_{std::move(context)},
47+
tracer_config_(context_->GetTracerConfigurator()(*instrumentation_scope_))
48+
{}
5149

5250
nostd::shared_ptr<opentelemetry::trace::Span> Tracer::StartSpan(
5351
nostd::string_view name,
5452
const opentelemetry::common::KeyValueIterable &attributes,
5553
const opentelemetry::trace::SpanContextKeyValueIterable &links,
5654
const opentelemetry::trace::StartSpanOptions &options) noexcept
5755
{
56+
if (!tracer_config_.IsEnabled())
57+
{
58+
return kNoopTracer.StartSpan(name, attributes, links, options);
59+
}
5860
opentelemetry::trace::SpanContext parent_context = GetCurrentSpan()->GetContext();
5961
if (nostd::holds_alternative<opentelemetry::trace::SpanContext>(options.parent))
6062
{
61-
if (!tracer_config_->IsEnabled())
62-
{
63-
return kNoopTracer->StartSpan(name, attributes, links, options);
64-
}
6563
auto span_context = nostd::get<opentelemetry::trace::SpanContext>(options.parent);
6664
if (span_context.IsValid())
6765
{
@@ -176,7 +174,7 @@ void Tracer::ForceFlushWithMicroseconds(uint64_t timeout) noexcept
176174
void Tracer::CloseWithMicroseconds(uint64_t timeout) noexcept
177175
{
178176
// Trace context is shared by many tracers.So we just call ForceFlush to flush all pending spans
179-
// and do not shutdown it.
177+
// and do not shutdown it.
180178
if (context_)
181179
{
182180
context_->ForceFlush(

0 commit comments

Comments
 (0)