|
ORE Studio 0.0.4
|
Immutable context passed through the call chain for telemetry. More...
#include <telemetry_context.hpp>

Public Member Functions | |
| telemetry_context (span_context ctx, std::shared_ptr< resource > res) | |
| Constructs a telemetry context. | |
| const span_context & | context () const |
| Gets the current span context. | |
| const trace_id & | get_trace_id () const |
| Gets the trace_id from the current context. | |
| const span_id & | get_span_id () const |
| Gets the span_id from the current context. | |
| const resource & | get_resource () const |
| Gets the resource associated with this context. | |
| std::shared_ptr< resource > | resource_ptr () const |
| Gets the shared pointer to the resource. | |
| std::pair< telemetry_context, span > | start_span (std::string_view name, span_kind kind=span_kind::internal) const |
| Creates a new child span within the same trace. | |
| std::pair< telemetry_context, span > | start_linked_trace (std::string_view name, span_kind kind=span_kind::internal) const |
| Creates a new trace linked to the current span. | |
| bool | is_valid () const |
| Checks if this context is valid. | |
Static Public Member Functions | |
| static telemetry_context | create_root (std::shared_ptr< resource > res) |
| Creates a root telemetry context for a new trace. | |
Immutable context passed through the call chain for telemetry.
The telemetry_context is designed to be passed as an explicit parameter to all functions that participate in distributed tracing. This approach works well with coroutines and makes data flow explicit.
Usage:
|
explicit |
Constructs a telemetry context.
| ctx | The span context identifying the current span. |
| res | The resource describing the entity producing telemetry. |
|
static |
Creates a root telemetry context for a new trace.
This is used to start a new trace at the entry point of an application or service. The root context has a newly generated trace_id and span_id.
| res | The resource describing the entity producing telemetry. |

| std::pair< telemetry_context, span > start_span | ( | std::string_view | name, |
| span_kind | kind = span_kind::internal |
||
| ) | const |
Creates a new child span within the same trace.
The returned span has this context's span_id as its parent.
| name | The name of the new span. |
| kind | The kind of span (default: internal). |
| std::pair< telemetry_context, span > start_linked_trace | ( | std::string_view | name, |
| span_kind | kind = span_kind::internal |
||
| ) | const |
Creates a new trace linked to the current span.
This is used when starting independent work that should be correlated with the current trace but not as a child span. For example, when a grid engine picks up work triggered by a client request.
| name | The name of the new span. |
| kind | The kind of span (default: internal). |