diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/jaegertracing/opentelemetry-cpp/examples/jaeger | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/jaegertracing/opentelemetry-cpp/examples/jaeger')
4 files changed, 83 insertions, 0 deletions
diff --git a/src/jaegertracing/opentelemetry-cpp/examples/jaeger/BUILD b/src/jaegertracing/opentelemetry-cpp/examples/jaeger/BUILD new file mode 100644 index 000000000..23f42f93b --- /dev/null +++ b/src/jaegertracing/opentelemetry-cpp/examples/jaeger/BUILD @@ -0,0 +1,13 @@ +cc_binary( + name = "example_jaeger", + srcs = [ + "main.cc", + ], + tags = ["jaeger"], + deps = [ + "//api", + "//examples/common/foo_library:common_foo_library", + "//exporters/jaeger:opentelemetry_exporter_jaeger_trace", + "//sdk/src/trace", + ], +) diff --git a/src/jaegertracing/opentelemetry-cpp/examples/jaeger/CMakeLists.txt b/src/jaegertracing/opentelemetry-cpp/examples/jaeger/CMakeLists.txt new file mode 100644 index 000000000..713521c3a --- /dev/null +++ b/src/jaegertracing/opentelemetry-cpp/examples/jaeger/CMakeLists.txt @@ -0,0 +1,6 @@ +include_directories(${CMAKE_SOURCE_DIR}/exporters/jaeger/include) + +add_executable(example_jaeger main.cc) +target_link_libraries( + example_jaeger ${CMAKE_THREAD_LIBS_INIT} common_foo_library + opentelemetry_trace opentelemetry_exporter_jaeger_trace) diff --git a/src/jaegertracing/opentelemetry-cpp/examples/jaeger/README.md b/src/jaegertracing/opentelemetry-cpp/examples/jaeger/README.md new file mode 100644 index 000000000..42ac4e125 --- /dev/null +++ b/src/jaegertracing/opentelemetry-cpp/examples/jaeger/README.md @@ -0,0 +1,18 @@ +# Jaeger Exporter Example + +This is an example of how to use the Jaeger exporter. + +The application in `main.cc` initializes an `JaegerExporter` instance and uses it +to register 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 spans are exported to the Jaeger agent using the Jaeger exporter. + +Note that the Jaeger exporter connects to the agent at `localhost:6831` by +default. + +Once you have the Collector running, see +[CONTRIBUTING.md](../../CONTRIBUTING.md) for instructions on building and +running the example. diff --git a/src/jaegertracing/opentelemetry-cpp/examples/jaeger/main.cc b/src/jaegertracing/opentelemetry-cpp/examples/jaeger/main.cc new file mode 100644 index 000000000..d0f507fd4 --- /dev/null +++ b/src/jaegertracing/opentelemetry-cpp/examples/jaeger/main.cc @@ -0,0 +1,46 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/jaeger/jaeger_exporter.h" +#include "opentelemetry/sdk/trace/simple_processor.h" +#include "opentelemetry/sdk/trace/tracer_provider.h" +#include "opentelemetry/trace/provider.h" + +#ifdef BAZEL_BUILD +# include "examples/common/foo_library/foo_library.h" +#else +# include "foo_library/foo_library.h" +#endif + +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; +namespace trace_sdk = opentelemetry::sdk::trace; +namespace jaeger = opentelemetry::exporter::jaeger; + +namespace +{ +opentelemetry::exporter::jaeger::JaegerExporterOptions opts; +void InitTracer() +{ + // Create Jaeger exporter instance + auto exporter = std::unique_ptr<trace_sdk::SpanExporter>(new jaeger::JaegerExporter(opts)); + auto processor = std::unique_ptr<trace_sdk::SpanProcessor>( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); + auto provider = + nostd::shared_ptr<trace::TracerProvider>(new trace_sdk::TracerProvider(std::move(processor))); + // Set the global trace provider + trace::Provider::SetTracerProvider(provider); +} +} // namespace + +int main(int argc, char *argv[]) +{ + if (argc == 2) + { + opts.endpoint = argv[1]; + } + // Removing this line will leave the default noop TracerProvider in place. + InitTracer(); + + foo_library(); +} |