diff options
Diffstat (limited to 'src/jaegertracing/opentelemetry-cpp/examples/simple/main.cc')
-rw-r--r-- | src/jaegertracing/opentelemetry-cpp/examples/simple/main.cc | 41 |
1 files changed, 41 insertions, 0 deletions
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(); +} |