ORE Studio 0.0.4
Loading...
Searching...
No Matches
telemetry_context.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_TELEMETRY_DOMAIN_TELEMETRY_CONTEXT_HPP
21#define ORES_TELEMETRY_DOMAIN_TELEMETRY_CONTEXT_HPP
22
23#include <memory>
24#include <string_view>
25#include "ores.telemetry/domain/span_context.hpp"
26#include "ores.telemetry/domain/span_kind.hpp"
27#include "ores.telemetry/domain/span.hpp"
28#include "ores.telemetry/domain/resource.hpp"
29
31
50class telemetry_context final {
51public:
59 std::shared_ptr<resource> res);
60
70 static telemetry_context create_root(std::shared_ptr<resource> res);
71
75 const span_context& context() const;
76
80 const trace_id& get_trace_id() const;
81
85 const span_id& get_span_id() const;
86
90 const resource& get_resource() const;
91
95 std::shared_ptr<resource> resource_ptr() const;
96
106 std::pair<telemetry_context, span> start_span(
107 std::string_view name,
108 span_kind kind = span_kind::internal) const;
109
121 std::pair<telemetry_context, span> start_linked_trace(
122 std::string_view name,
123 span_kind kind = span_kind::internal) const;
124
128 bool is_valid() const;
129
130private:
131 span_context ctx_;
132 std::shared_ptr<resource> resource_;
133};
134
135}
136
137#endif
Domain types for telemetry and observability.
Definition attribute_value.hpp:29
span_kind
The type of span, following OpenTelemetry conventions.
Definition span_kind.hpp:34
@ internal
Default value. Indicates an internal operation within an application, not representing a remote call.
Represents the entity producing telemetry data.
Definition resource.hpp:39
Immutable context for trace propagation across boundaries.
Definition span_context.hpp:37
A 64-bit span identifier, compatible with OpenTelemetry.
Definition span_id.hpp:42
Immutable context passed through the call chain for telemetry.
Definition telemetry_context.hpp:50
static telemetry_context create_root(std::shared_ptr< resource > res)
Creates a root telemetry context for a new trace.
Definition telemetry_context.cpp:39
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.
Definition telemetry_context.cpp:68
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.
Definition telemetry_context.cpp:91
const span_id & get_span_id() const
Gets the span_id from the current context.
Definition telemetry_context.cpp:56
const trace_id & get_trace_id() const
Gets the trace_id from the current context.
Definition telemetry_context.cpp:52
const span_context & context() const
Gets the current span context.
Definition telemetry_context.cpp:48
bool is_valid() const
Checks if this context is valid.
Definition telemetry_context.cpp:122
const resource & get_resource() const
Gets the resource associated with this context.
Definition telemetry_context.cpp:60
std::shared_ptr< resource > resource_ptr() const
Gets the shared pointer to the resource.
Definition telemetry_context.cpp:64
A 128-bit trace identifier, compatible with OpenTelemetry.
Definition trace_id.hpp:42