Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitlab/build-and-test-fast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ lint:

shellcheck:
extends: .build-and-test-fast
image: $CI_REGISTRY/nginx_musl_toolchain
image: $CI_REGISTRY/nginx_musl_toolchain:rust-1.85
tags: ["arch:amd64"]
script:
- find bin/ test/ example/ .gitlab/ -type f \( \( -executable -not -name '*.py' \) -o -name '*.sh' \) | xargs shellcheck --exclude SC1071,SC1091,SC2317
Expand Down Expand Up @@ -99,6 +99,7 @@ build-nginx-rum-fast:
- "1.26.3"
- "1.27.5"
- "1.28.2"
- "1.29.5"
- "1.29.6"
WAF: ["OFF"]

Expand Down Expand Up @@ -191,6 +192,10 @@ test-nginx-rum-fast:
BASE_IMAGE: ["nginx:1.28.2"]
NGINX_VERSION: ["1.28.2"]
WAF: ["OFF"]
- ARCH: ["amd64", "arm64"]
BASE_IMAGE: ["nginx:1.29.5"]
NGINX_VERSION: ["1.29.5"]
WAF: ["OFF"]
- ARCH: ["amd64", "arm64"]
BASE_IMAGE: ["nginx:1.29.6"]
NGINX_VERSION: ["1.29.6"]
Expand Down
2 changes: 1 addition & 1 deletion .gitlab/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ variables:

.build:
extends: .git-config
image: $CI_REGISTRY/nginx_musl_toolchain
image: $CI_REGISTRY/nginx_musl_toolchain:rust-1.85
tags: ["arch:$ARCH"]
variables:
MAKE_JOB_COUNT: "8"
Expand Down
2 changes: 1 addition & 1 deletion .gitlab/ssi-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

.ssi-assemble:
extends: .git-config
image: registry.ddbuild.io/ci/nginx-datadog/nginx_musl_toolchain
image: registry.ddbuild.io/ci/nginx-datadog/nginx_musl_toolchain:rust-1.85
stage: build
parallel:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion build_env/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ RUN apk add --no-cache openssl-dev pcre-dev pcre2-dev perl zlib-dev

# Rust toolchain
RUN apk add --no-cache curl
RUN curl --proto '=https' –tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -yq --default-toolchain 1.73.0 && \
RUN curl --proto '=https' –tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -yq --default-toolchain 1.85.0 && \
ln -s ~/.cargo/bin/cargo /usr/bin/cargo

RUN cargo install --locked cbindgen --version 0.26.0 && \
Expand Down
15 changes: 14 additions & 1 deletion deps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
include(FetchContent)

set(INJECT_BROWSER_SDK_GIT_REF "49245e1c6ed8275990bb910125187e0aaad09e3d" CACHE STRING
set(INJECT_BROWSER_SDK_GIT_REF "f509450" CACHE STRING
"Git tag/branch for inject-browser-sdk")

set(INJECT_BROWSER_SDK_NO_DEFAULT_FEATURES OFF CACHE BOOL
"Build inject-browser-sdk without default features")

FetchContent_Declare(
InjectBrowserSDK
GIT_REPOSITORY https://github.com/DataDog/inject-browser-sdk.git
GIT_TAG ${INJECT_BROWSER_SDK_GIT_REF}
)
FetchContent_MakeAvailable(InjectBrowserSDK)

# Pass cross-compilation sysroot/target flags to Rust cc crate builds
# (e.g. aws-lc-sys) that invoke the C compiler via CFLAGS.
if(CMAKE_SYSROOT AND CMAKE_C_COMPILER_TARGET AND COMMAND corrosion_set_env_vars)
set(_cross_flags "--sysroot=${CMAKE_SYSROOT} --target=${CMAKE_C_COMPILER_TARGET} -fuse-ld=lld -rtlib=compiler-rt")
corrosion_set_env_vars(inject_browser_sdk_ffi
"CFLAGS_x86_64_unknown_linux_musl=${_cross_flags}"
"CFLAGS_aarch64_unknown_linux_musl=${_cross_flags}"
)
endif()

if(NOT TARGET inject_browser_sdk)
add_library(inject_browser_sdk ALIAS inject_browser_sdk_ffi)
endif()
72 changes: 47 additions & 25 deletions src/rum/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,35 @@ rum_config_map get_rum_config_from_env() {
return config;
}

rum_config_map get_rum_config_from_stable_config() {
rum_config_map config;

auto entries = std::unique_ptr<StableConfigEntries,
decltype(&stable_config_entries_cleanup)>(
stable_config_get_entries("browser-sdk", false),
stable_config_entries_cleanup);

if (entries == nullptr || entries->error_code) {
return config;
}

for (uint32_t i = 0; i < entries->count; ++i) {
const char* name = entries->entries[i].name;
const char* value = entries->entries[i].value;
if (name == nullptr || value == nullptr || value[0] == '\0') continue;

std::string_view name_sv(name);
for (const auto& [env_name, config_key] : rum_env_mappings) {
if (name_sv == env_name) {
config[std::string(config_key)] = {std::string(value)};
break;
}
}
}

return config;
}

std::optional<bool> get_rum_enabled_from_env() {
const char* value = std::getenv("DD_RUM_ENABLED");
if (value == nullptr || value[0] == '\0') {
Expand Down Expand Up @@ -209,7 +238,7 @@ char* on_datadog_rum_config(ngx_conf_t* cf, ngx_command_t* command,
arg1_str.c_str());
}

auto rum_config = get_rum_config_from_env();
auto rum_config = get_rum_config_from_stable_config();

ngx_conf_t save = *cf;
cf->handler = set_config;
Expand Down Expand Up @@ -244,37 +273,33 @@ char* on_datadog_rum_config(ngx_conf_t* cf, ngx_command_t* command,
void try_build_snippet_from_env(ngx_conf_t* cf,
datadog::nginx::datadog_loc_conf_t* loc_conf) {
try {
auto env_config = get_rum_config_from_env();
if (env_config.empty()) return;

auto json = make_rum_json_config(default_rum_config_version, env_config);
if (json.empty()) {
ngx_log_error(
NGX_LOG_WARN, cf->log, 0,
"nginx-datadog: DD_RUM_* environment variables were set but "
"JSON config generation produced an empty result");
return;
}

auto snippet = std::unique_ptr<Snippet, decltype(&snippet_cleanup)>(
snippet_create_from_json(json.c_str()), snippet_cleanup);
snippet_create_from_stable_config("browser-sdk", false),
snippet_cleanup);

if (snippet == nullptr || snippet->error_code) {
ngx_log_error(NGX_LOG_WARN, cf->log, 0,
"nginx-datadog: failed to create RUM snippet from "
"environment variables: %s",
"stable config: %s",
snippet ? snippet->error_message : "null snippet");
return;
}

loc_conf->rum_snippet = snippet.release();
apply_rum_config_tags(loc_conf, env_config);
// Telemetry tags: best-effort from env (snippet is opaque)
const char* app_id = std::getenv("DD_RUM_APPLICATION_ID");
if (app_id && app_id[0] != '\0') {
loc_conf->rum_application_id_tag =
std::string("application_id:") + app_id;
}
loc_conf->rum_remote_config_tag = "remote_config_used:false";
} catch (const std::bad_alloc&) {
throw;
} catch (const std::exception& exception) {
ngx_log_error(NGX_LOG_WARN, cf->log, 0,
"nginx-datadog: failed to build RUM snippet from environment "
"variables: %s",
exception.what());
} catch (const std::exception& e) {
ngx_log_error(
NGX_LOG_WARN, cf->log, 0,
"nginx-datadog: failed to build RUM snippet from stable config: %s",
e.what());
}
}

Expand Down Expand Up @@ -346,11 +371,8 @@ char* datadog_rum_merge_loc_config(ngx_conf_t* cf,

std::vector<std::string_view> get_environment_variable_names() {
std::vector<std::string_view> names;
names.reserve(rum_env_mappings.size() + 1);
names.push_back("DD_RUM_ENABLED"sv);
for (const auto& [env_name, config_key] : rum_env_mappings) {
names.push_back(env_name);
}
names.push_back("DD_RUM_APPLICATION_ID"sv); // for telemetry tags
return names;
}

Expand Down
2 changes: 2 additions & 0 deletions src/rum/config_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ using rum_config_map =

rum_config_map get_rum_config_from_env();

rum_config_map get_rum_config_from_stable_config();

std::optional<bool> get_rum_enabled_from_env();

std::string make_rum_json_config(int config_version,
Expand Down
Loading
Loading