Skip to content

Commit

Permalink
Merge pull request #68 from open-telemetry/main
Browse files Browse the repository at this point in the history
[EXAMPLE] Clean the tracer initialization in OStream example (open-telemetry#3051)
  • Loading branch information
malkia authored Sep 6, 2024
2 parents c2db0bf + d623bc5 commit c3da8a2
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 @@ -40,18 +40,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 @@ -61,18 +61,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 @@ -28,18 +28,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 c3da8a2

Please sign in to comment.