userver: userver/tracing/tracer.hpp Source File
Loading...
Searching...
No Matches
tracer.hpp
1#pragma once
2
3#include <memory>
4
5#include <userver/tracing/span.hpp>
6#include <userver/tracing/tracer_fwd.hpp>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace logging::impl {
11class TagWriter;
12} // namespace logging::impl
13
14/// Opentracing support
15namespace tracing {
16
17struct NoLogSpans;
18
20public:
21 static void SetNoLogSpans(NoLogSpans&& spans);
22 static bool IsNoLogSpan(const std::string& name);
23
24 static void SetTracer(TracerPtr tracer);
25
26 static TracerPtr GetTracer();
27
28 const std::string& GetServiceName() const;
29
30 Span CreateSpanWithoutParent(std::string name);
31
32 Span CreateSpan(std::string name, const Span& parent, ReferenceType reference_type);
33
34 // Log tag-private information like trace id, span id, etc.
35 virtual void LogSpanContextTo(const Span::Impl& span, logging::impl::TagWriter writer) const = 0;
36
37 logging::LoggerPtr GetOptionalLogger() const { return optional_logger_; }
38
39protected:
40 explicit Tracer(std::string_view service_name, logging::LoggerPtr optional_logger)
41 : service_name_(service_name), optional_logger_(std::move(optional_logger)) {}
42
43 virtual ~Tracer();
44
45private:
46 const std::string service_name_;
47 const logging::LoggerPtr optional_logger_;
48};
49
50/// Make a tracer that could be set globally via tracing::Tracer::SetTracer
51TracerPtr MakeTracer(std::string_view service_name, logging::LoggerPtr logger, std::string_view tracer_type = "native");
52
53} // namespace tracing
54
55USERVER_NAMESPACE_END