From 924749ba1e55aeb0414e3a200d5adc5d05ecef71 Mon Sep 17 00:00:00 2001 From: "cliford.shelton" Date: Tue, 10 Nov 2026 13:47:56 -0500 Subject: [PATCH 1/2] feat(traces): relay feature flag events through the EVP proxy Tracers send feature flag evaluations and exposures as Event Platform events. They use a local EVP proxy only when /info advertises the bare /evp_proxy/v2/ path and evp_proxy_allowed_headers with DD-EVP-ORIGIN and DD-EVP-ORIGIN-VERSION; otherwise they send directly, which needs DD_API_KEY. With only DD_API_KEY_SECRET_ARN, those events were dropped. - Advertise /evp_proxy/v2/ and the two allowed headers in /info. - Route /evp_proxy/v2/api/v2/{flagevaluation,exposures} to event-platform-intake through the existing store-and-forward proxy, which adds the API key at flush. - v4 is not advertised, so tracers use v2. - Unrouted EVP paths keep returning 404, so tracers that match the base path by prefix send that data directly. Based on Aaron Silverman's patch from datadog-lambda-python#872. SVLS-10112 Co-Authored-By: Aaron Silverman Co-Authored-By: Claude Opus 5.5 --- bottlecap/src/traces/trace_agent.rs | 127 ++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/bottlecap/src/traces/trace_agent.rs b/bottlecap/src/traces/trace_agent.rs index c002ff20f..bcf4217e6 100644 --- a/bottlecap/src/traces/trace_agent.rs +++ b/bottlecap/src/traces/trace_agent.rs @@ -66,6 +66,10 @@ const LLM_OBS_EVAL_METRIC_ENDPOINT_PATH: &str = "/evp_proxy/v2/api/intake/llm-ob const LLM_OBS_EVAL_METRIC_ENDPOINT_PATH_V2: &str = "/evp_proxy/v2/api/intake/llm-obs/v2/eval-metric"; const LLM_OBS_SPANS_ENDPOINT_PATH: &str = "/evp_proxy/v2/api/v2/llmobs"; +// Some tracers need this base path in /info before they use EVP proxy routes. +const EVP_PROXY_V2_BASE_PATH: &str = "/evp_proxy/v2/"; +const FFE_FLAG_EVALUATION_ENDPOINT_PATH: &str = "/evp_proxy/v2/api/v2/flagevaluation"; +const FFE_EXPOSURES_ENDPOINT_PATH: &str = "/evp_proxy/v2/api/v2/exposures"; const INFO_ENDPOINT_PATH: &str = "/info"; const V1_DEBUGGER_ENDPOINT_PATH: &str = "/debugger/v1/input"; const V2_DEBUGGER_ENDPOINT_PATH: &str = "/debugger/v2/input"; @@ -75,6 +79,8 @@ const INSTRUMENTATION_ENDPOINT_PATH: &str = "/telemetry/proxy/api/v2/apmtelemetr // Intake endpoints const DSM_INTAKE_PATH: &str = "/api/v0.1/pipeline_stats"; const LLM_OBS_SPANS_INTAKE_PATH: &str = "/api/v2/llmobs"; +const FFE_FLAG_EVALUATION_INTAKE_PATH: &str = "/api/v2/flagevaluation"; +const FFE_EXPOSURES_INTAKE_PATH: &str = "/api/v2/exposures"; const LLM_OBS_EVAL_METRIC_INTAKE_PATH: &str = "/api/intake/llm-obs/v1/eval-metric"; const LLM_OBS_EVAL_METRIC_INTAKE_PATH_V2: &str = "/api/intake/llm-obs/v2/eval-metric"; const PROFILING_INTAKE_PATH: &str = "/api/v2/profile"; @@ -481,6 +487,11 @@ impl TraceAgent { post(Self::llm_obs_eval_metric_proxy_v2), ) .route(LLM_OBS_SPANS_ENDPOINT_PATH, post(Self::llm_obs_spans_proxy)) + .route( + FFE_FLAG_EVALUATION_ENDPOINT_PATH, + post(Self::ffe_flag_evaluation_proxy), + ) + .route(FFE_EXPOSURES_ENDPOINT_PATH, post(Self::ffe_exposures_proxy)) .route(V1_DEBUGGER_ENDPOINT_PATH, post(Self::debugger_logs_proxy)) .route(V2_DEBUGGER_ENDPOINT_PATH, post(Self::debugger_intake_proxy)) .route( @@ -623,6 +634,33 @@ impl TraceAgent { .await } + async fn ffe_flag_evaluation_proxy( + State(state): State, + request: Request, + ) -> Response { + Self::handle_proxy( + state.config, + state.proxy_aggregator, + request, + "event-platform-intake", + FFE_FLAG_EVALUATION_INTAKE_PATH, + "ffe_flag_evaluation", + ) + .await + } + + async fn ffe_exposures_proxy(State(state): State, request: Request) -> Response { + Self::handle_proxy( + state.config, + state.proxy_aggregator, + request, + "event-platform-intake", + FFE_EXPOSURES_INTAKE_PATH, + "ffe_exposures", + ) + .await + } + // Used for `/debugger/v1/input` in Exception Replay async fn debugger_logs_proxy(State(state): State, request: Request) -> Response { Self::handle_proxy( @@ -675,10 +713,15 @@ impl TraceAgent { LLM_OBS_EVAL_METRIC_ENDPOINT_PATH, LLM_OBS_EVAL_METRIC_ENDPOINT_PATH_V2, LLM_OBS_SPANS_ENDPOINT_PATH, + EVP_PROXY_V2_BASE_PATH, + FFE_FLAG_EVALUATION_ENDPOINT_PATH, + FFE_EXPOSURES_ENDPOINT_PATH, V1_DEBUGGER_ENDPOINT_PATH, V2_DEBUGGER_ENDPOINT_PATH, DEBUGGER_DIAGNOSTICS_ENDPOINT_PATH, ], + // handle_proxy forwards request headers; tracers check these before using EVP. + "evp_proxy_allowed_headers": ["DD-EVP-ORIGIN", "DD-EVP-ORIGIN-VERSION"], "client_drop_p0s": false, } ); @@ -1324,4 +1367,88 @@ mod tests { assert_eq!(response.status(), StatusCode::NOT_FOUND); } + + #[tokio::test] + async fn info_advertises_evp_proxy_for_feature_flags() { + let response = TraceAgent::info().await; + let body = axum::body::to_bytes(response.into_body(), usize::MAX) + .await + .expect("info body"); + let info: serde_json::Value = serde_json::from_slice(&body).expect("info json"); + let endpoints = info["endpoints"].as_array().expect("endpoints"); + for path in [ + EVP_PROXY_V2_BASE_PATH, + FFE_FLAG_EVALUATION_ENDPOINT_PATH, + FFE_EXPOSURES_ENDPOINT_PATH, + ] { + assert!(endpoints.iter().any(|e| e == path), "missing {path}"); + } + let headers = info["evp_proxy_allowed_headers"] + .as_array() + .expect("evp_proxy_allowed_headers"); + for header in ["DD-EVP-ORIGIN", "DD-EVP-ORIGIN-VERSION"] { + assert!(headers.iter().any(|h| h == header), "missing {header}"); + } + } + + /// Tracers that match `/evp_proxy/v2/` by prefix may send other EVP data + /// here. A 404 makes them send it directly instead. + #[tokio::test] + async fn unrouted_evp_paths_return_not_found() { + let agent = build_test_agent(); + let router = agent.make_router().expect("make_router"); + let response = router + .oneshot( + Request::builder() + .method("POST") + .uri("/evp_proxy/v2/api/v2/not-a-flag-route") + .header("X-Datadog-EVP-Subdomain", "event-platform-intake") + .body(Body::from("{}")) + .expect("build request"), + ) + .await + .expect("route response"); + + assert_eq!(response.status(), StatusCode::NOT_FOUND); + assert!(agent.proxy_aggregator.lock().await.get_batch().is_empty()); + } + + #[tokio::test] + async fn feature_flag_events_are_relayed_to_event_platform_intake() { + let agent = build_test_agent(); + let site = agent.config.site.clone(); + let router = agent.make_router().expect("make_router"); + for (path, intake) in [ + ( + FFE_FLAG_EVALUATION_ENDPOINT_PATH, + FFE_FLAG_EVALUATION_INTAKE_PATH, + ), + (FFE_EXPOSURES_ENDPOINT_PATH, FFE_EXPOSURES_INTAKE_PATH), + ] { + let response = router + .clone() + .oneshot( + Request::builder() + .method("POST") + .uri(path) + .header("Content-Type", "application/json") + .header("DD-EVP-ORIGIN", "dd-trace-py") + .header("DD-EVP-ORIGIN-VERSION", "4.17.0") + .header("X-Datadog-EVP-Subdomain", "event-platform-intake") + .body(Body::from(r#"{"events":[]}"#)) + .expect("build request"), + ) + .await + .expect("route response"); + assert_eq!(response.status(), StatusCode::OK, "{path}"); + let batch = agent.proxy_aggregator.lock().await.get_batch(); + assert_eq!(batch.len(), 1, "{path}"); + assert_eq!( + batch[0].target_url, + format!("https://event-platform-intake.{site}{intake}") + ); + assert_eq!(batch[0].headers["dd-evp-origin"], "dd-trace-py"); + assert_eq!(batch[0].headers["dd-evp-origin-version"], "4.17.0"); + } + } } From 8cd8505274147ed742aa1e39fd91b2d6b076283a Mon Sep 17 00:00:00 2001 From: "cliford.shelton" Date: Wed, 11 Nov 2026 17:58:02 -0500 Subject: [PATCH 2/2] fix(traces): give EVP proxy routes a 10 MiB body limit Tracers send EVP batches of up to 5 MiB, and the shared 2 MiB proxy limit rejected them with 413, which no tracer retries. Move the LLM Obs and feature flag EVP routes to their own router with the Datadog Agent's 10 MiB limit. Also assert the exact /info and route strings in tests, add a flush test for the API key and origin headers, and correct comments about tracer behavior. Co-Authored-By: Aaron Silverman Co-Authored-By: Claude Opus 5.5 --- bottlecap/src/traces/trace_agent.rs | 125 +++++++++++++++++++----- bottlecap/tests/evp_proxy_flush_test.rs | 91 +++++++++++++++++ 2 files changed, 189 insertions(+), 27 deletions(-) create mode 100644 bottlecap/tests/evp_proxy_flush_test.rs diff --git a/bottlecap/src/traces/trace_agent.rs b/bottlecap/src/traces/trace_agent.rs index bcf4217e6..4bf906a0f 100644 --- a/bottlecap/src/traces/trace_agent.rs +++ b/bottlecap/src/traces/trace_agent.rs @@ -66,7 +66,8 @@ const LLM_OBS_EVAL_METRIC_ENDPOINT_PATH: &str = "/evp_proxy/v2/api/intake/llm-ob const LLM_OBS_EVAL_METRIC_ENDPOINT_PATH_V2: &str = "/evp_proxy/v2/api/intake/llm-obs/v2/eval-metric"; const LLM_OBS_SPANS_ENDPOINT_PATH: &str = "/evp_proxy/v2/api/v2/llmobs"; -// Some tracers need this base path in /info before they use EVP proxy routes. +// Agentless flag discovery and Java/Go LLM Obs find the EVP proxy by this base path +// in /info; dd-trace-java and dd-trace-go LLM Obs also need the trailing slash. const EVP_PROXY_V2_BASE_PATH: &str = "/evp_proxy/v2/"; const FFE_FLAG_EVALUATION_ENDPOINT_PATH: &str = "/evp_proxy/v2/api/v2/flagevaluation"; const FFE_EXPOSURES_ENDPOINT_PATH: &str = "/evp_proxy/v2/api/v2/exposures"; @@ -93,6 +94,8 @@ const STATS_PAYLOAD_CHANNEL_BUFFER_SIZE: usize = 10; const BARRIER_CHANNEL_BUFFER_SIZE: usize = 1; pub const TRACE_REQUEST_BODY_LIMIT: usize = 50 * 1024 * 1024; pub const DEFAULT_REQUEST_BODY_LIMIT: usize = 2 * 1024 * 1024; +/// Tracers send EVP batches of about 5 MiB at most; the Agent's EVP proxy accepts 10 MiB. +const EVP_PROXY_REQUEST_BODY_LIMIT: usize = 10 * 1024 * 1024; pub const MAX_CONTENT_LENGTH: usize = 50 * 1024 * 1024; const LAMBDA_LOAD_SPAN: &str = "aws.lambda.load"; @@ -478,6 +481,20 @@ impl TraceAgent { let proxy_router = Router::new() .route(DSM_AGENT_PATH, post(Self::dsm_proxy)) .route(PROFILING_ENDPOINT_PATH, post(Self::profiling_proxy)) + .route(V1_DEBUGGER_ENDPOINT_PATH, post(Self::debugger_logs_proxy)) + .route(V2_DEBUGGER_ENDPOINT_PATH, post(Self::debugger_intake_proxy)) + .route( + DEBUGGER_DIAGNOSTICS_ENDPOINT_PATH, + post(Self::debugger_intake_proxy), + ) + .route( + INSTRUMENTATION_ENDPOINT_PATH, + post(Self::instrumentation_proxy), + ) + .layer(RequestBodyLimitLayer::new(DEFAULT_REQUEST_BODY_LIMIT)) + .with_state(proxy_state.clone()); + + let evp_proxy_router = Router::new() .route( LLM_OBS_EVAL_METRIC_ENDPOINT_PATH, post(Self::llm_obs_eval_metric_proxy), @@ -492,17 +509,7 @@ impl TraceAgent { post(Self::ffe_flag_evaluation_proxy), ) .route(FFE_EXPOSURES_ENDPOINT_PATH, post(Self::ffe_exposures_proxy)) - .route(V1_DEBUGGER_ENDPOINT_PATH, post(Self::debugger_logs_proxy)) - .route(V2_DEBUGGER_ENDPOINT_PATH, post(Self::debugger_intake_proxy)) - .route( - DEBUGGER_DIAGNOSTICS_ENDPOINT_PATH, - post(Self::debugger_intake_proxy), - ) - .route( - INSTRUMENTATION_ENDPOINT_PATH, - post(Self::instrumentation_proxy), - ) - .layer(RequestBodyLimitLayer::new(DEFAULT_REQUEST_BODY_LIMIT)) + .layer(RequestBodyLimitLayer::new(EVP_PROXY_REQUEST_BODY_LIMIT)) .with_state(proxy_state); let info_router = Router::new().route(INFO_ENDPOINT_PATH, any(Self::info)); @@ -511,6 +518,7 @@ impl TraceAgent { .merge(trace_router) .merge(stats_router) .merge(proxy_router) + .merge(evp_proxy_router) .merge(info_router); if let Some(extension) = &self.router_extension { @@ -720,7 +728,8 @@ impl TraceAgent { V2_DEBUGGER_ENDPOINT_PATH, DEBUGGER_DIAGNOSTICS_ENDPOINT_PATH, ], - // handle_proxy forwards request headers; tracers check these before using EVP. + // The proxy flusher keeps these two headers. Agentless flag discovery needs + // both listed before it uses the local route. "evp_proxy_allowed_headers": ["DD-EVP-ORIGIN", "DD-EVP-ORIGIN-VERSION"], "client_drop_p0s": false, } @@ -1368,6 +1377,9 @@ mod tests { assert_eq!(response.status(), StatusCode::NOT_FOUND); } + /// The `/info` fields tracers read to pick a local EVP route. Discovery prefers + /// v4 when it is listed; dd-trace-java and dd-trace-go LLM Obs need the trailing + /// slash; agentless flag discovery needs both identity headers. #[tokio::test] async fn info_advertises_evp_proxy_for_feature_flags() { let response = TraceAgent::info().await; @@ -1375,24 +1387,42 @@ mod tests { .await .expect("info body"); let info: serde_json::Value = serde_json::from_slice(&body).expect("info json"); - let endpoints = info["endpoints"].as_array().expect("endpoints"); + let endpoints: Vec<&str> = info["endpoints"] + .as_array() + .expect("endpoints") + .iter() + .filter_map(serde_json::Value::as_str) + .collect(); + // Literals, not the production constants, so a typo fails here. for path in [ - EVP_PROXY_V2_BASE_PATH, - FFE_FLAG_EVALUATION_ENDPOINT_PATH, - FFE_EXPOSURES_ENDPOINT_PATH, + "/evp_proxy/v2/", + "/evp_proxy/v2/api/v2/flagevaluation", + "/evp_proxy/v2/api/v2/exposures", ] { - assert!(endpoints.iter().any(|e| e == path), "missing {path}"); + assert!(endpoints.contains(&path), "missing {path} in {endpoints:?}"); } - let headers = info["evp_proxy_allowed_headers"] + assert!( + !endpoints + .iter() + .any(|e| e.trim_start_matches('/').starts_with("evp_proxy/v4")), + "v4 is listed, so tracers would send to unrouted v4 paths: {endpoints:?}" + ); + let headers: Vec = info["evp_proxy_allowed_headers"] .as_array() - .expect("evp_proxy_allowed_headers"); - for header in ["DD-EVP-ORIGIN", "DD-EVP-ORIGIN-VERSION"] { - assert!(headers.iter().any(|h| h == header), "missing {header}"); + .expect("evp_proxy_allowed_headers") + .iter() + .filter_map(serde_json::Value::as_str) + .map(str::to_ascii_lowercase) + .collect(); + for header in ["dd-evp-origin", "dd-evp-origin-version"] { + assert!( + headers.iter().any(|h| h == header), + "missing {header} in {headers:?}" + ); } } - /// Tracers that match `/evp_proxy/v2/` by prefix may send other EVP data - /// here. A 404 makes them send it directly instead. + /// EVP paths without a route return 404 and are not buffered. #[tokio::test] async fn unrouted_evp_paths_return_not_found() { let agent = build_test_agent(); @@ -1413,17 +1443,58 @@ mod tests { assert!(agent.proxy_aggregator.lock().await.get_batch().is_empty()); } + /// Tracers send EVP batches of about 5 MiB at most (the envelope can add a + /// little). Sent with Content-Length, such a batch gets 413 under the default + /// 2 MiB proxy limit, and tracers drop the rejected batch. + #[tokio::test] + async fn evp_proxy_routes_accept_five_mib_batches() { + for path in [ + LLM_OBS_SPANS_ENDPOINT_PATH, + LLM_OBS_EVAL_METRIC_ENDPOINT_PATH, + LLM_OBS_EVAL_METRIC_ENDPOINT_PATH_V2, + FFE_FLAG_EVALUATION_ENDPOINT_PATH, + FFE_EXPOSURES_ENDPOINT_PATH, + ] { + for (size, expected) in [ + (5 * 1024 * 1024 + 64 * 1024, StatusCode::OK), + ( + EVP_PROXY_REQUEST_BODY_LIMIT + 1, + StatusCode::PAYLOAD_TOO_LARGE, + ), + ] { + let agent = build_test_agent(); + let router = agent.make_router().expect("make_router"); + let response = router + .oneshot( + Request::builder() + .method("POST") + .uri(path) + .header("Content-Type", "application/json") + .header("Content-Length", size.to_string()) + .body(Body::from(vec![b' '; size])) + .expect("build request"), + ) + .await + .expect("route response"); + assert_eq!(response.status(), expected, "{path} with {size} bytes"); + let queued = agent.proxy_aggregator.lock().await.get_batch().len(); + assert_eq!(queued, usize::from(expected == StatusCode::OK), "{path}"); + } + } + } + #[tokio::test] async fn feature_flag_events_are_relayed_to_event_platform_intake() { let agent = build_test_agent(); let site = agent.config.site.clone(); let router = agent.make_router().expect("make_router"); + // Literals: the tracer paths and the intake paths are the contract. for (path, intake) in [ ( - FFE_FLAG_EVALUATION_ENDPOINT_PATH, - FFE_FLAG_EVALUATION_INTAKE_PATH, + "/evp_proxy/v2/api/v2/flagevaluation", + "/api/v2/flagevaluation", ), - (FFE_EXPOSURES_ENDPOINT_PATH, FFE_EXPOSURES_INTAKE_PATH), + ("/evp_proxy/v2/api/v2/exposures", "/api/v2/exposures"), ] { let response = router .clone() diff --git a/bottlecap/tests/evp_proxy_flush_test.rs b/bottlecap/tests/evp_proxy_flush_test.rs new file mode 100644 index 000000000..36c11d0e5 --- /dev/null +++ b/bottlecap/tests/evp_proxy_flush_test.rs @@ -0,0 +1,91 @@ +// Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/ +// SPDX-License-Identifier: Apache-2.0 +// Integration tests are exempt from the production lint policy in Cargo.toml. +#![allow( + unreachable_pub, + clippy::pedantic, + clippy::panic, + clippy::unwrap_used, + clippy::expect_used +)] + +//! The proxy flusher sends a queued flag event batch with the API key and the +//! tracer's identity headers. The trace agent builds the intake URL; here the +//! batch targets a local intake directly. + +mod fixtures; +#[path = "common/harness.rs"] +mod harness; + +use std::collections::HashMap; +use std::sync::Arc; + +use bottlecap::LAMBDA_RUNTIME_SLUG; +use bottlecap::config::Config; +use bottlecap::tags::provider::Provider; +use bottlecap::traces::proxy_aggregator::{Aggregator as ProxyAggregator, ProxyRequest}; +use bottlecap::traces::proxy_flusher::Flusher as ProxyFlusher; +use datadog_fips::reqwest_adapter::create_reqwest_client_builder; +use dogstatsd::api_key::ApiKeyFactory; +use harness::prelude::*; +use tokio::sync::Mutex; + +#[tokio::test] +async fn flag_event_batch_is_flushed_with_api_key_and_origin_headers() { + let intake = FaultIntake::start(FaultMode::Ok).await; + let config = Arc::new(Config { + api_key: TEST_API_KEY.to_string(), + site: "datadoghq.com".to_string(), + ..Config::default() + }); + let tags = Arc::new(Provider::new( + Arc::clone(&config), + LAMBDA_RUNTIME_SLUG.to_string(), + &HashMap::from([( + "function_arn".to_string(), + "arn:aws:lambda:us-east-1:123456789012:function:test".to_string(), + )]), + )); + let aggregator = Arc::new(Mutex::new(ProxyAggregator::default())); + let mut headers = reqwest::header::HeaderMap::new(); + headers.insert("content-type", "application/json".parse().unwrap()); + headers.insert("dd-evp-origin", "dd-trace-js".parse().unwrap()); + headers.insert("dd-evp-origin-version", "5.80.0".parse().unwrap()); + aggregator.lock().await.add(ProxyRequest { + headers, + body: r#"{"exposures":[{"flag":{"key":"harness-exposed-flag"}}]}"#.into(), + target_url: format!("{}/api/v2/exposures", intake.url()), + }); + // Test-only client towards a local intake; the FIPS adapter is what production uses. + let client = create_reqwest_client_builder() + .expect("client builder") + .no_proxy() + .build() + .expect("client"); + let flusher = ProxyFlusher::new( + Arc::new(ApiKeyFactory::new(TEST_API_KEY)), + Arc::clone(&aggregator), + tags, + Arc::clone(&config), + client, + ); + + let failed = flusher.flush(None).await; + assert!( + failed.is_none(), + "flush failed: {failed:?}. {}", + intake.summary() + ); + + let sent = intake.requests_to("/api/v2/exposures"); + assert_eq!(sent.len(), 1, "{}", intake.summary()); + assert_eq!(sent[0].api_key(), Some(TEST_API_KEY)); + assert_eq!(sent[0].header("dd-evp-origin"), Some("dd-trace-js")); + assert_eq!(sent[0].header("dd-evp-origin-version"), Some("5.80.0")); + assert!( + sent[0] + .body_text() + .unwrap() + .contains("harness-exposed-flag") + ); +}