Commit 7b8a6ad
authored
Add DD_RUM_* env var support for RUM configuration (#304)
* Add DD_RUM_* environment variable support for RUM configuration
Add support for configuring RUM via DD_RUM_* environment variables as
fallback defaults. Nginx `datadog_rum_config` directive values always
take precedence over env vars on a per-field basis. When no directive
exists and valid env vars are present, RUM auto-enables.
Environment variables: DD_RUM_ENABLED, DD_RUM_APPLICATION_ID,
DD_RUM_CLIENT_TOKEN, DD_RUM_SITE, DD_RUM_SERVICE, DD_RUM_ENV,
DD_RUM_VERSION, DD_RUM_SESSION_SAMPLE_RATE,
DD_RUM_SESSION_REPLAY_SAMPLE_RATE, DD_RUM_TRACK_RESOURCES,
DD_RUM_TRACK_LONG_TASKS, DD_RUM_TRACK_USER_INTERACTIONS,
DD_RUM_REMOTE_CONFIGURATION_ID.
Precedence rules:
- `datadog_rum on/off` always wins over DD_RUM_ENABLED
- `datadog_rum_config` fields always win over DD_RUM_* env vars
- DD_RUM_ENABLED=false explicitly disables even with config env vars
- Unrecognized DD_RUM_ENABLED values log a warning and skip auto-enable
Also includes:
- Case-insensitive parse_bool() for boolean env var parsing
- Fix std::stod crash with std::strtod for sample rate parsing
- Fix snippet memory leak on config error path
- Guard against rum_enable=1 with null snippet (prevents segfault)
- Null-terminated error messages via ngx_pcalloc
- Empty values vector guard in make_rum_json_config
- Use FetchContent for inject-browser-sdk dependency
- RUM integration tests and C++ unit tests
- RUM CI pipeline in GitLab
* Make rum_env_mappings constexpr and rename DD_RUM_VERSION to DD_RUM_MAJOR_VERSION
Move rum_env_mappings definition into config_internal.h as an
inline constexpr std::to_array, eliminating the separate
rum_env_mappings_size variable in favor of .size(). Rename
DD_RUM_VERSION to DD_RUM_MAJOR_VERSION.
* Use range-based for with structured bindings for rum_env_mappings loops
Replace index-based iteration with range-based for and structured
bindings. Also simplify std::getenv call to use string_view::data()
directly instead of constructing a temporary std::string.
* Extract conf_err() helper to combine error buffer allocation and formatting
Replace repeated alloc_err_buf + ngx_snprintf pairs with a single
conf_err() variadic template. Also fix "Rust SDK" comment to "RUM SDK"
and use static_cast for C-style casts.
* Name magic number 5 as default_rum_config_version constant
* Use RAII for Snippet lifetime and minor cleanups
Wrap snippet_create_from_json in unique_ptr with snippet_cleanup
deleter to ensure cleanup on all paths including exceptions. Also
rename catch variable from 'e' to 'exception'.
* Extract try_build_snippet_from_env() from merge_loc_config
Reduce nesting by moving the env-based snippet construction into its
own function with early returns.
* Extract resolve_rum_enable_from_env() from merge_loc_config
Move the DD_RUM_ENABLED resolution logic into its own function with
early returns to reduce nesting.
* Rename environment_variable_names to get_environment_variable_names
Use a verb prefix for the rum namespace function, and simplify
bool-to-ngx_flag_t conversion with static_cast.
* Fix env var name mismatch in tests and UB in conf_err call
Update tests and docker-compose to use DD_RUM_ENVIRONMENT and
DD_RUM_MAJOR_VERSION matching the mapping table. Convert string_view
to std::string before passing to variadic ngx_snprintf to avoid UB.
* Improve error handling and fix silent failures in RUM config
- Add NULL check in conf_err for ngx_pcalloc failure
- Log warning when json.empty() after env vars were read
- Rethrow std::bad_alloc instead of swallowing it; fix misleading
catch message
- Pass unrecognized boolean values as strings to RUM SDK instead of
silently defaulting to false
- Refactor resolve_rum_enable_from_env to read getenv once
* Fix RUM build: reinterpret_cast for u_char* and add string_view_literals
- Use reinterpret_cast instead of static_cast for char* to u_char*
conversion in conf_err (clang rejects static_cast between unrelated types)
- Add `using namespace std::string_view_literals` so the `sv` suffix
is available for the DD_RUM_ENABLED string literal
* Fix GHA build: allow overriding base image to bypass internal registry mirror
The GitHub Actions runners have registry.ddbuild.io configured as a Docker
mirror, but can't reach it. Parametrize the base image via ARG so GHA can
use the public alpine:3.20.3 instead.
* Address GitLab CI review comments: reorder and expand RUM jobs
- Move .build-nginx-rum template after .build-nginx in common.yml
- Group build-nginx-rum-fast with other build jobs in build-and-test-fast.yml
- Expand RUM version matrix to cover all major versions (1.24, 1.25, 1.26, 1.27, 1.28, 1.29)
- Move build-nginx-rum-all/test-nginx-rum-all inline with other jobs in build-and-test-all.yml
- Add missing 1.25.5 and 1.27.5 to the all-versions RUM matrix
* Address C++ review comments in rum/config.cpp
- Rename single-letter loop variable `e` to `entry`
- Extract duplicated tag-setting logic into apply_rum_config_tags() helper
* Address review comments: nits and consistency fixes
- Makefile: add space before $(if for readability
- config_internal.h: add rum_config_map type alias; use in signatures
- config.cpp: use values.front() instead of values[0] throughout
- config.cpp: fix misleading version error message (vN not v5)
- test_rum_config.cpp: group rapidjson include with other third-party includes
- test_injection.py: replace bare assert with self.assertXxx() for consistency
* Fix: restore arg_values[0] for ngx_str_t* pointer (not a vector)1 parent 697ea42 commit 7b8a6ad
25 files changed
Lines changed: 1374 additions & 152 deletions
File tree
- .github/workflows
- .gitlab
- build_env
- deps
- src
- rum
- test
- cases
- rum
- conf
- services/nginx
- unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
57 | 73 | | |
58 | 74 | | |
59 | 75 | | |
| |||
237 | 253 | | |
238 | 254 | | |
239 | 255 | | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
240 | 287 | | |
241 | 288 | | |
242 | 289 | | |
| |||
296 | 343 | | |
297 | 344 | | |
298 | 345 | | |
| 346 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
65 | 81 | | |
66 | 82 | | |
67 | 83 | | |
| |||
121 | 137 | | |
122 | 138 | | |
123 | 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 | + | |
124 | 172 | | |
125 | 173 | | |
126 | 174 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
20 | 33 | | |
21 | 34 | | |
22 | 35 | | |
| |||
51 | 64 | | |
52 | 65 | | |
53 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
54 | 77 | | |
55 | 78 | | |
56 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
118 | 128 | | |
119 | 129 | | |
120 | 130 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
4 | 5 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
9 | 10 | | |
| 11 | + | |
10 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
116 | 119 | | |
117 | 120 | | |
118 | 121 | | |
| |||
340 | 343 | | |
341 | 344 | | |
342 | 345 | | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
343 | 353 | | |
344 | 354 | | |
345 | 355 | | |
| |||
0 commit comments