diff --git a/pubsub-open-telemetry/CMakeLists.txt b/pubsub-open-telemetry/CMakeLists.txt index ad6bb47..207b1b0 100644 --- a/pubsub-open-telemetry/CMakeLists.txt +++ b/pubsub-open-telemetry/CMakeLists.txt @@ -43,7 +43,10 @@ target_link_libraries(publisher PRIVATE publisher_helper parse_args) add_executable(publisher_zipkin publisher_zipkin.cc) target_compile_features(publisher_zipkin PRIVATE cxx_std_14) -target_link_libraries(publisher_zipkin PRIVATE publisher_helper parse_args opentelemetry-cpp::opentelemetry_exporter_zipkin_trace) +target_link_libraries( + publisher_zipkin + PRIVATE publisher_helper parse_args + opentelemetry-cpp::opentelemetry_exporter_zipkin_trace) add_executable(quickstart quickstart.cc) target_compile_features(quickstart PRIVATE cxx_std_14) diff --git a/pubsub-open-telemetry/publisher.md b/pubsub-open-telemetry/publisher.md index ddc5536..d0a1a6c 100644 --- a/pubsub-open-telemetry/publisher.md +++ b/pubsub-open-telemetry/publisher.md @@ -82,11 +82,13 @@ If you do not already, have one create a local Zipkin instance. #### (optional) Create a local Zipkin instance. To run Zipkin on the host `http://localhost:9411` + ```shell docker run -d -p 9411:9411 openzipkin/zipkin ``` To kill the instance + ```shell docker container ls docker rm -f openzipkin/zipkin @@ -104,6 +106,7 @@ docker rm -f openzipkin/zipkin ## Build and run ### Using CMake and Vcpkg + #### Run the publisher with Zipkin ```sh @@ -113,6 +116,7 @@ cmake --build .build ``` #### Run basic publisher examples + ```shell .build/publisher_zipkin [project-name] [topic-id] .build/publisher_zipkin [project-name] [topic-id] -n 1000 diff --git a/pubsub-open-telemetry/publisher_zipkin.cc b/pubsub-open-telemetry/publisher_zipkin.cc index 10a46e9..6a52607 100644 --- a/pubsub-open-telemetry/publisher_zipkin.cc +++ b/pubsub-open-telemetry/publisher_zipkin.cc @@ -12,8 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "google/cloud/pubsub/publisher.h" #include "google/cloud/opentelemetry/trace_exporter.h" +#include "google/cloud/pubsub/publisher.h" +#include "opentelemetry/exporters/zipkin/zipkin_exporter_factory.h" +#include "opentelemetry/exporters/zipkin/zipkin_exporter_options.h" #include "parse_args.h" #include "publisher_helper.h" #include @@ -21,8 +23,6 @@ #include #include #include -#include "opentelemetry/exporters/zipkin/zipkin_exporter_factory.h" -#include "opentelemetry/exporters/zipkin/zipkin_exporter_options.h" #include // Create a few namespace aliases to make the code easier to read. @@ -32,18 +32,18 @@ namespace trace_sdk = ::opentelemetry::sdk::trace; namespace trace = ::opentelemetry::trace; namespace zipkin = opentelemetry::exporter::zipkin; -void ConfigureZipkinTracer(ParseResult const& args) { +void ConfigureZipkinTracer(ParseResult const& args) { auto exporter = zipkin::ZipkinExporterFactory::Create(); trace_sdk::BatchSpanProcessorOptions span_options; span_options.max_queue_size = args.max_queue_size; auto processor = trace_sdk::BatchSpanProcessorFactory::Create( std::move(exporter), span_options); - auto provider = trace_sdk::TracerProviderFactory::Create( - std::move(processor)); + auto provider = + trace_sdk::TracerProviderFactory::Create(std::move(processor)); - trace::Provider::SetTracerProvider(std::move(provider)); -} + trace::Provider::SetTracerProvider(std::move(provider)); +} int main(int argc, char* argv[]) try { auto args = ParseArguments(argc, argv);