-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtracer.h
More file actions
114 lines (97 loc) · 4.31 KB
/
tracer.h
File metadata and controls
114 lines (97 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#pragma once
// This component provides a class, `Tracer`, that instantiates the mechanisms
// necessary for tracing, and provides member functions for creating spans.
// Each span created by `Tracer` is either the root of a new trace (see
// `create_span`) or part of an existing trace whose information is extracted
// from a provided key/value source (see `extract_span`).
//
// `Tracer` is instantiated with a `FinalizedTracerConfig`, which can be
// obtained from a `TracerConfig` via the `finalize_config` function. See
// `tracer_config.h`.
#include <cstddef>
#include <memory>
#include "baggage.h"
#include "clock.h"
#include "expected.h"
#include "id_generator.h"
#include "optional.h"
#include "span.h"
#include "span_config.h"
#include "tracer_config.h"
#include "tracer_signature.h"
namespace datadog {
namespace tracing {
class ConfigManager;
class DictReader;
struct SpanConfig;
class TraceSampler;
class SpanSampler;
class IDGenerator;
class InMemoryFile;
class Tracer {
std::shared_ptr<Logger> logger_;
RuntimeID runtime_id_;
TracerSignature signature_;
std::shared_ptr<ConfigManager> config_manager_;
std::shared_ptr<Collector> collector_;
std::shared_ptr<SpanSampler> span_sampler_;
std::shared_ptr<const IDGenerator> generator_;
Clock clock_;
std::vector<PropagationStyle> injection_styles_;
std::vector<PropagationStyle> extraction_styles_;
Optional<std::string> hostname_;
std::size_t tags_header_max_size_;
// Store the tracer configuration in an in-memory file, allowing it to be
// read to determine if the process is instrumented with a tracer and to
// retrieve relevant tracing information.
std::shared_ptr<InMemoryFile> metadata_file_;
Baggage::Options baggage_opts_;
bool baggage_injection_enabled_;
bool baggage_extraction_enabled_;
bool tracing_enabled_;
HttpEndpointCalculationMode resource_renaming_mode_;
public:
// Create a tracer configured using the specified `config`, and optionally:
// - using the specified `generator` to create trace IDs and span IDs
// - using the specified `clock` to get the current time.
explicit Tracer(const FinalizedTracerConfig& config);
Tracer(const FinalizedTracerConfig& config,
const std::shared_ptr<const IDGenerator>& generator);
// Create a new trace and return the root span of the trace. Optionally
// specify a `config` indicating the attributes of the root span.
Span create_span();
Span create_span(const SpanConfig& config);
// Return a span whose parent and other context is parsed from the specified
// `reader`, and whose attributes are determined by the optionally specified
// `config`. If there is no tracing information in `reader`, then return an
// error with code `Error::NO_SPAN_TO_EXTRACT`. If a failure occurs, then
// return an error with some other code.
Expected<Span> extract_span(const DictReader& reader);
Expected<Span> extract_span(const DictReader& reader,
const SpanConfig& config);
// Return a span extracted from the specified `reader` (see `extract_span`).
// If there is no span to extract, or if an error occurs during extraction,
// then return a span that is the root of a new trace (see `create_span`).
// Optionally specify a `config` indicating the attributes of the span.
Span extract_or_create_span(const DictReader& reader);
Span extract_or_create_span(const DictReader& reader,
const SpanConfig& config);
// Create a baggage.
Baggage create_baggage();
// Return the extracted baggage from the specified `reader`.
// An error is returned if an error occurs during extraction.
Expected<Baggage, Baggage::Error> extract_baggage(const DictReader& reader);
// Return the extracted baggage from the specified `reader`, or an empty
// baggage is there is no baggage to extract if an error occurs during
// extraction.
Baggage extract_or_create_baggage(const DictReader& reader);
// Inject baggage into the specified `reader`.
Expected<void> inject(const Baggage& baggage, DictWriter& writer);
// Return a JSON object describing this Tracer's configuration. It is the
// same JSON object that was logged when this Tracer was created.
std::string config() const;
private:
void store_config(const std::unordered_map<std::string, std::string>&);
};
} // namespace tracing
} // namespace datadog