-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathtelemetry.h
More file actions
173 lines (146 loc) · 5.99 KB
/
Copy pathtelemetry.h
File metadata and controls
173 lines (146 loc) · 5.99 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#pragma once
#include <datadog/clock.h>
#include <datadog/config.h>
#include <datadog/event_scheduler.h>
#include <datadog/http_client.h>
#include <datadog/logger.h>
#include <datadog/telemetry/configuration.h>
#include <datadog/telemetry/metrics.h>
#include <datadog/tracer_signature.h>
#include <memory>
#include <vector>
/// Telemetry functions are responsibles for handling internal telemetry data to
/// track Datadog product usage. It _can_ collect and report logs and metrics.
///
/// IMPORTANT: This is intended for use only by Datadog Engineers.
namespace datadog::telemetry {
/// Initialize the telemetry module
/// Once initialized, sends a notification indicating that the application has
/// started. The telemetry module is running for the entire lifecycle of the
/// application.
///
/// @param configuration The finalized configuration settings.
/// @param logger User logger instance.
/// @param metrics A vector user metrics to report.
///
/// NOTE: Make sure to call `init` before calling any of the other telemetry
/// functions.
void init(FinalizedConfiguration configuration,
std::shared_ptr<tracing::Logger> logger,
std::shared_ptr<tracing::HTTPClient> client,
std::shared_ptr<tracing::EventScheduler> event_scheduler,
tracing::HTTPClient::URL agent_url,
tracing::Clock clock = tracing::default_clock);
void init(FinalizedConfiguration configuration,
tracing::TracerSignature tracer_signature,
std::shared_ptr<tracing::Logger> logger,
std::shared_ptr<tracing::HTTPClient> client,
std::shared_ptr<tracing::EventScheduler> event_scheduler,
tracing::HTTPClient::URL agent_url,
tracing::Clock clock = tracing::default_clock);
/// Sends configuration changes.
///
/// This function is responsible for sending reported configuration changes
/// reported by `capture_configuration_change`.
///
/// @note This function should be called _AFTER_ all configuration changes are
/// captures by `capture_configuration_change`.
void send_configuration_change();
/// Captures a change in the application's configuration.
///
/// This function is called to report updates to the application's
/// configuration. It takes a vector of new configuration metadata as a
/// parameter, which contains the updated settings.
///
/// @param new_configuration A vector containing the new configuration metadata.
///
/// @note This function should be invoked whenever there is a change in the
/// configuration.
void capture_configuration_change(
const std::vector<tracing::ConfigMetadata>& new_configuration);
/// The `log` namespace provides functions for reporting logs.
namespace log {
/// Report internal warning message to Datadog.
///
/// @param message The warning message to log.
void warning(std::string message);
/// Report internal error message to Datadog.
///
/// @param message The error message.
void error(std::string message);
/// Report internal error message to Datadog.
///
/// @param message The error message.
/// @param stacktrace Stacktrace leading to the error.
void error(std::string message, std::string stacktrace);
} // namespace log
/// The `counter` namespace provides functions to track values.
/// Counters can be useful for tracking the total number of an event occurring
/// in one time interval. For example, the amount of requests, errors or jobs
/// processed every 10 seconds.
namespace counter {
/// Increments the specified counter by 1.
///
/// @param `counter` the counter to increment.
void increment(const Counter& counter);
/// Increments the specified counter by 1.
///
/// @param `counter` the counter to increment.
/// @param `tags` the distribution tags.
void increment(const Counter& counter, const std::vector<std::string>& tags);
/// Decrements the specified counter by 1.
///
/// @param `counter` the counter to decrement.
void decrement(const Counter& counter);
/// Decrements the specified counter by 1.
///
/// @param `counter` the counter to decrement.
/// @param `tags` the distribution tags.
void decrement(const Counter& counter, const std::vector<std::string>& tags);
/// Sets the counter to a specific value.
///
/// @param `counter` the counter to update.
/// @param `value` the value to assign to the counter.
void set(const Counter& counter, uint64_t value);
/// Sets the counter to a specific value.
///
/// @param `counter` the counter to update.
/// @param `tags` the distribution tags.
/// @param `value` the value to assign to the counter.
void set(const Counter& counter, const std::vector<std::string>& tags,
uint64_t value);
} // namespace counter
/// The `rate` namespace provides support for rate metrics-values.
/// Rates can be useful for tracking the total number of an event occurrences in
/// one time interval. For example, the number of requests per second.
namespace rate {
/// Sets the rate to a specific value.
///
/// @param `rate` the rate to update.
/// @param `value` the value to assign to the counter.
void set(const Rate& rate, uint64_t value);
/// Sets the rate to a specific value.
///
/// @param `rate` the rate to update.
/// @param `tags` the distribution tags.
/// @param `value` the value to assign to the counter.
void set(const Rate& rate, const std::vector<std::string>&, uint64_t value);
} // namespace rate
/// The `distribution` namespace provides support for statistical distribution.
/// Distribution can be useful for tracking things like response times or
/// payload sizes.
namespace distribution {
/// Adds a value to the distribution.
///
/// @param `distribution` the distribution to update.
/// @param `value` the value to add to the distribution.
void add(const Distribution& distribution, uint64_t value);
/// Adds a value to the distribution.
///
/// @param `distribution` the distribution to update.
/// @param `tags` the distribution tags.
/// @param `value` the value to add to the distribution.
void add(const Distribution& distribution, const std::vector<std::string>& tags,
uint64_t value);
} // namespace distribution
} // namespace datadog::telemetry