diff options
Diffstat (limited to 'src/jaegertracing/opentelemetry-cpp/examples/simple')
4 files changed, 74 insertions, 0 deletions
diff --git a/src/jaegertracing/opentelemetry-cpp/examples/simple/BUILD b/src/jaegertracing/opentelemetry-cpp/examples/simple/BUILD new file mode 100644 index 000000000..6a5a76646 --- /dev/null +++ b/src/jaegertracing/opentelemetry-cpp/examples/simple/BUILD @@ -0,0 +1,15 @@ +cc_binary( + name = "example_simple", + srcs = [ + "main.cc", + ], + tags = [ + "examples", + "ostream", + ], + deps = [ + "//api", + "//examples/common/foo_library:common_foo_library", + "//exporters/ostream:ostream_span_exporter", + ], +) diff --git a/src/jaegertracing/opentelemetry-cpp/examples/simple/CMakeLists.txt b/src/jaegertracing/opentelemetry-cpp/examples/simple/CMakeLists.txt new file mode 100644 index 000000000..4368039c1 --- /dev/null +++ b/src/jaegertracing/opentelemetry-cpp/examples/simple/CMakeLists.txt @@ -0,0 +1,6 @@ +include_directories(${CMAKE_SOURCE_DIR}/exporters/ostream/include) + +add_executable(example_simple main.cc) +target_link_libraries( + example_simple ${CMAKE_THREAD_LIBS_INIT} common_foo_library + opentelemetry_trace opentelemetry_exporter_ostream_span) diff --git a/src/jaegertracing/opentelemetry-cpp/examples/simple/README.md b/src/jaegertracing/opentelemetry-cpp/examples/simple/README.md new file mode 100644 index 000000000..b3c449c53 --- /dev/null +++ b/src/jaegertracing/opentelemetry-cpp/examples/simple/README.md @@ -0,0 +1,12 @@ + +# Simple Trace Example + +In this example, the application in `main.cc` initializes and registers a tracer +provider from the [OpenTelemetry +SDK](https://github.com/open-telemetry/opentelemetry-cpp). The application then +calls a `foo_library` which has been instrumented using the [OpenTelemetry +API](https://github.com/open-telemetry/opentelemetry-cpp/tree/main/api). +Resulting telemetry is directed to stdout through the StdoutSpanExporter. + +See [CONTRIBUTING.md](../../CONTRIBUTING.md) for instructions on building and +running the example. diff --git a/src/jaegertracing/opentelemetry-cpp/examples/simple/main.cc b/src/jaegertracing/opentelemetry-cpp/examples/simple/main.cc new file mode 100644 index 000000000..d022e5c23 --- /dev/null +++ b/src/jaegertracing/opentelemetry-cpp/examples/simple/main.cc @@ -0,0 +1,41 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/trace/simple_processor.h" +#include "opentelemetry/sdk/trace/tracer_provider.h" +#include "opentelemetry/trace/provider.h" + +// Using an exporter that simply dumps span data to stdout. +#ifdef BAZEL_BUILD +# include "examples/common/foo_library/foo_library.h" +#else +# include "foo_library/foo_library.h" +#endif +#include "opentelemetry/exporters/ostream/span_exporter.h" + +namespace trace_api = opentelemetry::trace; +namespace trace_sdk = opentelemetry::sdk::trace; +namespace nostd = opentelemetry::nostd; +namespace +{ +void initTracer() +{ + auto exporter = std::unique_ptr<trace_sdk::SpanExporter>( + new opentelemetry::exporter::trace::OStreamSpanExporter); + auto processor = std::unique_ptr<trace_sdk::SpanProcessor>( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); + auto provider = nostd::shared_ptr<trace_api::TracerProvider>( + new trace_sdk::TracerProvider(std::move(processor))); + + // Set the global trace provider + trace_api::Provider::SetTracerProvider(provider); +} +} // namespace + +int main() +{ + // Removing this line will leave the default noop TracerProvider in place. + initTracer(); + + foo_library(); +} |