From 1ef843084143267709ea3122d5d8f475481be499 Mon Sep 17 00:00:00 2001 From: Johannes Tax Date: Fri, 15 May 2020 15:51:11 -0700 Subject: [PATCH 01/12] Add a simple example for the tracer workflow --- examples/simple/library.cc | 30 ++++++++++++++++++ .../sdk/common/.atomic_shared_ptr.h.swp | Bin 0 -> 12288 bytes 2 files changed, 30 insertions(+) create mode 100644 examples/simple/library.cc create mode 100644 sdk/include/opentelemetry/sdk/common/.atomic_shared_ptr.h.swp diff --git a/examples/simple/library.cc b/examples/simple/library.cc new file mode 100644 index 0000000000..ce33c6aba9 --- /dev/null +++ b/examples/simple/library.cc @@ -0,0 +1,30 @@ +#include "opentelemetry/trace/provider.h" + +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; + +static nostd::shared_ptr get_tracer() +{ + auto provider = trace::Provider::GetTracerProvider(); + return provider->GetTracer(""); +} + +static void f1() +{ + auto span = get_tracer()->StartSpan("f1"); +} + +static void f2() +{ + auto span = get_tracer()->StartSpan("f2"); + + f1(); + f1(); +} + +void library() +{ + auto span = get_tracer()->StartSpan("library"); + + f2(); +} diff --git a/sdk/include/opentelemetry/sdk/common/.atomic_shared_ptr.h.swp b/sdk/include/opentelemetry/sdk/common/.atomic_shared_ptr.h.swp new file mode 100644 index 0000000000000000000000000000000000000000..6e9379499e2d743a5e4e95e67f3fab21a16a5a05 GIT binary patch literal 12288 zcmeI&O>fgM7zglY+u$SD;zb%Pph`4Uuni$3BG++SL*rPsJ3tfSjQ9i` z_y(M~z;}U90Vi%eEt{Z|2ItYgrN5%YPZH;MOY-#Fd!4S>Y^@QG3q+4Ues~g>FH%xO z`)U}JOVgRZ4qdwxY`@u`#AL$BrLt05?nV=$e45k?>7N@}d*hNBo64l{vZ=k7v3w@2 z)8k2bY<4!I>#C}qRH?44F5*Z9Qx-mj*68H>Vg>>WFEB}i=H^-2SYK;TEmj&=#PX%x zg=YZ(1Rwwb2tWV=5P$##7D*uaC3?*deCF_>`4hlwEFIe(?qUN02tWV=5P$##AOHaf zKmY;|fWRpfP$kj(b3{Kl)BpcR@BiP=6Mf@+<$U3M=6vG3sCgu zgpg7=Rhj6OHiBEyX~nqG4oL8rMC*p)wjG;o6LqjY)j?br)}^alHjd^WRot##OiS&c zGy_pQ?BpBkbU^d>n_u6}>`o{DV}*S3uNHaHnCqaI``le`Yu6ezxX1UX=GyN*`5S!L M2Q{pesGTPx# literal 0 HcmV?d00001 From 4d948919e3cc06ac1934f548d554529cadfcaa9d Mon Sep 17 00:00:00 2001 From: Johannes Tax Date: Fri, 15 May 2020 15:59:49 -0700 Subject: [PATCH 02/12] Remove obsolete file --- .../sdk/common/.atomic_shared_ptr.h.swp | Bin 12288 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 sdk/include/opentelemetry/sdk/common/.atomic_shared_ptr.h.swp diff --git a/sdk/include/opentelemetry/sdk/common/.atomic_shared_ptr.h.swp b/sdk/include/opentelemetry/sdk/common/.atomic_shared_ptr.h.swp deleted file mode 100644 index 6e9379499e2d743a5e4e95e67f3fab21a16a5a05..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI&O>fgM7zglY+u$SD;zb%Pph`4Uuni$3BG++SL*rPsJ3tfSjQ9i` z_y(M~z;}U90Vi%eEt{Z|2ItYgrN5%YPZH;MOY-#Fd!4S>Y^@QG3q+4Ues~g>FH%xO z`)U}JOVgRZ4qdwxY`@u`#AL$BrLt05?nV=$e45k?>7N@}d*hNBo64l{vZ=k7v3w@2 z)8k2bY<4!I>#C}qRH?44F5*Z9Qx-mj*68H>Vg>>WFEB}i=H^-2SYK;TEmj&=#PX%x zg=YZ(1Rwwb2tWV=5P$##7D*uaC3?*deCF_>`4hlwEFIe(?qUN02tWV=5P$##AOHaf zKmY;|fWRpfP$kj(b3{Kl)BpcR@BiP=6Mf@+<$U3M=6vG3sCgu zgpg7=Rhj6OHiBEyX~nqG4oL8rMC*p)wjG;o6LqjY)j?br)}^alHjd^WRot##OiS&c zGy_pQ?BpBkbU^d>n_u6}>`o{DV}*S3uNHaHnCqaI``le`Yu6ezxX1UX=GyN*`5S!L M2Q{pesGTPx# From f61ae529763cd6864eaaae4e2499024ee00f2010 Mon Sep 17 00:00:00 2001 From: Johannes Tax Date: Wed, 20 May 2020 13:56:29 -0700 Subject: [PATCH 03/12] PR comments --- examples/simple/BUILD | 1 + examples/simple/library.cc | 30 ------------------------------ 2 files changed, 1 insertion(+), 30 deletions(-) delete mode 100644 examples/simple/library.cc diff --git a/examples/simple/BUILD b/examples/simple/BUILD index 34583e2eac..5b7a83cfa4 100644 --- a/examples/simple/BUILD +++ b/examples/simple/BUILD @@ -20,6 +20,7 @@ cc_binary( deps = [ ":foo_library", "//api", + "//examples/simple:foo_library", "//sdk/src/trace", ], ) diff --git a/examples/simple/library.cc b/examples/simple/library.cc deleted file mode 100644 index ce33c6aba9..0000000000 --- a/examples/simple/library.cc +++ /dev/null @@ -1,30 +0,0 @@ -#include "opentelemetry/trace/provider.h" - -namespace trace = opentelemetry::trace; -namespace nostd = opentelemetry::nostd; - -static nostd::shared_ptr get_tracer() -{ - auto provider = trace::Provider::GetTracerProvider(); - return provider->GetTracer(""); -} - -static void f1() -{ - auto span = get_tracer()->StartSpan("f1"); -} - -static void f2() -{ - auto span = get_tracer()->StartSpan("f2"); - - f1(); - f1(); -} - -void library() -{ - auto span = get_tracer()->StartSpan("library"); - - f2(); -} From 3065c6bb7b9739672c001f05451fc8635b3b0654 Mon Sep 17 00:00:00 2001 From: Johannes Tax Date: Wed, 20 May 2020 16:23:59 -0700 Subject: [PATCH 04/12] Bazel fixes --- examples/simple/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/simple/BUILD b/examples/simple/BUILD index 5b7a83cfa4..134e5df580 100644 --- a/examples/simple/BUILD +++ b/examples/simple/BUILD @@ -6,6 +6,7 @@ cc_library( hdrs = [ "foo_library/foo_library.h", ], + linkstatic = True, deps = [ "//api", ], @@ -20,7 +21,6 @@ cc_binary( deps = [ ":foo_library", "//api", - "//examples/simple:foo_library", "//sdk/src/trace", ], ) From d78bf3e6d83b4ee1521fb3438efcf337e292c004 Mon Sep 17 00:00:00 2001 From: Johannes Tax Date: Thu, 21 May 2020 17:56:51 -0700 Subject: [PATCH 05/12] Fix bazel build --- examples/simple/BUILD | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/simple/BUILD b/examples/simple/BUILD index 134e5df580..34583e2eac 100644 --- a/examples/simple/BUILD +++ b/examples/simple/BUILD @@ -6,7 +6,6 @@ cc_library( hdrs = [ "foo_library/foo_library.h", ], - linkstatic = True, deps = [ "//api", ], From f2181b9b1df738b8ed061df1b99daf4fa4e2bc5d Mon Sep 17 00:00:00 2001 From: Ankit Bhargava Date: Fri, 29 May 2020 15:17:59 -0400 Subject: [PATCH 06/12] Adding documentation and build instructions --- examples/simple/README.md | 33 +++++++++++++++++++++++++++++++++ examples/simple/main.cc | 15 +++++++++++---- 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 examples/simple/README.md diff --git a/examples/simple/README.md b/examples/simple/README.md new file mode 100644 index 0000000000..4faff8cb8b --- /dev/null +++ b/examples/simple/README.md @@ -0,0 +1,33 @@ + +# Simple Trace Example + +This example sets up a tracer in the main application then makes several calls to a custom library instrumented with the Open Telemetry SDK . Specifically, it demonstrates the setup of fundamental Open Telemetry componenets such as Tracers, Tracer Providers and Spans. The example also illustrates context propogation from parent spans to children spans and events. All telemetry output is directed to stdout. + +## Build and Run +--- + +
  • Install the latest bazel version by following the steps listed here
  • + +
  • Clone or fork the Open Telemetry C++ repository:
  • + +```sh +git clone https://github.com/open-telemetry/opentelemetry-cpp.git +``` + +
  • Build the example from the root of the opentelemetry-cpp directory using Bazel:
  • + +```sh +cd opentelemetry-cpp/ +bazel build //examples/simple:example_simple +``` + +
  • Run the resulting executable to see telemetry from the application as it calls the instrumented library:
  • + +```sh +bazel-bin/examples/simple/example_simple +``` + +## Useful Links +--- +
  • Open Telemetry
  • +
  • Tracing SDK Specification
  • \ No newline at end of file diff --git a/examples/simple/main.cc b/examples/simple/main.cc index af03d2e6db..5de9b454eb 100644 --- a/examples/simple/main.cc +++ b/examples/simple/main.cc @@ -11,19 +11,26 @@ namespace { void initTracer() { - auto exporter = std::unique_ptr(new StdoutExporter); - auto processor = std::shared_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); + // Specify the exporter: StdoutExporter in this case simply passes all output from the span + // processor to stdout + auto exporter = std::unique_ptr(new StdoutExporter); + // Specify the Span Processor: SimpleSpanProcessor forwards all completed spans directly to the + // exporter + auto processor = std::shared_ptr(new sdktrace::SimpleSpanProcessor( + std::move(exporter))); // Create a Span Processor given the StdoutExporter defined earlier + // Initialize a trace provider with the Span Processor instance defined above auto provider = nostd::shared_ptr(new sdktrace::TracerProvider(processor)); + // Set global trace provider trace::Provider::SetTracerProvider(provider); } } // namespace int main() { - // Removing this line will leave OT initialized with the default noop + // Removing this line will leave OTel SDK initialized with the default noop // tracer, thus being effectively deactivated. initTracer(); + // Call the instrumented library foo_library(); } From 52424b37ec20830274b46c56d4f762ba909897a1 Mon Sep 17 00:00:00 2001 From: Ankit Bhargava Date: Wed, 3 Jun 2020 13:10:00 -0400 Subject: [PATCH 07/12] Condensed comments, moved build/run instructions to CONTRIBUTING.md --- examples/simple/README.md | 31 ++----------------------------- examples/simple/main.cc | 12 ++++-------- 2 files changed, 6 insertions(+), 37 deletions(-) diff --git a/examples/simple/README.md b/examples/simple/README.md index 4faff8cb8b..beea3cd9a8 100644 --- a/examples/simple/README.md +++ b/examples/simple/README.md @@ -1,33 +1,6 @@ # Simple Trace Example -This example sets up a tracer in the main application then makes several calls to a custom library instrumented with the Open Telemetry SDK . Specifically, it demonstrates the setup of fundamental Open Telemetry componenets such as Tracers, Tracer Providers and Spans. The example also illustrates context propogation from parent spans to children spans and events. All telemetry output is directed to stdout. +In this example, an application in `main.cc` initializes and registers a tracer provider from the Open Telemetry SDK . The application then calls a `foo_library` which has been manually instrumented using the OpenTelemetry API . Resulting telemetry is directed to stdout by through a custom exporter. -## Build and Run ---- - -
  • Install the latest bazel version by following the steps listed here
  • - -
  • Clone or fork the Open Telemetry C++ repository:
  • - -```sh -git clone https://github.com/open-telemetry/opentelemetry-cpp.git -``` - -
  • Build the example from the root of the opentelemetry-cpp directory using Bazel:
  • - -```sh -cd opentelemetry-cpp/ -bazel build //examples/simple:example_simple -``` - -
  • Run the resulting executable to see telemetry from the application as it calls the instrumented library:
  • - -```sh -bazel-bin/examples/simple/example_simple -``` - -## Useful Links ---- -
  • Open Telemetry
  • -
  • Tracing SDK Specification
  • \ No newline at end of file +See CONTRIBUTING.md for instructions on building and running the example. \ No newline at end of file diff --git a/examples/simple/main.cc b/examples/simple/main.cc index 5de9b454eb..fb28ed16a5 100644 --- a/examples/simple/main.cc +++ b/examples/simple/main.cc @@ -11,16 +11,12 @@ namespace { void initTracer() { - // Specify the exporter: StdoutExporter in this case simply passes all output from the span - // processor to stdout auto exporter = std::unique_ptr(new StdoutExporter); - // Specify the Span Processor: SimpleSpanProcessor forwards all completed spans directly to the - // exporter - auto processor = std::shared_ptr(new sdktrace::SimpleSpanProcessor( - std::move(exporter))); // Create a Span Processor given the StdoutExporter defined earlier - // Initialize a trace provider with the Span Processor instance defined above + // Specify the Span Processor: SimpleSpanProcessor forwards spans directly to the exporter + auto processor = std::shared_ptr( + new sdktrace::SimpleSpanProcessor(std::move(exporter))); auto provider = nostd::shared_ptr(new sdktrace::TracerProvider(processor)); - // Set global trace provider + // Set the global trace provider trace::Provider::SetTracerProvider(provider); } } // namespace From 5512d5f4652ec24ced496c9fabe67f1380758c72 Mon Sep 17 00:00:00 2001 From: Ankit Bhargava Date: Thu, 11 Jun 2020 00:15:32 -0400 Subject: [PATCH 08/12] Typo fix in README.md Co-authored-by: Reiley Yang --- examples/simple/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/simple/README.md b/examples/simple/README.md index beea3cd9a8..fe52ac6243 100644 --- a/examples/simple/README.md +++ b/examples/simple/README.md @@ -1,6 +1,6 @@ # Simple Trace Example -In this example, an application in `main.cc` initializes and registers a tracer provider from the Open Telemetry SDK . The application then calls a `foo_library` which has been manually instrumented using the OpenTelemetry API . Resulting telemetry is directed to stdout by through a custom exporter. +In this example, an application in `main.cc` initializes and registers a tracer provider from the Open Telemetry SDK . The application then calls a `foo_library` which has been manually instrumented using the OpenTelemetry API . Resulting telemetry is directed to stdout through a custom exporter. -See CONTRIBUTING.md for instructions on building and running the example. \ No newline at end of file +See CONTRIBUTING.md for instructions on building and running the example. From 72f9c18be89d39c545acd62321042e74c526207f Mon Sep 17 00:00:00 2001 From: Ankit Bhargava Date: Thu, 11 Jun 2020 00:22:28 -0400 Subject: [PATCH 09/12] Updating comments in main.cc Replacing the unofficial "OTel" shorthand with the "OpenTelemetry" --- examples/simple/main.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/simple/main.cc b/examples/simple/main.cc index fb28ed16a5..ea88400401 100644 --- a/examples/simple/main.cc +++ b/examples/simple/main.cc @@ -23,7 +23,7 @@ void initTracer() int main() { - // Removing this line will leave OTel SDK initialized with the default noop + // Removing this line will leave OpenTelemetry SDK initialized with the default noop // tracer, thus being effectively deactivated. initTracer(); From 7c32c869e34a43a001a06a5fd934b77daa6a15a1 Mon Sep 17 00:00:00 2001 From: Ankit Bhargava Date: Fri, 12 Jun 2020 12:22:24 -0400 Subject: [PATCH 10/12] Incorporating review suggestions --- examples/simple/README.md | 4 ++-- examples/simple/main.cc | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/simple/README.md b/examples/simple/README.md index fe52ac6243..dfcae3c465 100644 --- a/examples/simple/README.md +++ b/examples/simple/README.md @@ -1,6 +1,6 @@ # Simple Trace Example -In this example, an application in `main.cc` initializes and registers a tracer provider from the Open Telemetry SDK . The application then calls a `foo_library` which has been manually instrumented using the OpenTelemetry API . Resulting telemetry is directed to stdout through a custom exporter. +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/master/api). Resulting telemetry is directed to stdout through a custom exporter. -See CONTRIBUTING.md for instructions on building and running the example. +See [CONTRIBUTING.md](../../CONTRIBUTING.md) for instructions on building and running the example. \ No newline at end of file diff --git a/examples/simple/main.cc b/examples/simple/main.cc index ea88400401..755ba2779c 100644 --- a/examples/simple/main.cc +++ b/examples/simple/main.cc @@ -23,10 +23,8 @@ void initTracer() int main() { - // Removing this line will leave OpenTelemetry SDK initialized with the default noop - // tracer, thus being effectively deactivated. + // Removing this line will leave the default noop TracerProvider in place. initTracer(); - // Call the instrumented library foo_library(); } From 6ae95bb913a2caca6c018b06fd0fb6dd8a69e2ae Mon Sep 17 00:00:00 2001 From: Ankit Bhargava Date: Wed, 17 Jun 2020 10:57:56 -0400 Subject: [PATCH 11/12] spacing consistency and line wrapping --- examples/simple/README.md | 6 +++++- examples/simple/main.cc | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/simple/README.md b/examples/simple/README.md index dfcae3c465..5a36a70616 100644 --- a/examples/simple/README.md +++ b/examples/simple/README.md @@ -1,6 +1,10 @@ # 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/master/api). Resulting telemetry is directed to stdout through a custom exporter. +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/master/api). + Resulting telemetry is directed to stdout through a custom exporter. See [CONTRIBUTING.md](../../CONTRIBUTING.md) for instructions on building and running the example. \ No newline at end of file diff --git a/examples/simple/main.cc b/examples/simple/main.cc index 755ba2779c..756c764e89 100644 --- a/examples/simple/main.cc +++ b/examples/simple/main.cc @@ -11,8 +11,7 @@ namespace { void initTracer() { - auto exporter = std::unique_ptr(new StdoutExporter); - // Specify the Span Processor: SimpleSpanProcessor forwards spans directly to the exporter + auto exporter = std::unique_ptr(new StdoutExporter); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); auto provider = nostd::shared_ptr(new sdktrace::TracerProvider(processor)); From e89e017e6e51869887b08f41a7da236e868c279c Mon Sep 17 00:00:00 2001 From: Ankit Bhargava Date: Fri, 19 Jun 2020 01:21:14 -0400 Subject: [PATCH 12/12] rebased and removed leading spaces --- CMakeLists.txt | 6 +++--- examples/simple/README.md | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ee6dcbe380..9fbfc1c059 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,9 +23,9 @@ include(CTest) find_package(Threads) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - # Options for Visual C++ compiler: - # /Zc:__cplusplus - report an updated value for recent C++ language standards. - # Without this option MSVC returns the value of __cplusplus="199711L" + # Options for Visual C++ compiler: /Zc:__cplusplus - report an updated value + # for recent C++ language standards. Without this option MSVC returns the + # value of __cplusplus="199711L" set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus") endif() diff --git a/examples/simple/README.md b/examples/simple/README.md index 5a36a70616..d59a1423cd 100644 --- a/examples/simple/README.md +++ b/examples/simple/README.md @@ -2,9 +2,9 @@ # 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/master/api). - Resulting telemetry is directed to stdout through a custom exporter. +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/master/api). +Resulting telemetry is directed to stdout through a custom exporter. See [CONTRIBUTING.md](../../CONTRIBUTING.md) for instructions on building and running the example. \ No newline at end of file