-
Notifications
You must be signed in to change notification settings - Fork 10
RUM telemetry #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
RUM telemetry #204
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #204 +/- ##
=======================================
Coverage 71.25% 71.25%
=======================================
Files 49 49
Lines 6356 6356
Branches 903 903
=======================================
Hits 4529 4529
Misses 1378 1378
Partials 449 449
🚀 New features to boost your workflow:
|
src/rum/telemetry.h
Outdated
extern datadog::telemetry::Counter injection_skipped; | ||
extern datadog::telemetry::Counter injection_succeed; | ||
extern datadog::telemetry::Counter injection_failed; | ||
extern datadog::telemetry::Counter content_security_policy; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add const
here to clarify that this isn't intended to be modified?
src/rum/telemetry.h
Outdated
|
||
const std::vector<std::string>& get_common_tags(); | ||
|
||
void increment_counter(const datadog::telemetry::Counter& counter, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make it clearer for the reader, it would be better to avoid reusing the same telemetry function name. Instead, you could expose a function to build the telemetry tags, for example
template <typename... T>
auto build_telemetry_tags(T&&... tags) {
std::vector<std::string> tags{std::forward<T>(args)...};
tags.emplace_back("integration_name:nginx");
...
return tags;
}
src/rum/injection.h
Outdated
@@ -32,6 +32,7 @@ class InjectionHandler final { | |||
|
|||
// A flag indicating whether padding should be added to the HTML responses. | |||
bool output_padding_; | |||
bool rum_first_csp_ = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove once getteing the csp header is done after process the request.
src/rum/injection.cpp
Outdated
telemetry::increment_counter(telemetry::injection_failed, | ||
{"reason:missing_header_tag", | ||
"application_id:" + cfg->rum_application_id, | ||
"remote_config_used:" + cfg->remote_config}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider building the application_id and remote_config_used tags once, rather than recreating them each time.
src/rum/injection.cpp
Outdated
if (rum_first_csp_) { | ||
if (auto csp = | ||
search_header(r->headers_out.headers, "content-security-policy"); | ||
csp != nullptr) { | ||
telemetry::increment_counter(telemetry::content_security_policy, | ||
{"status:seen", "kind:header"}); | ||
} | ||
rum_first_csp_ = false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to move this to after the request is fully processed, inside on_log_request
.
src/datadog_conf.h
Outdated
std::string rum_application_id; | ||
std::string remote_config; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider using these to build the tag, and renaming it to something more descriptive to make it clearer for the reader. also consider initializing these.
src/rum/config.cpp
Outdated
loc_conf->rum_application_id = ""; | ||
if (rum_config.count("applicationId") > 0 && | ||
!rum_config["applicationId"].empty()) { | ||
loc_conf->rum_application_id = rum_config["applicationId"][0]; | ||
} | ||
|
||
loc_conf->remote_config = (rum_config.count("remoteConfigurationId") > 0 && | ||
!rum_config["remoteConfigurationId"].empty()) | ||
? "true" | ||
: "false"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better to use find
here instead. Since these are only used for telemetry tags, consider building the tags directly here or at each call to telemetry::counter::X
>
517011d
to
7b98a5d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add few comments that should be addressed. This PR has a dependency on dd-trace-cpp
. Please note that it cannot be approved/merged until dd-trace-cpp
is upgraded.
src/rum/config.cpp
Outdated
auto it_app_id = rum_config.find("applicationId"); | ||
loc_conf->rum_application_id_tag = | ||
"application_id:" + | ||
((it_app_id != rum_config.end() && !it_app_id->second.empty()) | ||
? it_app_id->second[0] | ||
: std::string("N/A")); | ||
|
||
auto it_remote_config = rum_config.find("remoteConfigurationId"); | ||
bool remote_config_present = (it_remote_config != rum_config.end() && | ||
!it_remote_config->second.empty()); | ||
loc_conf->rum_remote_config_tag = | ||
"remote_config_used:" + | ||
std::string(remote_config_present ? "true" : "false"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto it_app_id = rum_config.find("applicationId"); | |
loc_conf->rum_application_id_tag = | |
"application_id:" + | |
((it_app_id != rum_config.end() && !it_app_id->second.empty()) | |
? it_app_id->second[0] | |
: std::string("N/A")); | |
auto it_remote_config = rum_config.find("remoteConfigurationId"); | |
bool remote_config_present = (it_remote_config != rum_config.end() && | |
!it_remote_config->second.empty()); | |
loc_conf->rum_remote_config_tag = | |
"remote_config_used:" + | |
std::string(remote_config_present ? "true" : "false"); | |
loc_conf->rum_application_id_tag = "application_id:N/A"; | |
loc_conf->rum_remote_config_tag = "remote_config_used:false"; | |
if (auto it = rum_config.find("applicationId"); it != rum_config.cend() && !it->second.empty()) { | |
loc_conf->rum_application_id_tag = "application_id:" + it_app_id->second; | |
} | |
if (auto it = rum_config.find("remoteConfigurationId"); it != rum_config.cend() && !it->second.empty()) { | |
loc_conf->rum_remote_config_tag = true; | |
} |
I would even argue to set the default rum_application_id_tag
and rum_remote_config_tag
during the loc_conf init.
src/rum/injection.cpp
Outdated
} | ||
|
||
return output(r, output_chain, next_body_filter); | ||
} | ||
|
||
ngx_int_t InjectionHandler::on_log_request(ngx_http_request_t *r) { | ||
if (rum_first_csp_) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC on_log_request
is designed to be called only once per request. May I suggest to remove this check?
src/rum/injection.h
Outdated
// @param r - HTTP request being processed. | ||
ngx_int_t on_log_request(ngx_http_request_t *r); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// @param r - HTTP request being processed. | |
ngx_int_t on_log_request(ngx_http_request_t *r); | |
// @param r - HTTP request being processed. | |
// @return ngx_int_t - Status code indicating success or failure. | |
ngx_int_t on_log_request(ngx_http_request_t *r); |
src/rum/telemetry.h
Outdated
static const std::vector<std::string> common_tags = { | ||
"integration_name:nginx", | ||
std::format("integration_version:{}", | ||
std::string(datadog_semver_nginx_mod)), | ||
"injector_version:0.1.0"}; | ||
|
||
std::vector<std::string> tags{std::forward<T>(specific_tags)...}; | ||
|
||
tags.reserve(tags.size() + common_tags.size()); | ||
tags.insert(tags.end(), common_tags.begin(), common_tags.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static const std::vector<std::string> common_tags = { | |
"integration_name:nginx", | |
std::format("integration_version:{}", | |
std::string(datadog_semver_nginx_mod)), | |
"injector_version:0.1.0"}; | |
std::vector<std::string> tags{std::forward<T>(specific_tags)...}; | |
tags.reserve(tags.size() + common_tags.size()); | |
tags.insert(tags.end(), common_tags.begin(), common_tags.end()); | |
std::vector<std::string> tags{std::forward<T>(specific_tags)...}; | |
tags.emplace_back("integration_name:nginx"); | |
tags.emplace_back("injector_version:0.1.0"); | |
tags.emplace_back(std::format("integration_version:{}", datadog_semver_nginx_mod.c_str())); |
src/rum/telemetry.h
Outdated
namespace telemetry { | ||
|
||
template <typename... T> | ||
auto build_telemetry_tags(T&&... specific_tags) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that the term 'telemetry' appears both in the name and the namespace, which might be redundant. Would you consider renaming it to build_tags
to improve clarity?
All comments addressed
Does this mean you are expecting dd-trace-cpp to be upgraded in this same PR? Or that given there's ongoing work in dd-trace-cpp then this has to wait? Given RUM is not being built by default, I was leaving upgrading dd-trace-cpp up to you, and upgrading it only in the RUM branch testing it for RUM. |
1e3fee9
to
e9bb286
Compare
Add RUM telemetry: