diff --git a/examples/batch/main.cc b/examples/batch/main.cc index bb19a4b8fa..2793694d49 100644 --- a/examples/batch/main.cc +++ b/examples/batch/main.cc @@ -39,7 +39,8 @@ void initTracer() auto processor = trace_sdk::BatchSpanProcessorFactory::Create(std::move(exporter), options); - auto provider = trace_sdk::TracerProviderFactory::Create(std::move(processor), resource); + std::shared_ptr provider = + trace_sdk::TracerProviderFactory::Create(std::move(processor), resource); // Set the global trace provider. trace_api::Provider::SetTracerProvider(provider); diff --git a/examples/grpc/tracer_common.h b/examples/grpc/tracer_common.h index 56dfd48161..c127664c90 100644 --- a/examples/grpc/tracer_common.h +++ b/examples/grpc/tracer_common.h @@ -8,7 +8,7 @@ #include "opentelemetry/exporters/ostream/span_exporter_factory.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" -#include "opentelemetry/sdk/trace/tracer_context.h" +#include "opentelemetry/sdk/trace/tracer_context_factory.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/propagation/http_trace_context.h" #include "opentelemetry/trace/provider.h" @@ -77,8 +77,10 @@ void initTracer() std::vector> processors; processors.push_back(std::move(processor)); // Default is an always-on sampler. - auto context = std::make_shared(std::move(processors)); - auto provider = opentelemetry::sdk::trace::TracerProviderFactory::Create(context); + std::shared_ptr context = + opentelemetry::sdk::trace::TracerContextFactory::Create(std::move(processors)); + std::shared_ptr provider = + opentelemetry::sdk::trace::TracerProviderFactory::Create(context); // Set the global trace provider opentelemetry::trace::Provider::SetTracerProvider(provider); diff --git a/examples/http/tracer_common.h b/examples/http/tracer_common.h index 1d0683de3f..a607f69293 100644 --- a/examples/http/tracer_common.h +++ b/examples/http/tracer_common.h @@ -2,8 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once + #include "opentelemetry/exporters/ostream/span_exporter_factory.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" +#include "opentelemetry/sdk/trace/tracer_context_factory.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" @@ -65,8 +67,10 @@ void initTracer() std::vector> processors; processors.push_back(std::move(processor)); // Default is an always-on sampler. - auto context = std::make_shared(std::move(processors)); - auto provider = opentelemetry::sdk::trace::TracerProviderFactory::Create(context); + std::shared_ptr context = + opentelemetry::sdk::trace::TracerContextFactory::Create(std::move(processors)); + std::shared_ptr provider = + opentelemetry::sdk::trace::TracerProviderFactory::Create(context); // Set the global trace provider opentelemetry::trace::Provider::SetTracerProvider(provider); diff --git a/examples/jaeger/main.cc b/examples/jaeger/main.cc index 4fcab89b7a..2756f4ce2c 100644 --- a/examples/jaeger/main.cc +++ b/examples/jaeger/main.cc @@ -25,7 +25,8 @@ void InitTracer() // Create Jaeger exporter instance auto exporter = jaeger::JaegerExporterFactory::Create(opts); auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); - auto provider = trace_sdk::TracerProviderFactory::Create(std::move(processor)); + std::shared_ptr provider = + trace_sdk::TracerProviderFactory::Create(std::move(processor)); // Set the global trace provider trace::Provider::SetTracerProvider(provider); } diff --git a/examples/multi_processor/main.cc b/examples/multi_processor/main.cc index 501e169bf8..86686daa79 100644 --- a/examples/multi_processor/main.cc +++ b/examples/multi_processor/main.cc @@ -35,7 +35,8 @@ std::shared_ptr initTracer() std::vector> processors; processors.push_back(std::move(processor1)); processors.push_back(std::move(processor2)); - auto provider = trace_sdk::TracerProviderFactory::Create(std::move(processors)); + std::shared_ptr provider = + trace_sdk::TracerProviderFactory::Create(std::move(processors)); // Set the global trace provider trace_api::Provider::SetTracerProvider(std::move(provider)); diff --git a/examples/multithreaded/main.cc b/examples/multithreaded/main.cc index 1e3de50d3d..bb6020bf58 100644 --- a/examples/multithreaded/main.cc +++ b/examples/multithreaded/main.cc @@ -21,8 +21,9 @@ void initTracer() { auto exporter = opentelemetry::exporter::trace::OStreamSpanExporterFactory::Create(); auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); - auto provider = trace_sdk::TracerProviderFactory::Create( - std::move(processor), opentelemetry::sdk::resource::Resource::Create({})); + std::shared_ptr provider = + trace_sdk::TracerProviderFactory::Create(std::move(processor), + opentelemetry::sdk::resource::Resource::Create({})); // Set the global trace provider trace_api::Provider::SetTracerProvider(provider); } diff --git a/examples/otlp/grpc_log_main.cc b/examples/otlp/grpc_log_main.cc index c8d4a2c0c3..980b18e50a 100644 --- a/examples/otlp/grpc_log_main.cc +++ b/examples/otlp/grpc_log_main.cc @@ -38,7 +38,8 @@ void InitTracer() // Create OTLP exporter instance auto exporter = otlp::OtlpGrpcExporterFactory::Create(opts); auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); - auto provider = trace_sdk::TracerProviderFactory::Create(std::move(processor)); + std::shared_ptr provider = + trace_sdk::TracerProviderFactory::Create(std::move(processor)); // Set the global trace provider trace::Provider::SetTracerProvider(provider); } diff --git a/examples/otlp/grpc_main.cc b/examples/otlp/grpc_main.cc index e9d7ed146e..7d3dd3e4a8 100644 --- a/examples/otlp/grpc_main.cc +++ b/examples/otlp/grpc_main.cc @@ -25,7 +25,8 @@ void InitTracer() // Create OTLP exporter instance auto exporter = otlp::OtlpGrpcExporterFactory::Create(opts); auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); - auto provider = trace_sdk::TracerProviderFactory::Create(std::move(processor)); + std::shared_ptr provider = + trace_sdk::TracerProviderFactory::Create(std::move(processor)); // Set the global trace provider trace::Provider::SetTracerProvider(provider); } diff --git a/examples/otlp/http_log_main.cc b/examples/otlp/http_log_main.cc index 97ec887673..1789f542da 100644 --- a/examples/otlp/http_log_main.cc +++ b/examples/otlp/http_log_main.cc @@ -35,7 +35,8 @@ void InitTracer() // Create OTLP exporter instance auto exporter = otlp::OtlpHttpExporterFactory::Create(opts); auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); - auto provider = trace_sdk::TracerProviderFactory::Create(std::move(processor)); + std::shared_ptr provider = + trace_sdk::TracerProviderFactory::Create(std::move(processor)); // Set the global trace provider trace::Provider::SetTracerProvider(provider); } diff --git a/examples/otlp/http_main.cc b/examples/otlp/http_main.cc index 2e235549ba..8257429d89 100644 --- a/examples/otlp/http_main.cc +++ b/examples/otlp/http_main.cc @@ -28,7 +28,8 @@ void InitTracer() // Create OTLP exporter instance auto exporter = otlp::OtlpHttpExporterFactory::Create(opts); auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); - auto provider = trace_sdk::TracerProviderFactory::Create(std::move(processor)); + std::shared_ptr provider = + trace_sdk::TracerProviderFactory::Create(std::move(processor)); // Set the global trace provider trace::Provider::SetTracerProvider(provider); } diff --git a/examples/simple/main.cc b/examples/simple/main.cc index 5130e9cee6..dc630f47d9 100644 --- a/examples/simple/main.cc +++ b/examples/simple/main.cc @@ -22,7 +22,8 @@ void initTracer() { auto exporter = trace_exporter::OStreamSpanExporterFactory::Create(); auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); - auto provider = trace_sdk::TracerProviderFactory::Create(std::move(processor)); + std::shared_ptr provider = + trace_sdk::TracerProviderFactory::Create(std::move(processor)); // Set the global trace provider trace_api::Provider::SetTracerProvider(provider); diff --git a/examples/zipkin/main.cc b/examples/zipkin/main.cc index 30e045f2ce..e916cdf4f8 100644 --- a/examples/zipkin/main.cc +++ b/examples/zipkin/main.cc @@ -28,7 +28,8 @@ void InitTracer() auto resource = resource::Resource::Create(attributes); auto exporter = zipkin::ZipkinExporterFactory::Create(opts); auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); - auto provider = trace_sdk::TracerProviderFactory::Create(std::move(processor), resource); + std::shared_ptr provider = + trace_sdk::TracerProviderFactory::Create(std::move(processor), resource); // Set the global trace provider trace::Provider::SetTracerProvider(provider); } diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h b/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h index 88cc6be0b1..b13d3fffb3 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h @@ -23,20 +23,20 @@ class TracerContextFactory /** * Create a TracerContext. */ - static std::shared_ptr Create( + static std::unique_ptr Create( std::vector> &&processor); /** * Create a TracerContext. */ - static std::shared_ptr Create( + static std::unique_ptr Create( std::vector> &&processor, opentelemetry::sdk::resource::Resource resource); /** * Create a TracerContext. */ - static std::shared_ptr Create( + static std::unique_ptr Create( std::vector> &&processor, opentelemetry::sdk::resource::Resource resource, std::unique_ptr sampler); @@ -44,7 +44,7 @@ class TracerContextFactory /** * Create a TracerContext. */ - static std::shared_ptr Create( + static std::unique_ptr Create( std::vector> &&processor, opentelemetry::sdk::resource::Resource resource, std::unique_ptr sampler, diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h b/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h index 20ce9a3f50..38cf3951cc 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h @@ -24,19 +24,19 @@ class TracerProviderFactory public: /* Serie of builders with a single processor. */ - static std::shared_ptr Create( + static std::unique_ptr Create( std::unique_ptr processor); - static std::shared_ptr Create( + static std::unique_ptr Create( std::unique_ptr processor, opentelemetry::sdk::resource::Resource resource); - static std::shared_ptr Create( + static std::unique_ptr Create( std::unique_ptr processor, opentelemetry::sdk::resource::Resource resource, std::unique_ptr sampler); - static std::shared_ptr Create( + static std::unique_ptr Create( std::unique_ptr processor, opentelemetry::sdk::resource::Resource resource, std::unique_ptr sampler, @@ -44,19 +44,19 @@ class TracerProviderFactory /* Serie of builders with a vector of processor. */ - static std::shared_ptr Create( + static std::unique_ptr Create( std::vector> &&processors); - static std::shared_ptr Create( + static std::unique_ptr Create( std::vector> &&processors, opentelemetry::sdk::resource::Resource resource); - static std::shared_ptr Create( + static std::unique_ptr Create( std::vector> &&processors, opentelemetry::sdk::resource::Resource resource, std::unique_ptr sampler); - static std::shared_ptr Create( + static std::unique_ptr Create( std::vector> &&processors, opentelemetry::sdk::resource::Resource resource, std::unique_ptr sampler, @@ -64,7 +64,7 @@ class TracerProviderFactory /* Create with a tracer context. */ - static std::shared_ptr Create( + static std::unique_ptr Create( std::shared_ptr context); }; diff --git a/sdk/src/trace/tracer_context_factory.cc b/sdk/src/trace/tracer_context_factory.cc index 942f4b2b74..1e8d4cc1c0 100644 --- a/sdk/src/trace/tracer_context_factory.cc +++ b/sdk/src/trace/tracer_context_factory.cc @@ -13,14 +13,14 @@ namespace sdk namespace trace { -std::shared_ptr TracerContextFactory::Create( +std::unique_ptr TracerContextFactory::Create( std::vector> &&processor) { auto resource = opentelemetry::sdk::resource::Resource::Create({}); return Create(std::move(processor), resource); } -std::shared_ptr TracerContextFactory::Create( +std::unique_ptr TracerContextFactory::Create( std::vector> &&processor, opentelemetry::sdk::resource::Resource resource) { @@ -28,7 +28,7 @@ std::shared_ptr TracerContextFactory::Create( return Create(std::move(processor), resource, std::move(sampler)); } -std::shared_ptr TracerContextFactory::Create( +std::unique_ptr TracerContextFactory::Create( std::vector> &&processor, opentelemetry::sdk::resource::Resource resource, std::unique_ptr sampler) @@ -37,13 +37,13 @@ std::shared_ptr TracerContextFactory::Create( return Create(std::move(processor), resource, std::move(sampler), std::move(id_generator)); } -std::shared_ptr TracerContextFactory::Create( +std::unique_ptr TracerContextFactory::Create( std::vector> &&processor, opentelemetry::sdk::resource::Resource resource, std::unique_ptr sampler, std::unique_ptr id_generator) { - std::shared_ptr context(new TracerContext( + std::unique_ptr context(new TracerContext( std::move(processor), resource, std::move(sampler), std::move(id_generator))); return context; } diff --git a/sdk/src/trace/tracer_provider_factory.cc b/sdk/src/trace/tracer_provider_factory.cc index 8d2eb36158..e03187fa6b 100644 --- a/sdk/src/trace/tracer_provider_factory.cc +++ b/sdk/src/trace/tracer_provider_factory.cc @@ -15,14 +15,14 @@ namespace sdk namespace trace { -std::shared_ptr TracerProviderFactory::Create( +std::unique_ptr TracerProviderFactory::Create( std::unique_ptr processor) { auto resource = opentelemetry::sdk::resource::Resource::Create({}); return Create(std::move(processor), resource); } -std::shared_ptr TracerProviderFactory::Create( +std::unique_ptr TracerProviderFactory::Create( std::unique_ptr processor, opentelemetry::sdk::resource::Resource resource) { @@ -30,7 +30,7 @@ std::shared_ptr TracerProviderFactory::Create( return Create(std::move(processor), resource, std::move(sampler)); } -std::shared_ptr TracerProviderFactory::Create( +std::unique_ptr TracerProviderFactory::Create( std::unique_ptr processor, opentelemetry::sdk::resource::Resource resource, std::unique_ptr sampler) @@ -39,25 +39,25 @@ std::shared_ptr TracerProviderFactory::Cre return Create(std::move(processor), resource, std::move(sampler), std::move(id_generator)); } -std::shared_ptr TracerProviderFactory::Create( +std::unique_ptr TracerProviderFactory::Create( std::unique_ptr processor, opentelemetry::sdk::resource::Resource resource, std::unique_ptr sampler, std::unique_ptr id_generator) { - std::shared_ptr provider(new trace_sdk::TracerProvider( + std::unique_ptr provider(new trace_sdk::TracerProvider( std::move(processor), resource, std::move(sampler), std::move(id_generator))); return provider; } -std::shared_ptr TracerProviderFactory::Create( +std::unique_ptr TracerProviderFactory::Create( std::vector> &&processors) { auto resource = opentelemetry::sdk::resource::Resource::Create({}); return Create(std::move(processors), resource); } -std::shared_ptr TracerProviderFactory::Create( +std::unique_ptr TracerProviderFactory::Create( std::vector> &&processors, opentelemetry::sdk::resource::Resource resource) { @@ -65,7 +65,7 @@ std::shared_ptr TracerProviderFactory::Cre return Create(std::move(processors), resource, std::move(sampler)); } -std::shared_ptr TracerProviderFactory::Create( +std::unique_ptr TracerProviderFactory::Create( std::vector> &&processors, opentelemetry::sdk::resource::Resource resource, std::unique_ptr sampler) @@ -74,21 +74,21 @@ std::shared_ptr TracerProviderFactory::Cre return Create(std::move(processors), resource, std::move(sampler), std::move(id_generator)); } -std::shared_ptr TracerProviderFactory::Create( +std::unique_ptr TracerProviderFactory::Create( std::vector> &&processors, opentelemetry::sdk::resource::Resource resource, std::unique_ptr sampler, std::unique_ptr id_generator) { - std::shared_ptr provider(new trace_sdk::TracerProvider( + std::unique_ptr provider(new trace_sdk::TracerProvider( std::move(processors), resource, std::move(sampler), std::move(id_generator))); return provider; } -std::shared_ptr TracerProviderFactory::Create( +std::unique_ptr TracerProviderFactory::Create( std::shared_ptr context) { - std::shared_ptr provider(new trace_sdk::TracerProvider(context)); + std::unique_ptr provider(new trace_sdk::TracerProvider(context)); return provider; }