Repository navigation
[FFE] Send DD-Service on agentless configuration requests - #9687
Conversation
The Feature Flags CDN logs each configuration request for usage metering and attributes it to a service when the request carries DD-Service. Send the tracer's service on every agentless poll, so Feature Flags usage can be broken down by service. The service can be changed in code after startup, so it is read per request and kept current through the settings subscription the source already uses for the environment. When DD_SERVICE isn't set, the inferred default is sent, the same name the spans use. Only a service matching the format the CDN accepts is sent. The CDN drops any other value, and a header value with a line break or a non-ASCII character can make the request fail, which would fail every poll. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BenchmarksBenchmark execution time: 2026-11-17 19:56:00 Comparing candidate commit 5ee22e2 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 72 metrics, 0 unstable metrics, 13 known flaky benchmarks, 112 flaky benchmarks without significant changes.
|
The CDN attributes usage to DD-Service only when it matches its service format, so a name like "My Service" was not sent and its usage billed without a service, while APM shows it as my_service. On IIS the inferred name is the site and application path, such as "Default Web Site/Shop", so the default name was affected too. Clean the name up with NormalizerTraceProcessor.NormalizeService, the tracer's port of the Agent's service normalization, right before it becomes the header: "My Service" is sent as my_service and "Default Web Site/Shop" as default_web_site/shop. The tracer's own service is left as configured. The result is still checked against the CDN's format, because the normalizer keeps non-ASCII letters and can leave nothing at all. A name with nothing usable left is not sent, with a debug log, and polling carries on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the reuse of NormalizerTraceProcessor.NormalizeService with a small helper that matches the Node.js tracer's normalizeService, so both tracers send the same DD-Service for the same name: lowercase, every character other than a-z 0-9 _ : . / - becomes _, the characters before the first letter or digit are dropped, and the name is cut to 100 characters. Unlike that normalizer, this keeps a leading digit (2fa-service), replaces non-ASCII letters instead of keeping them (cafe with an accent is sent as caf_ rather than not at all), and doesn't merge runs of replaced characters. It also no longer logs "Fixing malformed trace" for a long name. A name with no ASCII letter or digit is still not sent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (9687) and master. ✅ No regressions detected |
DD-Service is now the service name that APM shows, or the request has no header. Before, the header used the cleanup of the Node.js tracer. That cleanup can bill usage under a name that APM does not show: it sent _svc as svc, but APM shows _svc. CleanUpService is now a port of NormalizeService in the current Agent (pkg/trace/traceutil/normalize, v0.82.3). It cuts the name to 100 bytes of UTF-8 and lowercases ASCII letters. It keeps letters, digits and : . / -, and changes each run of other characters to one _. It removes a run at the end of the name. NormalizerTraceProcessor.NormalizeService is not used, because it follows an older Agent. That version removes the characters before the first letter, so 2fa-service becomes fa-service. The CDN drops some names that APM shows, such as _svc and café-api. The source does not send these names. It logs them once at debug level and continues to poll. The tests check 36 names against values from the Agent code and the CDN pattern. The comments that this PR adds now use short, simple sentences. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The source no longer copies the CDN pattern. The CDN alone decides which DD-Service values it attributes, so that rule can change without an SDK release. The source now sends the name that APM shows when it is not empty and has only printable ASCII (0x21 to 0x7E). The ASCII check stays because HttpClient throws "Request headers must contain only ASCII characters" for a value such as café-api. Then every poll fails, and flags never load. The CDN drops non-ASCII values anyway, so attribution does not change. _svc, -svc, .svc, :svc, - and " svc" (as _svc) now send a header. Non-ASCII and empty names still send no header and log once at debug level. CleanUpService does not change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The comments said that the CDN drops _svc and every non-ASCII name. The source now sends _svc, and it does not send a name that is empty or not plain ASCII. The comments now say that. No code changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
greghuels
left a comment
There was a problem hiding this comment.
Approving at 000c9c0. The only validation is the printable-ASCII guard (0x21–0x7E), with no CDN shape pattern left. Normalization gives the same header as the Agent's NormalizeService (via dd-trace-go#5878) on all 20,334 test inputs: generated strings, control characters, CRLF payloads, and cases like _svc, unnamed-service and a²b.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 000c9c0cad
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
With client-side stats normalization active, DD_SERVICE=2fa-service produces spans named fa-service while Feature Flags requests send 2fa-service, splitting usage attribution from APM.
🤖 Bits Code Review · Commit 000c9c0
andrewlock
left a comment
There was a problem hiding this comment.
I don't think we should have another implementation of service normalization (which even differs from the other implementations). It's just asking for issues with drift and difference.
Also, most of the testing is adding a lot of noise trying to test other components because it's testing along the wrong seams IMO
leoromanovsky
left a comment
There was a problem hiding this comment.
🤖 Comment from Codex working with leoromanovsky:
Approving as requested by leoromanovsky. The service-normalization mismatch and late-activation settings replay findings remain open; their reproduction and suggested remedies are recorded in the review threads.
The DD-Service header now uses NormalizerTraceProcessor.NormalizeService, the tracer's own service normalizer, instead of a copy in Feature Flags. The ASCII check stays. The tests check only the wiring, because the tracer's own tests cover the normalizer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
More details
The PR sends an ASCII-safe, shared-normalized DD-Service header on every agentless poll; the earlier client-side stats/OTLP mismatch is fixed. Default Agent export can still attribute 2fa-service as fa-service, a known discrepancy explicitly deferred to APM normalization work in the PR discussion.
🤖 Bits Code Review · Commit 1b6f87e
HttpClient throws on any non-ASCII header value, so the check stays in .NET. The comment no longer says that the CDN decides which names it attributes, because the CDN will copy any value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The source now sends the result of NormalizerTraceProcessor.NormalizeService as it is. Only an empty result sends no header. Feature Flags adds no check of its own on the value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
The PR adds DD-Service attribution to agentless polls, but removing the ASCII guard makes services such as café-api fail every configuration request on modern .NET. The earlier stats/OTLP naming mismatch is fixed; the default-export naming discrepancy remains deferred to APM normalization work.
🤖 Bits Code Review · Commit 5ee22e2
# What does this PR do? Adds an optional `service` to `CdnConfig`. Each CDN configuration request sends it in a `DD-Service` header, 304 revalidations included. The header has the service name after the trace normalizer, or there is no header. - `cdn.rs`: new `CdnConfig::service`. `CdnFetcher::new` passes it to the transport. - `cdn/transport.rs`: `usage_service` normalizes the service once, when the fetcher is built. `build_request` adds `DD-Service` when there is a value. - `Cargo.toml`: `libdd-ffe` uses `normalize_service` from `libdd-trace-normalization`. The `cdn` feature turns on this optional dependency. The request has no header when the normalized name is empty or the normalizer fallback `unnamed-service`. The fetcher logs this once at debug level and continues to poll. A non-ASCII name goes out as its UTF-8 bytes. | `service` | `DD-Service` header | |---|---| | `checkout` | `checkout` | | `My Service` | `my_service` | | `Default Web Site/Shop` | `default_web_site/shop` | | `café-api` | `café-api` (UTF-8 bytes) | | `支付` | `支付` (UTF-8 bytes) | | `___` | no header (the fallback `unnamed-service`) | <details><summary>Why no header for the fallback</summary> `normalize_service` gives `unnamed-service` when nothing is left of the name, for example `___` or a blank name. That value says only that the service has no usable name, so the request has no header. A service that is itself named `unnamed-service` also has no header, because it is the same value. </details> # Motivation The Feature Flags CDN uses `DD-Service` to attribute configuration requests to a service. Customers can then break their Feature Flags usage down by service. Any SDK that fetches through `libdd-ffe` gets this when it sets the field. Today that is PHP, through the sidecar. dd-trace-php sets `service` in DataDog/dd-trace-php#4495. The header uses the normalizer that libdatadog already has for span services, so this PR adds no other copy of the normalization rules. A later fix to that normalizer also changes the header. The tracers also send `DD-Service`: DataDog/dd-trace-go#5878, DataDog/dd-trace-java#13378, DataDog/dd-trace-dotnet#9687, DataDog/dd-trace-js#11166, DataDog/dd-trace-py#21683, DataDog/dd-trace-rb#6673. System tests: DataDog/system-tests#8446. <details><summary>More detail</summary> - The CDN copies the header value to its usage logs, and metering-api normalizes every usage tag again. - The `http` crate accepts UTF-8 header values, and hyper sends their bytes. So a non-ASCII name cannot make a request fail, and the fetcher sends it as is. - The normalization also protects polling. A value with CR/LF is not a valid header value. The request cannot be built, so every poll fails. The normalizer replaces CR/LF, so a bad service removes only the header. It never stops flag fetching. </details> # Additional Notes - `CdnConfig` is the fetcher identity (Eq/Hash, and IPC). So the sidecar runs one fetcher for each service. This is expected. - Breaking: `CdnConfig` has a new public field, so struct literals need `service`. The field is `#[serde(default)]`, so JSON without it reads as no service. IPC uses bincode, so the client and the sidecar must come from the same libdatadog version, as before. - Custom endpoints also get the header. A service name is not a secret, unlike the API key. - Nothing else changes. `DD-Service` is not part of the CDN cache key, so ETags work as before. <details><summary>Implementation notes</summary> - `libdd-trace-normalization` adds no new crate to `Cargo.lock`. Its dependencies (`anyhow`, `libdd-trace-protobuf`) are already in the workspace. - `normalize_service` removes the characters before the first letter, so `2fa-service` becomes `fa-service` and `_svc` becomes `svc`. The current Agent keeps them. That difference is in the shared normalizer, and the APM team owns its fix. This PR does not change the normalizer. - A whitespace-only service and `___` get the debug log. An empty service gets no log. - The shared test log capture moves from `telemetry/` to the crate root, so CDN tests can check the debug log. </details> # How to test the change? - `CdnFetcher` tests against a mock HTTP server: - `checkout` is sent on the first 200 and on the next 304. - `My Service` arrives as `DD-Service: my_service`, and `Default Web Site/Shop` as `DD-Service: default_web_site/shop`, on 2 polls each. - With `___` or `!!!` (the fallback `unnamed-service`), requests have no header. The debug log appears once over several polls. - With `café-api` or `支付`, a raw socket server gets the UTF-8 bytes of the name on 2 polls, and fetching works. (httpmock cannot match a header value that is not ASCII.) - With no service or an empty service, requests have no header and fetching works. - A unit test checks that the header carries the result of `normalize_service`, also for `café-api` and `支付`, and which results send no header. The normalizer has its own tests in its crate. - The sidecar CDN HTTP/IPC test registers a service. Its mock answers only requests that have the header. - ffe-dogfooding ran a PHP app end to end against the staging CDN, on an earlier head of this PR. A proxy recorded the `DD-Service` header of each poll, and the CDN logs had the same values. Each name in the PHP results below gives the same header with `normalize_service`. <details><summary>Results</summary> - `cargo nextest run -p libdd-ffe --features cdn`: 94 pass. `cargo nextest run -p libdd-ffe`: 45 pass. `cargo nextest run -p datadog-sidecar -E 'test(/cdn/)'`: 11 pass. - `cargo clippy -p libdd-ffe --features cdn --all-targets -- -D warnings` is clean. `cargo check -p libdd-ffe --no-default-features` passes with and without `cdn`. - `cargo +nightly-2026-07-26 fmt -p libdd-ffe -- --check` is clean. </details> <details><summary>PHP dogfooding results</summary> The PHP app ran dd-trace-php from DataDog/dd-trace-php#4312 (the CDN integration). #4312 pins libdatadog at #2676, so the build used that commit plus an earlier head of this PR. #4312 does not set `service` yet, so the build also had a small local patch, the shape of the dd-trace-php follow-up: - `ddog_ffe_cdn_config_new` gets a `service` argument and sets `CdnConfig.service`. An empty value gives `None`. - `ddtrace_ffe_startup` passes `DD_SERVICE` (which falls back to `OTEL_SERVICE_NAME`), else `datadog_default_service_name()`. The root span uses the same rule. PHP ignores a `service` tag in `DD_TAGS` on spans, so the patch ignores it too. The app was in agentless mode with a 5-second poll interval. A proxy recorded each poll and forwarded it to the staging CDN. | Case | `DD-Service` | |---|---| | `DD_SERVICE=My Service` | `my_service` | | `DD_SERVICE=checkout-dogfood` | `checkout-dogfood` | | `DD_SERVICE=café-api` | no header on that head; the current head sends `café-api` | | `DD_SERVICE=支付` | no header on that head; the current head sends `支付` | | `DD_SERVICE=a b!` | `a_b` | | empty `DD_SERVICE`, `OTEL_SERVICE_NAME=ffe-dogfooding-php8-openfeature` | `ffe-dogfooding-php8-openfeature` | | `DD_SERVICE=ffe-dogfooding-php-agentless`, straight to the CDN with no proxy | `ffe-dogfooding-php-agentless` (CDN logs) | | `OTEL_SERVICE_NAME=My OTel Svc` only | `my_otel_svc` | | `DD_TAGS=service:tagged-svc,team:ffe` only | `web.request`, the default PHP service of the spans | | `DD_SERVICE=dd-wins`, `OTEL_SERVICE_NAME=otel-loses` | `dd-wins` | - Each case sent the header on the first `200` and on each later `304`. The provider was ready and the flags evaluated. - After 3 polls with `503`, 2 polls with `429` and 2 polls slower than the request timeout, the polls continued with the same header and the app recovered. - In Remote Configuration mode, the app sent no CDN polls. </details> Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: david.ioinovitch <david.ioinovitch@datadoghq.com>
Summary of changes
Sends the tracer's service as a
DD-Serviceheader on agentless Feature Flags configuration requests. The value is the service normalized with the tracer's ownNormalizerTraceProcessor.NormalizeService. When the normalized name is empty, the request has no header.AgentlessConfigurationSourceaddsDD-Serviceto every poll. This includes polls that get a 304.DefaultServiceName, the name that the spans use. This isDD_SERVICE, then theservicetag inDD_TAGS, then the inferred default.NormalizerTraceProcessor.NormalizeService. For example,My Serviceis sent asmy_service. The tracer's own service does not change.___, the request has no header. Polling continues.DD-ServiceheadercheckoutcheckoutMy Servicemy_serviceDefault Web Site/Shop(IIS default)default_web_site/shopcafé-apicafé-api支付支付___Reason for change
The Feature Flags CDN uses
DD-Serviceto attribute configuration requests to a service. Customers can then break down their Feature Flags usage by service.The usage must have the same service name as APM, so the header uses the tracer's own normalizer. Feature Flags adds no normalizer of its own.
The IIS case
On .NET Framework, the default service of an IIS application is
<site name>/<application path>, for exampleDefault Web Site/Shop. That name has spaces. The header sendsdefault_web_site/shop, as the tracer normalizes it.Implementation details
UpdateServicecallsNormalizerTraceProcessor.NormalizeServicewhen the service setting changes, not for each poll.RequestAsync()adds the header to each request.Names with non-ASCII letters
café-apiis sent ascafé-api.HttpClientrefuses a header value that is not ASCII. It throws "Request headers must contain only ASCII characters" (tested on .NET 11). So for such a name, each agentless poll fails, and flags do not load.Known difference: names that start with a digit
NormalizeServicefollows an older Agent. It removes the characters before the first letter, so2fa-serviceis sent asfa-service. With client-side stats or OTLP export, the spans go through the same function, so APM also showsfa-service. In the default mode, the Agent normalizes the spans and keeps2fa-service.The APM team owns the fix in the tracer's normalizer. When it lands, the header follows with no change in Feature Flags.
Other details
CreateRequestFactory, because there the value cannot change. Code can change the service after startup, and the settings callback updates the header._settingsSubscription.Createtakes an optional request factory. A test can then build the source from tracer settings and examine its requests.DD-Serviceis not part of the CDN cache key.Test coverage
Tests in
AgentlessConfigurationSourceTestsuse a mocked request. The tracer's own tests cover the normalizer, so these tests check the wiring:checkout,My Service,Default Web Site/Shop,café-apiand___(no header).Create.DD_SERVICE=My Servicesendsmy_service. With___, the request goes out with no header. The tracer'sServiceNameandDefaultServiceNamedo not change.Other tests
DD-Serviceis on every poll. This includes the 304 that answersIf-None-Match.DD_SERVICEis not set.The focused tests pass locally on net11.0 (37 tests):
dotnet test tracer/test/Datadog.Trace.Tests/Datadog.Trace.Tests.csproj --framework net11.0 --filter "FullyQualifiedName~FeatureFlags.AgentlessConfigurationSourceTests".The header path also ran in the ffe-dogfooding app, built from source, against the staging CDN. The CDN logs show
my_serviceforMy Service,a_bfora b!andtagged-svcforDD_TAGS=service:tagged-svc.café-apiand支付sent no header, and the polls continued. CDN errors (503, 429, timeouts) did not stop the polls, and Remote Configuration mode sent no CDN request. That run used an earlier commit of this PR.NormalizeServicegives the same header for each of these names.Other details
The header also goes to custom endpoints. Unlike the API key, a service name is not a secret.
Generated with Claude Code