Skip to content

Commit

Permalink
[EXAMPLE] Clean the tracer initialization in OStream example (#3051)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomsonTan authored Sep 5, 2024
1 parent 261a151 commit d623bc5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions examples/logs_simple/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ void InitTracer()
auto exporter = trace_exporter::OStreamSpanExporterFactory::Create();
auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter));

std::shared_ptr<opentelemetry::sdk::trace::TracerProvider> provider =
opentelemetry::sdk::trace::TracerProviderFactory::Create(std::move(processor));
std::shared_ptr<opentelemetry::sdk::trace::TracerProvider> sdk_provider =
trace_sdk::TracerProviderFactory::Create(std::move(processor));

// Set the global trace provider
const std::shared_ptr<trace_api::TracerProvider> &api_provider = provider;
const std::shared_ptr<trace_api::TracerProvider> &api_provider = sdk_provider;
trace_api::Provider::SetTracerProvider(api_provider);
}

void CleanupTracer()
{
std::shared_ptr<trace_api::TracerProvider> none;
trace_api::Provider::SetTracerProvider(none);
std::shared_ptr<trace_api::TracerProvider> noop;
trace_api::Provider::SetTracerProvider(noop);
}

void InitLogger()
Expand All @@ -65,18 +65,18 @@ void InitLogger()
std::unique_ptr<logs_sdk::LogRecordExporter>(new logs_exporter::OStreamLogRecordExporter);
auto processor = logs_sdk::SimpleLogRecordProcessorFactory::Create(std::move(exporter));

std::shared_ptr<opentelemetry::sdk::logs::LoggerProvider> provider(
opentelemetry::sdk::logs::LoggerProviderFactory::Create(std::move(processor)));
std::shared_ptr<opentelemetry::sdk::logs::LoggerProvider> sdk_provider(
logs_sdk::LoggerProviderFactory::Create(std::move(processor)));

// Set the global logger provider
const std::shared_ptr<logs_api::LoggerProvider> &api_provider = provider;
const std::shared_ptr<logs_api::LoggerProvider> &api_provider = sdk_provider;
logs_api::Provider::SetLoggerProvider(api_provider);
}

void CleanupLogger()
{
std::shared_ptr<logs_api::LoggerProvider> none;
logs_api::Provider::SetLoggerProvider(none);
std::shared_ptr<logs_api::LoggerProvider> noop;
logs_api::Provider::SetLoggerProvider(noop);
}

} // namespace
Expand Down
10 changes: 5 additions & 5 deletions examples/simple/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ void InitTracer()
auto exporter = trace_exporter::OStreamSpanExporterFactory::Create();
auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter));

std::shared_ptr<opentelemetry::sdk::trace::TracerProvider> provider =
opentelemetry::sdk::trace::TracerProviderFactory::Create(std::move(processor));
std::shared_ptr<opentelemetry::sdk::trace::TracerProvider> sdk_provider =
trace_sdk::TracerProviderFactory::Create(std::move(processor));

// Set the global trace provider
const std::shared_ptr<opentelemetry::trace::TracerProvider> &api_provider = provider;
const std::shared_ptr<opentelemetry::trace::TracerProvider> &api_provider = sdk_provider;
trace_api::Provider::SetTracerProvider(api_provider);
}

void CleanupTracer()
{
std::shared_ptr<opentelemetry::trace::TracerProvider> none;
trace_api::Provider::SetTracerProvider(none);
std::shared_ptr<opentelemetry::trace::TracerProvider> noop;
trace_api::Provider::SetTracerProvider(noop);
}
} // namespace

Expand Down

0 comments on commit d623bc5

Please sign in to comment.