userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
manager.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <
userver/clients/http/middlewares/base.hpp
>
7
#include <
userver/clients/http/response.hpp
>
8
#include <
userver/tracing/span.hpp
>
9
#include <
userver/tracing/span_builder.hpp
>
10
#include <
userver/utils/flags.hpp
>
11
12
USERVER_NAMESPACE_BEGIN
13
14
namespace
server::http
{
15
class
HttpResponse
;
16
class
HttpRequest
;
17
}
// namespace server::http
18
19
namespace
tracing
{
20
26
class
TracingManagerBase
{
27
public
:
28
virtual
~TracingManagerBase
() =
default
;
29
35
virtual
bool
TryFillSpanBuilderFromRequest
(
const
server::http::HttpRequest
& request,
SpanBuilder
& span_builder)
36
const
= 0;
37
39
virtual
void
FillRequestWithTracingContext
(
const
Span
& span,
clients::http::MiddlewareRequest
request)
const
= 0;
40
42
virtual
void
FillResponseWithTracingContext
(
const
Span
& span,
server::http::HttpResponse
& response)
const
= 0;
43
};
44
45
// clang-format off
46
enum class
Format
:
short
{
47
kNone = 0,
48
55
kYandexTaxi
= 1 << 1,
56
59
kYandex
= 1 << 2,
60
64
kOpenTelemetry
= 1 << 3,
65
73
kB3Alternative
= 1 << 4,
74
};
75
// clang-format on
76
78
Format
FormatFromString
(std::string_view format);
79
80
bool
TryFillSpanBuilderFromRequest(
Format
format,
const
server::http::HttpRequest
& request,
SpanBuilder
& span_builder);
81
82
void
FillRequestWithTracingContext(
Format
format,
const
tracing::Span
& span,
clients::http::MiddlewareRequest
request);
83
84
void
FillResponseWithTracingContext(
Format
format,
const
Span
& span,
server::http::HttpResponse
& response);
85
88
enum
OtelTraceFlags
: std::uint8_t {
89
kNoTracing
= 0x00,
90
kSampled
= 0x01,
91
};
92
96
OtelTraceFlags
GetInheritedOtelTraceFlags
();
97
100
std::string_view
GetInheritedOtelTraceState
();
101
105
void
SetInheritedOtelTracingData
(std::string_view tracestate, std::string_view traceflags);
106
109
class
GenericTracingManager final :
public
TracingManagerBase
{
110
public
:
111
enum class
SamplingEnabled :
bool
{
112
kNo =
false
,
113
kYes =
true
,
114
};
115
116
GenericTracingManager() =
delete
;
117
118
GenericTracingManager(
119
utils::Flags<Format>
in_request_response,
120
utils::Flags<Format>
new_request,
121
SamplingEnabled sampling = SamplingEnabled::kNo
122
)
123
: in_request_response_{in_request_response},
124
new_request_{new_request},
125
sampling_{sampling}
126
{}
127
128
bool
TryFillSpanBuilderFromRequest
(
const
server::http::HttpRequest
& request,
SpanBuilder
& span_builder)
129
const override
;
130
131
void
FillRequestWithTracingContext
(
const
tracing::Span
& span,
clients::http::MiddlewareRequest
request)
132
const override
;
133
134
void
FillResponseWithTracingContext
(
const
Span
& span,
server::http::HttpResponse
& response)
const override
;
135
136
private
:
137
const
utils::Flags<Format>
in_request_response_;
138
const
utils::Flags<Format>
new_request_;
139
const
SamplingEnabled sampling_{SamplingEnabled::kNo};
140
};
141
142
}
// namespace tracing
143
144
USERVER_NAMESPACE_END
userver
tracing
manager.hpp
Generated on
for userver by
Doxygen
1.17.0