Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

pablomartinezbernardo
Copy link
Collaborator

@pablomartinezbernardo pablomartinezbernardo commented Apr 25, 2025

Add RUM telemetry:

  • All already existing metrics
  • Including CSP
  • Application id and remote config tags

@codecov-commenter
Copy link

codecov-commenter commented Apr 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.25%. Comparing base (a2e2d29) to head (e9bb286).

Additional details and impacted files

Impacted file tree graph

@@           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           
Files with missing lines Coverage Δ
src/datadog_context.cpp 61.79% <ø> (ø)
src/ngx_http_datadog_module.cpp 70.11% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pablomartinezbernardo pablomartinezbernardo marked this pull request as ready for review April 25, 2025 12:52
@pablomartinezbernardo pablomartinezbernardo requested a review from a team as a code owner April 25, 2025 12:52
@pablomartinezbernardo pablomartinezbernardo requested review from dmehala and removed request for a team April 25, 2025 12:52
Comment on lines 13 to 16
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;
Copy link
Contributor

@dmehala dmehala Apr 26, 2025

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?


const std::vector<std::string>& get_common_tags();

void increment_counter(const datadog::telemetry::Counter& counter,
Copy link
Contributor

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;
}

@@ -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;
Copy link
Contributor

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.

Comment on lines 231 to 234
telemetry::increment_counter(telemetry::injection_failed,
{"reason:missing_header_tag",
"application_id:" + cfg->rum_application_id,
"remote_config_used:" + cfg->remote_config});
Copy link
Contributor

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.

Comment on lines 175 to 183
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;
}
Copy link
Contributor

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.

Comment on lines 216 to 217
std::string rum_application_id;
std::string remote_config;
Copy link
Contributor

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.

Comment on lines 168 to 177
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";
Copy link
Contributor

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>

@pablomartinezbernardo pablomartinezbernardo marked this pull request as draft April 28, 2025 08:40
@pablomartinezbernardo pablomartinezbernardo force-pushed the pmartinez/rum-app-id-rc-tags branch from 517011d to 7b98a5d Compare April 28, 2025 09:50
@pablomartinezbernardo pablomartinezbernardo marked this pull request as ready for review April 28, 2025 09:54
Copy link
Contributor

@dmehala dmehala left a 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.

Comment on lines 168 to 179
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");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

}

return output(r, output_chain, next_body_filter);
}

ngx_int_t InjectionHandler::on_log_request(ngx_http_request_t *r) {
if (rum_first_csp_) {
Copy link
Contributor

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?

Comment on lines 72 to 73
// @param r - HTTP request being processed.
ngx_int_t on_log_request(ngx_http_request_t *r);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// @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);

Comment on lines 17 to 26
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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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()));

namespace telemetry {

template <typename... T>
auto build_telemetry_tags(T&&... specific_tags) {
Copy link
Contributor

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?

@pablomartinezbernardo
Copy link
Collaborator Author

All comments addressed

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.

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.

@pablomartinezbernardo pablomartinezbernardo force-pushed the pmartinez/rum-app-id-rc-tags branch from 1e3fee9 to e9bb286 Compare May 5, 2025 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants