Skip to content

Commit

Permalink
Merge branch 'main' into rename-jaeger-target
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Jul 22, 2021
2 parents 474a38a + 083cf02 commit 42f6973
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
6 changes: 5 additions & 1 deletion examples/batch/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ void initTracer()
// We export `kNumSpans` after every `schedule_delay_millis` milliseconds.
options.max_export_batch_size = kNumSpans;

opentelemetry::sdk::resource::ResourceAttributes attributes = {{"service", "test_service"},
{"version", (uint32_t)1}};
auto resource = opentelemetry::sdk::resource::Resource::Create(attributes);

auto processor = std::unique_ptr<sdktrace::SpanProcessor>(
new sdktrace::BatchSpanProcessor(std::move(exporter), options));

auto provider = nostd::shared_ptr<opentelemetry::trace::TracerProvider>(
new sdktrace::TracerProvider(std::move(processor)));
new sdktrace::TracerProvider(std::move(processor), resource));
// Set the global trace provider.
opentelemetry::trace::Provider::SetTracerProvider(provider);
}
Expand Down
4 changes: 3 additions & 1 deletion sdk/include/opentelemetry/sdk/trace/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ class Tracer final : public trace_api::Tracer, public std::enable_shared_from_th
Sampler &GetSampler() { return context_->GetSampler(); }

private:
std::shared_ptr<sdk::trace::TracerContext> context_;
// order of declaration is important here - instrumentation library should destroy after
// tracer-context.
std::shared_ptr<InstrumentationLibrary> instrumentation_library_;
std::shared_ptr<sdk::trace::TracerContext> context_;
};
} // namespace trace
} // namespace sdk
Expand Down
4 changes: 2 additions & 2 deletions sdk/include/opentelemetry/sdk/trace/tracer_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ class TracerContext
bool Shutdown() noexcept;

private:
// This is an atomic pointer so we can adapt the processor pipeline dynamically.
std::unique_ptr<SpanProcessor> processor_;
// order of declaration is important here - resource object should be destroyed after processor.
opentelemetry::sdk::resource::Resource resource_;
std::unique_ptr<Sampler> sampler_;
std::unique_ptr<IdGenerator> id_generator_;
std::unique_ptr<SpanProcessor> processor_;
};

} // namespace trace
Expand Down
3 changes: 2 additions & 1 deletion sdk/include/opentelemetry/sdk/trace/tracer_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ class TracerProvider final : public opentelemetry::trace::TracerProvider
bool ForceFlush(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept;

private:
std::shared_ptr<sdk::trace::TracerContext> context_;
// order of declaration is important here - tracers should destroy only after context.
std::vector<std::shared_ptr<opentelemetry::sdk::trace::Tracer>> tracers_;
std::shared_ptr<sdk::trace::TracerContext> context_;
std::mutex lock_;
};
} // namespace trace
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/trace/tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace trace

Tracer::Tracer(std::shared_ptr<sdk::trace::TracerContext> context,
std::unique_ptr<InstrumentationLibrary> instrumentation_library) noexcept
: context_{context}, instrumentation_library_{std::move(instrumentation_library)}
: instrumentation_library_{std::move(instrumentation_library)}, context_{context}
{}

nostd::shared_ptr<trace_api::Span> Tracer::StartSpan(
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/trace/tracer_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ TracerContext::TracerContext(std::vector<std::unique_ptr<SpanProcessor>> &&proce
opentelemetry::sdk::resource::Resource resource,
std::unique_ptr<Sampler> sampler,
std::unique_ptr<IdGenerator> id_generator) noexcept
: processor_(std::unique_ptr<SpanProcessor>(new MultiSpanProcessor(std::move(processors)))),
resource_(resource),
: resource_(resource),
sampler_(std::move(sampler)),
id_generator_(std::move(id_generator))
id_generator_(std::move(id_generator)),
processor_(std::unique_ptr<SpanProcessor>(new MultiSpanProcessor(std::move(processors))))
{}

Sampler &TracerContext::GetSampler() const noexcept
Expand Down

0 comments on commit 42f6973

Please sign in to comment.