Skip to content

Commit 79c32f3

Browse files
committed
Infer trace_config from the context
1 parent a8a04e5 commit 79c32f3

File tree

4 files changed

+10
-24
lines changed

4 files changed

+10
-24
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ class Tracer final : public opentelemetry::trace::Tracer,
3737
/** Construct a new Tracer with the given context pipeline. */
3838
explicit Tracer(std::shared_ptr<TracerContext> context,
3939
std::unique_ptr<InstrumentationScope> instrumentation_scope =
40-
InstrumentationScope::Create(""),
41-
TracerConfig tracer_config = TracerConfig::Default()) noexcept;
40+
InstrumentationScope::Create("")) noexcept;
4241

4342
nostd::shared_ptr<opentelemetry::trace::Span> StartSpan(
4443
nostd::string_view name,
@@ -106,9 +105,9 @@ class Tracer final : public opentelemetry::trace::Tracer,
106105
private:
107106
// order of declaration is important here - instrumentation scope should destroy after
108107
// tracer-context.
108+
std::unique_ptr<TracerConfig> tracer_config_;
109109
std::shared_ptr<InstrumentationScope> instrumentation_scope_;
110110
std::shared_ptr<TracerContext> context_;
111-
TracerConfig tracer_config_;
112111
static const std::shared_ptr<opentelemetry::trace::NoopTracer> kNoopTracer;
113112
};
114113
} // namespace trace

sdk/include/opentelemetry/sdk/trace/tracer_provider.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ class OPENTELEMETRY_EXPORT TracerProvider final : public opentelemetry::trace::T
123123
std::vector<std::shared_ptr<Tracer>> tracers_;
124124
std::shared_ptr<TracerContext> context_;
125125
std::mutex lock_;
126-
127-
// private helper to get TracerConfig from InstrumentationScope using tracer configurator.
128-
TracerConfig GetTracerConfig(const InstrumentationScope &instrumentation_scope) const;
129126
};
130127
} // namespace trace
131128
} // namespace sdk

sdk/src/trace/tracer.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ const std::shared_ptr<opentelemetry::trace::NoopTracer> Tracer::kNoopTracer =
4141
std::make_shared<opentelemetry::trace::NoopTracer>();
4242

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

5151
nostd::shared_ptr<opentelemetry::trace::Span> Tracer::StartSpan(
5252
nostd::string_view name,
@@ -57,7 +57,7 @@ nostd::shared_ptr<opentelemetry::trace::Span> Tracer::StartSpan(
5757
opentelemetry::trace::SpanContext parent_context = GetCurrentSpan()->GetContext();
5858
if (nostd::holds_alternative<opentelemetry::trace::SpanContext>(options.parent))
5959
{
60-
if (!tracer_config_.IsEnabled())
60+
if (!tracer_config_->IsEnabled())
6161
{
6262
return kNoopTracer->StartSpan(name, attributes, links, options);
6363
}

sdk/src/trace/tracer_provider.cc

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,8 @@ nostd::shared_ptr<trace_api::Tracer> TracerProvider::GetTracer(
119119
instrumentationscope::InstrumentationScopeAttributes attrs_map(attributes);
120120
auto scope =
121121
instrumentationscope::InstrumentationScope::Create(name, version, schema_url, attrs_map);
122-
const instrumentationscope::InstrumentationScope &scope_reference =
123-
instrumentationscope::InstrumentationScope(*scope);
124122

125-
auto tracer = std::shared_ptr<Tracer>(
126-
new Tracer(context_, std::move(scope), GetTracerConfig(scope_reference)));
123+
auto tracer = std::shared_ptr<Tracer>(new Tracer(context_, std::move(scope)));
127124
tracers_.push_back(tracer);
128125
return nostd::shared_ptr<trace_api::Tracer>{tracer};
129126
}
@@ -147,13 +144,6 @@ bool TracerProvider::ForceFlush(std::chrono::microseconds timeout) noexcept
147144
{
148145
return context_->ForceFlush(timeout);
149146
}
150-
151-
TracerConfig TracerProvider::GetTracerConfig(
152-
const InstrumentationScope &instrumentation_scope) const
153-
{
154-
return context_->GetTracerConfigurator()(instrumentation_scope);
155-
}
156-
157147
} // namespace trace
158148
} // namespace sdk
159149
OPENTELEMETRY_END_NAMESPACE

0 commit comments

Comments
 (0)