Skip to content

Commit dca35bd

Browse files
authored
[part 7] refactor!(telemetry): improve telemetry lifecycle (#205)
Changes: - add support for install_signature. - add support for product in configuration that will be reported in app-started message. - unit tests
1 parent c85660b commit dca35bd

File tree

14 files changed

+361
-168
lines changed

14 files changed

+361
-168
lines changed

BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ cc_library(
119119
"include/datadog/telemetry/configuration.h",
120120
"include/datadog/telemetry/metrics.h",
121121
"include/datadog/telemetry/telemetry.h",
122+
"include/datadog/telemetry/product.h",
122123
"include/datadog/remote_config/capability.h",
123124
"include/datadog/remote_config/listener.h",
124125
"include/datadog/remote_config/product.h",

include/datadog/environment.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ namespace environment {
5656
MACRO(DD_TELEMETRY_DEBUG) \
5757
MACRO(DD_TRACE_BAGGAGE_MAX_ITEMS) \
5858
MACRO(DD_TRACE_BAGGAGE_MAX_BYTES) \
59-
MACRO(DD_TELEMETRY_LOG_COLLECTION_ENABLED)
59+
MACRO(DD_TELEMETRY_LOG_COLLECTION_ENABLED) \
60+
MACRO(DD_INSTRUMENTATION_INSTALL_ID) \
61+
MACRO(DD_INSTRUMENTATION_INSTALL_TYPE) \
62+
MACRO(DD_INSTRUMENTATION_INSTALL_TIME)
6063

6164
#define WITH_COMMA(ARG) ARG,
6265

include/datadog/telemetry/configuration.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#pragma once
22

3+
#include <datadog/config.h>
34
#include <datadog/expected.h>
45
#include <datadog/optional.h>
6+
#include <datadog/telemetry/product.h>
57

68
#include <chrono>
79
#include <string>
10+
#include <vector>
811

912
namespace datadog::telemetry {
1013

@@ -38,6 +41,8 @@ struct Configuration {
3841
// Can be overriden by the `DD_TELEMETRY_LOG_COLLECTION_ENABLED` environment
3942
// variable.
4043
tracing::Optional<bool> report_logs;
44+
// List of products reported in the `app-started` message.
45+
std::vector<Product> products;
4146
};
4247

4348
struct FinalizedConfiguration {
@@ -49,6 +54,13 @@ struct FinalizedConfiguration {
4954
std::chrono::steady_clock::duration heartbeat_interval;
5055
std::string integration_name;
5156
std::string integration_version;
57+
std::vector<Product> products;
58+
59+
// Onboarding metadata coming from `DD_INSTRUMENTATION_INSTALL_*` environment
60+
// variables.
61+
tracing::Optional<std::string> install_id;
62+
tracing::Optional<std::string> install_type;
63+
tracing::Optional<std::string> install_time;
5264

5365
friend tracing::Expected<FinalizedConfiguration> finalize_config(
5466
const Configuration&);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#pragma once
2+
3+
#include <datadog/config.h>
4+
#include <datadog/optional.h>
5+
6+
#include <string>
7+
#include <unordered_map>
8+
9+
namespace datadog::telemetry {
10+
11+
/// Represents a single product and its associated metadata.
12+
struct Product final {
13+
enum class Name : char {
14+
tracing,
15+
appsec,
16+
profiler,
17+
mlobs,
18+
live_debugger,
19+
rum,
20+
};
21+
22+
/// The product name identifier from one of the possible values above.
23+
Name name;
24+
/// Flag indicating if the product is currently enabled.
25+
bool enabled;
26+
/// The version string of the product.
27+
std::string version;
28+
/// Optional error code related to the product status.
29+
tracing::Optional<int> error_code;
30+
/// Optional error message related to the product status.
31+
tracing::Optional<std::string> error_message;
32+
/// Map of configuration settings for the product.
33+
std::unordered_map<tracing::ConfigName, tracing::ConfigMetadata>
34+
configurations;
35+
};
36+
37+
inline std::string_view to_string(Product::Name product) {
38+
switch (product) {
39+
case Product::Name::tracing:
40+
return "tracing";
41+
case Product::Name::appsec:
42+
return "appsec";
43+
case Product::Name::profiler:
44+
return "profiler";
45+
case Product::Name::mlobs:
46+
return "mlobs";
47+
case Product::Name::live_debugger:
48+
return "live_debugger";
49+
case Product::Name::rum:
50+
return "rum";
51+
}
52+
53+
// unreachable.
54+
return "";
55+
}
56+
57+
} // namespace datadog::telemetry

include/datadog/telemetry/telemetry.h

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <datadog/telemetry/metrics.h>
1010

1111
#include <memory>
12-
#include <unordered_map>
1312
#include <vector>
1413

1514
/// Telemetry functions are responsibles for handling internal telemetry data to
@@ -19,8 +18,9 @@
1918
namespace datadog::telemetry {
2019

2120
/// Initialize the telemetry module
22-
/// Once initialized, the telemetry module is running for the entier lifecycle
23-
/// of the application.
21+
/// Once initialized, sends a notification indicating that the application has
22+
/// started. The telemetry module is running for the entire lifecycle of the
23+
/// application.
2424
///
2525
/// @param configuration The finalized configuration settings.
2626
/// @param logger User logger instance.
@@ -36,21 +36,6 @@ void init(FinalizedConfiguration configuration,
3636
tracing::HTTPClient::URL agent_url,
3737
tracing::Clock clock = tracing::default_clock);
3838

39-
/// Sends a notification indicating that the application has started.
40-
///
41-
/// This function is responsible for reporting the application has successfully
42-
/// started. It takes a configuration map as a parameter, which contains various
43-
/// configuration settings helping to understand how our product are used.
44-
///
45-
/// @param conf A map containing configuration names and their corresponding
46-
/// metadata.
47-
///
48-
/// @note This function should be called after the application has completed its
49-
/// initialization process to ensure that all components are aware of the
50-
/// application's startup status.
51-
void send_app_started(const std::unordered_map<tracing::ConfigName,
52-
tracing::ConfigMetadata>& conf);
53-
5439
/// Sends configuration changes.
5540
///
5641
/// This function is responsible for sending reported configuration changes

src/datadog/telemetry/configuration.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ tracing::Expected<FinalizedConfiguration> finalize_config(
122122
pick(env_config->integration_version, user_config.integration_version,
123123
tracing::tracer_version);
124124

125+
// products
126+
result.products = user_config.products;
127+
128+
// onboarding data
129+
if (auto install_id = lookup(environment::DD_INSTRUMENTATION_INSTALL_ID)) {
130+
result.install_id = std::string(*install_id);
131+
}
132+
if (auto install_type =
133+
lookup(environment::DD_INSTRUMENTATION_INSTALL_TYPE)) {
134+
result.install_type = std::string(*install_type);
135+
}
136+
if (auto install_time =
137+
lookup(environment::DD_INSTRUMENTATION_INSTALL_TIME)) {
138+
result.install_time = std::string(*install_time);
139+
}
140+
125141
return result;
126142
}
127143

src/datadog/telemetry/telemetry.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,6 @@ void init(FinalizedConfiguration configuration,
6161
agent_url, clock});
6262
}
6363

64-
void send_app_started(const std::unordered_map<tracing::ConfigName,
65-
tracing::ConfigMetadata>& conf) {
66-
std::visit(
67-
details::Overload{
68-
[&](Telemetry& telemetry) { telemetry.send_app_started(conf); },
69-
[](NoopTelemetry) {},
70-
},
71-
instance());
72-
}
73-
7464
void send_configuration_change() {
7565
std::visit(
7666
details::Overload{

0 commit comments

Comments
 (0)