ORE Studio 0.0.4
Loading...
Searching...
No Matches
span.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_SPAN_HPP
21#define ORES_TELEMETRY_DOMAIN_SPAN_HPP
22
23#include <chrono>
24#include <optional>
25#include <string>
26#include <vector>
27#include "ores.telemetry/domain/span_context.hpp"
28#include "ores.telemetry/domain/span_kind.hpp"
29#include "ores.telemetry/domain/span_status.hpp"
30#include "ores.telemetry/domain/span_link.hpp"
31#include "ores.telemetry/domain/attribute_value.hpp"
32
34
45struct span final {
50
54 std::optional<span_id> parent_span_id;
55
59 std::vector<span_link> links;
60
66 std::string name;
67
72
76 std::chrono::system_clock::time_point start_time;
77
81 std::optional<std::chrono::system_clock::time_point> end_time;
82
87
91 std::string status_message;
92
99
103 bool is_session() const;
104
108 bool is_root() const;
109
113 std::optional<std::chrono::nanoseconds> duration() const;
114};
115
116}
117
118#endif
Domain types for telemetry and observability.
Definition attribute_value.hpp:29
std::map< std::string, attribute_value > attributes
A collection of attributes as key-value pairs.
Definition attribute_value.hpp:52
span_status_code
The status code of a span, following OpenTelemetry conventions.
Definition span_status.hpp:32
@ unset
The default status. The operation completed without any known errors.
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 a single operation within a trace.
Definition span.hpp:45
std::optional< std::chrono::system_clock::time_point > end_time
When the span ended. Empty if the span is still in progress.
Definition span.hpp:81
span_kind kind
The kind of span (internal, server, client, producer, consumer).
Definition span.hpp:71
attributes attrs
Key-value pairs providing additional context about the operation.
Definition span.hpp:98
bool is_root() const
Checks if this is a root span (no parent).
Definition span.cpp:28
bool is_session() const
Checks if this span represents a session (has session.id attribute).
Definition span.cpp:24
std::string status_message
A message describing the status, typically set when status is error.
Definition span.hpp:91
std::string name
A human-readable name describing the operation.
Definition span.hpp:66
std::optional< span_id > parent_span_id
The parent span's ID, if this is not a root span.
Definition span.hpp:54
std::vector< span_link > links
Links to other spans forming hypergraph relationships.
Definition span.hpp:59
std::chrono::system_clock::time_point start_time
When the span started.
Definition span.hpp:76
span_status_code status_code
The status code of the operation.
Definition span.hpp:86
span_context context
The span's identity (trace_id + span_id + flags).
Definition span.hpp:49
std::optional< std::chrono::nanoseconds > duration() const
Calculates the duration of the span if it has ended.
Definition span.cpp:32
Immutable context for trace propagation across boundaries.
Definition span_context.hpp:37