From 408b7c1908c98a4a289e07c92335e9d4f364c777 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Mon, 24 May 2021 10:39:26 +0530 Subject: [PATCH 1/4] api getting started --- docs/public/GettingStarted.rst | 48 +++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/docs/public/GettingStarted.rst b/docs/public/GettingStarted.rst index ad061cc125..93b39d602d 100644 --- a/docs/public/GettingStarted.rst +++ b/docs/public/GettingStarted.rst @@ -48,5 +48,51 @@ related span is ended. The concept of an active span is important, as any span that is created without explicitly specifying a parent is parented to the currently -active span. +active span. A span without a parent is called root span. +Create nested Spans +^^^^^^^^^^^^^^^^^^^ + +..code:: cpp + + auto outer_span = tracer->StartSpan("Outer operation"); + auto outer_scope = tracer->WithActiveSpan(outer_span); + { + auto inner_span = tracer->StartSpan("Inner operation"); + auto inner_scope = tracer->WithActiveSpan(inner_span); + --- + inner_span->End(); + } + --- + outer_span->End(); + + +Spans can be nested, and have a parent-child relationship with other spans. +When a given span is active,the newly created span inherits the active span's +trace ID, and other context attributes. + +Context Propagation +^^^^^^^^^^^^^^^^^^ + +..code:: cpp + + HttpTextMapCarrier carrier; + auto propagator = + opentelemetry::context::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); + + //inject context to headers + auto current_ctx = opentelemetry::context::RuntimeContext::GetCurrent(); + propagator->Inject(carrier, current_ctx); + + //Extract headers to context + auto current_ctx = opentelemetry::context::RuntimeContext::GetCurrent(); + auto new_context = propagator->Extract(carrier, current_ctx); + auto remote_span = opentelemetry::trace::propagation::GetSpan(new_context); + + + +``Context`` contains the meta-data of the currently active Span including Span Id, +Trace Id, and flags. Context Propagation is an important mechanism in distributed +tracing to transfer this Context across service boundary often through HTTP headers. +OpenTelemetry provides a text-based approach to propagate context to remote services +using the W3C Trace Context HTTP headers. From 270ffe069d627a8ee493eb54e627caa3a738d753 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Mon, 24 May 2021 11:24:18 +0530 Subject: [PATCH 2/4] fix --- docs/public/GettingStarted.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/public/GettingStarted.rst b/docs/public/GettingStarted.rst index 93b39d602d..0f9565f223 100644 --- a/docs/public/GettingStarted.rst +++ b/docs/public/GettingStarted.rst @@ -53,17 +53,17 @@ active span. A span without a parent is called root span. Create nested Spans ^^^^^^^^^^^^^^^^^^^ -..code:: cpp +.. code:: cpp auto outer_span = tracer->StartSpan("Outer operation"); auto outer_scope = tracer->WithActiveSpan(outer_span); { auto inner_span = tracer->StartSpan("Inner operation"); auto inner_scope = tracer->WithActiveSpan(inner_span); - --- + // inner operation inner_span->End(); } - --- + // outer operation outer_span->End(); @@ -74,7 +74,7 @@ trace ID, and other context attributes. Context Propagation ^^^^^^^^^^^^^^^^^^ -..code:: cpp +.. code:: cpp HttpTextMapCarrier carrier; auto propagator = From 0fe854e5329b1d1b77e9777c815d2e5c0828de03 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Mon, 24 May 2021 11:57:53 +0530 Subject: [PATCH 3/4] add doc for set global propagator --- docs/public/GettingStarted.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/public/GettingStarted.rst b/docs/public/GettingStarted.rst index 0f9565f223..e0ef4e6163 100644 --- a/docs/public/GettingStarted.rst +++ b/docs/public/GettingStarted.rst @@ -60,10 +60,10 @@ Create nested Spans { auto inner_span = tracer->StartSpan("Inner operation"); auto inner_scope = tracer->WithActiveSpan(inner_span); - // inner operation + // ... perform inner operation inner_span->End(); } - // outer operation + // ... perform outer operation outer_span->End(); @@ -76,6 +76,12 @@ Context Propagation .. code:: cpp + // set global propagator + opentelemetry::context::propagation::GlobalTextMapPropagator::SetGlobalPropagator( + nostd::shared_ptr( + new opentelemetry::trace::propagation::HttpTraceContext())); + + // get global propagator HttpTextMapCarrier carrier; auto propagator = opentelemetry::context::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); From 9c597200f131893196d2be18877f8e5ed37331f9 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Mon, 24 May 2021 12:19:18 +0530 Subject: [PATCH 4/4] grammer --- docs/public/GettingStarted.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/public/GettingStarted.rst b/docs/public/GettingStarted.rst index e0ef4e6163..abff4d6d13 100644 --- a/docs/public/GettingStarted.rst +++ b/docs/public/GettingStarted.rst @@ -68,7 +68,7 @@ Create nested Spans Spans can be nested, and have a parent-child relationship with other spans. -When a given span is active,the newly created span inherits the active span's +When a given span is active, the newly created span inherits the active span's trace ID, and other context attributes. Context Propagation