userver: userver/tracing/manager_component.hpp Source File
Loading...
Searching...
No Matches
manager_component.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/tracing/manager_component.hpp
4/// @brief TracingManager base and default components
5
6#include <string>
7
8#include <userver/components/component_base.hpp>
9#include <userver/tracing/manager.hpp>
10#include <userver/tracing/span.hpp>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace tracing {
15
16/// @brief Base component for implementing TracingManager component
17// NOLINTNEXTLINE(fuchsia-multiple-inheritance)
19public:
20 TracingManagerComponentBase(const components::ComponentConfig&, const components::ComponentContext&);
21};
22
23// clang-format off
24
25/// @ingroup userver_components
26///
27/// @brief Component that provides access to the actual TracingManager
28/// that is used in handlers and clients.
29///
30/// This component allows conversion of tracing formats and allows working with
31/// multiple tracing formats. For example:
32/// @code
33/// # yaml
34/// incoming-format: ['opentelemetry', 'taxi']
35/// new-requests-format: ['b3-alternative', 'opentelemetry']
36/// @endcode
37/// means that tracing data is extracted from OpenTelemetry headers if they
38/// were received or from Yandex-Taxi specific headers. The outgoing requests
39/// will have the tracing::Format::kB3Alternative headers and OpenTelemetry
40/// headers at the same time.
41///
42/// The component can be configured in service config.
43///
44/// ## Static options:
45/// Name | Description | Default value
46/// ---- | ----------- | -------------
47/// component-name | name of the component, that implements TracingManagerComponentBase | <use tracing::GenericTracingManager with below settings>
48/// incoming-format | Array of incoming tracing formats supported by tracing::FormatFromString | ['opentelemetry', 'taxi']
49/// new-requests-format | Send tracing data in those formats supported by tracing::FormatFromString | ['opentelemetry', 'taxi']
50///
51// clang-format on
52class DefaultTracingManagerLocator final : public components::ComponentBase {
53public:
54 /// @ingroup userver_component_names
55 /// @brief The default name of tracing::DefaultTracingManagerLocator
56 static constexpr std::string_view kName = "tracing-manager-locator";
57
58 DefaultTracingManagerLocator(const components::ComponentConfig&, const components::ComponentContext&);
59
60 const TracingManagerBase& GetTracingManager() const;
61
62 static yaml_config::Schema GetStaticConfigSchema();
63
64private:
65 GenericTracingManager default_manager_;
66 const TracingManagerBase& tracing_manager_;
67};
68
69} // namespace tracing
70
71template <>
72inline constexpr bool components::kHasValidate<tracing::DefaultTracingManagerLocator> = true;
73
74template <>
75inline constexpr auto components::kConfigFileMode<tracing::DefaultTracingManagerLocator> = ConfigFileMode::kNotRequired;
76
77USERVER_NAMESPACE_END