Implement stable session identifier headers for telemetry#295
Implement stable session identifier headers for telemetry#295khanayan123 wants to merge 12 commits intomainfrom
Conversation
Add DD-Session-ID and DD-Root-Session-ID headers to all telemetry requests per the Stable Service Instance Identifier RFC. - DD-Session-ID (= runtime_id) sent on every telemetry request - DD-Root-Session-ID sent only when root != current runtime_id - Root session ID inherited from _DD_ROOT_CPP_SESSION_ID env var (for exec-based child processes) or defaults to first runtime_id - setenv propagates root session ID to exec'd children automatically - Fork propagation is automatic (memory survives fork) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
BenchmarksBenchmark execution time: 2026-03-24 19:26:09 Comparing candidate commit a3b7684 in PR branch Found 0 performance improvements and 1 performance regressions! Performance is the same for 0 metrics, 0 unstable metrics.
|
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Use environment::lookup() instead of std::getenv() directly, and register DD_ROOT_CPP_SESSION_ID in DD_LIST_ENVIRONMENT_VARIABLES per project convention. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
_DD_ROOT_CPP_SESSION_ID is an internal propagation variable not in the public configuration registry. Route it through a new lookup_internal() helper in environment.cpp (the one file allowed to call std::getenv) rather than registering it in DD_LIST_ENVIRONMENT_VARIABLES, which would cause supported-configurations.json to fail remote registry validation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
setenv() is POSIX-only; Windows requires _putenv_s(). Add set_internal() to environment.cpp (the platform-appropriate layer) that uses the right call per platform, and route the tracer's root session ID propagation through it. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace lookup_internal/set_internal (linter-added wrappers) with direct std::getenv and setenv/_putenv_s calls. The _DD_ROOT_CPP_SESSION_ID env var is an internal propagation mechanism and does not belong in the supported config registry. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace direct std::getenv/setenv calls with environment::lookup() and environment::set() via the DD_LIST_ENVIRONMENT_VARIABLES registry. Also add the var to supported-configurations.json. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Read _DD_ROOT_CPP_SESSION_ID in finalize_config() and store it in FinalizedTracerConfig, consistent with how all other env vars are handled. Removes the ad-hoc get_root_session_id() helper in tracer.cpp. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replaces exclusive env var propagation with a shared memory carrier:
- Linux: memfd_create("dd-session-ids") without MFD_CLOEXEC; child
discovers via /proc/self/fd/ scan
- macOS: shm_open("/dd-session-ids-<pid>"); child opens by getppid()
- Windows: CreateFileMapping("Local\dd-session-ids-<pid>"); child
opens by Toolhelp32-resolved parent PID
Tracer creates the carrier on startup and keeps it alive as a member.
finalize_config() prefers SHM on read, falls back to the env var for
interop with SDKs that still use _DD_ROOT_CPP_SESSION_ID.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
SHM is now the sole propagation mechanism. The env var was only ever written and read by C++ itself, so there was no cross-SDK interop value in keeping it. Removes: the registry entry, environment::set(), the write in Tracer constructor, the fallback read in finalize_config, and the supported-configurations.json entry. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
Implements the Stable Service Instance Identifier RFC for the C++ SDK.
DD-Session-ID(=runtime_id) and conditionalDD-Root-Session-IDheaders to all telemetry requests (app-started, heartbeats, app-closing, etc.)DD-Root-Session-IDis only sent when it differs fromDD-Session-ID(i.e., in child processes)_DD_ROOT_CPP_SESSION_IDvia the config registry (environment::lookup) or defaults to the currentruntime_idenvironment::set(_DD_ROOT_CPP_SESSION_ID, ...)is called at tracer init so exec'd children inherit it automatically (no-op if already set)Files changed
include/datadog/environment.h— Added_DD_ROOT_CPP_SESSION_IDtoDD_LIST_ENVIRONMENT_VARIABLESregistry; addedenvironment::set()declarationsrc/datadog/environment.cpp— Addedenvironment::set()implementation (platform-aware, no-overwrite)include/datadog/tracer_signature.h— Addedroot_session_idmember toTracerSignaturesrc/datadog/tracer.cpp— Computes root session ID viaenvironment::lookup; registers it viaenvironment::setfor exec propagationsrc/datadog/telemetry/telemetry_impl.cpp— Adds session headers toapp_started()andsend_payload()supported-configurations.json— Added_DD_ROOT_CPP_SESSION_IDentryCompanion system-tests PR: DataDog/system-tests#6510
Test plan
🤖 Generated with Claude Code