Skip to content

Commit

Permalink
Address comments in tracer: fix logic
Browse files Browse the repository at this point in the history
  • Loading branch information
psx95 committed Dec 4, 2024
1 parent 2f1ee38 commit 31c73a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion sdk/include/opentelemetry/sdk/trace/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ 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_;
std::shared_ptr<InstrumentationScope> instrumentation_scope_;
std::shared_ptr<TracerContext> context_;
TracerConfig tracer_config_;
static const std::shared_ptr<opentelemetry::trace::NoopTracer> kNoopTracer;
};
} // namespace trace
Expand Down
19 changes: 9 additions & 10 deletions sdk/src/trace/tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,24 @@ const std::shared_ptr<opentelemetry::trace::NoopTracer> Tracer::kNoopTracer =

Tracer::Tracer(std::shared_ptr<TracerContext> context,
std::unique_ptr<InstrumentationScope> instrumentation_scope) noexcept
: instrumentation_scope_{std::move(instrumentation_scope)}, context_{std::move(context)}
{
tracer_config_ =
std::make_unique<TracerConfig>(context_->GetTracerConfigurator()(*instrumentation_scope_));
}
: instrumentation_scope_{std::move(instrumentation_scope)},
context_{std::move(context)},
tracer_config_(context_->GetTracerConfigurator()(*instrumentation_scope_))
{}

nostd::shared_ptr<opentelemetry::trace::Span> Tracer::StartSpan(
nostd::string_view name,
const opentelemetry::common::KeyValueIterable &attributes,
const opentelemetry::trace::SpanContextKeyValueIterable &links,
const opentelemetry::trace::StartSpanOptions &options) noexcept
{
if (!tracer_config_.IsEnabled())
{
return kNoopTracer->StartSpan(name, attributes, links, options);
}
opentelemetry::trace::SpanContext parent_context = GetCurrentSpan()->GetContext();
if (nostd::holds_alternative<opentelemetry::trace::SpanContext>(options.parent))
{
if (!tracer_config_->IsEnabled())
{
return kNoopTracer->StartSpan(name, attributes, links, options);
}
auto span_context = nostd::get<opentelemetry::trace::SpanContext>(options.parent);
if (span_context.IsValid())
{
Expand Down Expand Up @@ -176,7 +175,7 @@ void Tracer::ForceFlushWithMicroseconds(uint64_t timeout) noexcept
void Tracer::CloseWithMicroseconds(uint64_t timeout) noexcept
{
// Trace context is shared by many tracers.So we just call ForceFlush to flush all pending spans
// and do not shutdown it.
// and do not shutdown it.
if (context_)
{
context_->ForceFlush(
Expand Down

0 comments on commit 31c73a3

Please sign in to comment.