Skip to content

Commit

Permalink
Merge branch 'main' into copyrights
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored May 25, 2021
2 parents 3cabcfe + 02f9efc commit 566cce0
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion docs/public/GettingStarted.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,57 @@ 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);
// ... perform inner operation
inner_span->End();
}
// ... perform outer operation
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
// set global propagator
opentelemetry::context::propagation::GlobalTextMapPropagator::SetGlobalPropagator(
nostd::shared_ptr<opentelemetry::context::propagation::TextMapPropagator>(
new opentelemetry::trace::propagation::HttpTraceContext()));
// get global propagator
HttpTextMapCarrier<opentelemetry::ext::http::client::Headers> 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.

0 comments on commit 566cce0

Please sign in to comment.