Skip to content

Commit

Permalink
chore(otel): more general factory handling (#14372)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbolduc authored Jun 26, 2024
1 parent 42336db commit 37a1b7f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions google/cloud/opentelemetry/samples/samples.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,12 @@ void CustomTracerProvider(std::vector<std::string> const& argv) {
auto processor =
opentelemetry::sdk::trace::BatchSpanProcessorFactory::Create(
std::move(exporter), options);
auto provider = opentelemetry::sdk::trace::TracerProviderFactory::Create(
std::move(processor));

// Set the global trace provider
opentelemetry::trace::Provider::SetTracerProvider(std::move(provider));
// Create a tracer provider and set it as the global trace provider
opentelemetry::trace::Provider::SetTracerProvider(
std::shared_ptr<opentelemetry::trace::TracerProvider>(
opentelemetry::sdk::trace::TracerProviderFactory::Create(
std::move(processor))));

MyApplicationCode();

Expand Down
9 changes: 5 additions & 4 deletions google/cloud/testing_util/opentelemetry_matchers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <opentelemetry/trace/provider.h>

namespace {

void AttributeFormatter(
std::string* out,
std::pair<std::string const,
Expand Down Expand Up @@ -189,10 +190,10 @@ SpanCatcher::SpanCatcher()
auto processor =
std::make_unique<opentelemetry::sdk::trace::SimpleSpanProcessor>(
std::move(exporter));
std::shared_ptr<opentelemetry::trace::TracerProvider> provider =
opentelemetry::sdk::trace::TracerProviderFactory::Create(
std::move(processor));
opentelemetry::trace::Provider::SetTracerProvider(std::move(provider));
opentelemetry::trace::Provider::SetTracerProvider(
std::shared_ptr<opentelemetry::trace::TracerProvider>(
opentelemetry::sdk::trace::TracerProviderFactory::Create(
std::move(processor))));
}

SpanCatcher::~SpanCatcher() {
Expand Down

0 comments on commit 37a1b7f

Please sign in to comment.