userver: userver/tracing/span_event.hpp Source File
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
span_event.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/tracing/span_event.hpp
4/// @brief @copybrief tracing::SpanEvent
5
6#include <chrono>
7#include <string_view>
8#include <unordered_map>
9
10#include <userver/formats/json_fwd.hpp>
11#include <userver/tracing/any_value.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace tracing {
16
17/// @brief Span event -- time-stamped annotation of the span with user-provided text description.
18/// @see https://opentelemetry.io/docs/concepts/signals/traces/#span-events
19/// @see
20/// https://github.com/open-telemetry/opentelemetry-proto/blob/v1.3.2/opentelemetry/proto/trace/v1/trace.proto#L220.
21struct SpanEvent final {
22 using Timestamp = std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>;
23 using KeyValue = std::unordered_map<std::string, AnyValue>;
24
25 /// @brief Constructor. Creates span event with name and timestamp.
26 /// @param name Event name.
27 explicit SpanEvent(std::string_view name);
28
29 /// @brief Constructor. Creates span event with name, timestamp and attributes.
30 /// @param name Event name.
31 /// @param attributes Key-value attributes.
32 SpanEvent(std::string_view name, KeyValue attributes);
33
34 /// @brief Event name.
35 std::string name;
36
37 /// @brief Event timestamp.
38 Timestamp timestamp{};
39
40 /// @brief Attributes.
41 /// @see
42 /// https://github.com/open-telemetry/opentelemetry-proto/blob/v1.3.2/opentelemetry/proto/common/v1/common.proto#L64.
43 /// @see
44 /// https://github.com/open-telemetry/opentelemetry-proto/blob/v1.3.2/opentelemetry/proto/trace/v1/trace.proto#L231.
45 /// @details Collection of unique key-value pairs.
47};
48
49SpanEvent Parse(const formats::json::Value& value, formats::parse::To<SpanEvent>);
50
51void WriteToStream(const SpanEvent& span_event, formats::json::StringBuilder& sw);
52
53} // namespace tracing
54
55USERVER_NAMESPACE_END