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