Repository navigation
Send the service on agentless Feature Flags configuration requests - #13378
gh-worker-dd-mergequeue-cf854d[bot] merged 11 commits into
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 SDK's service on every agentless poll, so Feature Flags usage can be broken down by service. With the Java agent attached, that is the agent's resolved service name, the one its spans use. Only a service matching the format the CDN accepts is sent; anything else is skipped with a debug log. The CDN drops any other value, and a header value with a line break or a character outside Latin-1 makes HttpRequest.Builder throw, which would fail every poll. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Feature Flags CDN logs the requesting SDK from the DD-Client-Library-Language and DD-Client-Library-Version headers. The Java SDK doesn't send them, so its configuration requests are logged without an SDK name. Send java and the SDK version on the configuration request only; event intake requests are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
The CDN attributes usage to DD-Service only when it matches its service format, so a service like "My Service" was skipped and its usage billed without a service, while APM shows it as my_service. Clean the name up right before it becomes the header: lowercase it, replace each character outside a-z, 0-9 and _:./- with _, drop the leading characters that aren't letters or digits, and cut it to 100 characters. The character rules are those of TagsHelper.sanitize, which the tracer applies to the service it sends to Remote Configuration. dd-openfeature is published on its own and doesn't depend on internal-api, so it has its own copy. Only the header value is cleaned up; the configured service is unchanged. A name with nothing left once cleaned up, like 支付, is still not sent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The previous commit cleaned up the service with the rules of TagsHelper.sanitize. These rules can give a name that APM does not show: _svc becomes svc, but APM shows _svc. Thus the CDN can bill usage to a service that APM does not have. Now DD-Service is the name that APM shows, or the SDK sends no header. The SDK normalizes the service with the rules of NormalizeService in the Datadog Agent (v0.82.3). It sends the result only if the result matches the CDN format. My Service gives my_service. _svc and café-api give no header. The SDK cannot call TraceUtils.normalizeServiceName, because dd-openfeature does not depend on internal-api. That helper also follows older Agent rules. Thus the SDK has its own port. The SDK now reads the service without trimming it. The tracer does not trim the service of its spans, so APM shows " svc" as _svc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tracer sets the service of every span from a service tag in DD_TAGS or DD_TRACE_SPAN_TAGS. The Feature Flags service setting read Config.getServiceName(), which ignores these tags. Thus with DD_TAGS=service:checkout and no DD_SERVICE, spans showed checkout, but DD-Service and the exposure events had the inferred name. Use the service tag of the merged span tags when the service-name tag interceptor is on, as the tracer does. Config already drops the DD_TAGS service tag when DD_SERVICE is set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SDK sent the APM name of the service only if it matched the CDN format. The CDN is the only place that decides which DD-Service values it accepts. It drops other values, from any client. The SDK now does not copy that rule, so the rule can change in one place, without SDK releases. The SDK now sends the APM name if it is not empty and is printable ASCII. After normalization, only non-ASCII letters and digits fail this check. The JDK HttpClient throws IllegalArgumentException on a header value like 支付, and then every poll fails. The CDN drops non-ASCII values anyway, so this check does not change the usage attribution. _svc, " svc", -svc and .svc now send their APM name. café-api, 支付 and ___ still send no header. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
greghuels
left a comment
There was a problem hiding this comment.
Approving at 2b15e80. 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.
|
Hi! 👋 Thanks for your pull request! 🎉 To help us review it, please make sure to:
If you need help, please check our contributing guidelines. |
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: 2b15e800b2
ℹ️ 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.
CDN usage can be attributed to a different service from APM when service mappings or service.name tags are configured. On JDK 11, newer Unicode letters can also normalize to an unrelated ASCII name instead of causing the header to be omitted.
🤖 Bits Code Review · Commit 2b15e80
leoromanovsky
left a comment
There was a problem hiding this comment.
🤖 Review from Codex working with leoromanovsky:
Approved. The service-attribution findings remain documented in the existing review threads.
The JDK HttpClient throws on a value like 支付 and sends é as ?, so the check stays in Java. The comment no longer says that the CDN decides which values it attributes, because the CDN will copy any value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The source now sends the normalized service as it is. Only an empty result sends no header. The SDK 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 service and SDK identity headers to agentless polls, but removing ASCII validation now makes services such as 支付 fail every poll, preventing flag loading. Earlier attribution defects involving service mappings, service.name tags, and Unicode classification on JDK 11 remain unresolved.
🤖 Bits Code Review · Commit e69b6d6
Master added a FlagSelectionRequest parameter to the CdnConfigurationSource constructors. The merge keeps it and adds the service parameter next to the API key, so both changes compile together. Two tests pass the new arguments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Service mappings and the service.name tag alias can make the new DD-Service header identify a different service than APM, undermining the service-level usage attribution this change introduces.
🤖 Bits Code Review · Commit 1c502ff
The header now gets the service of the tracer's spans in the same three steps as the tracer: merge the global and span tags into a TagMap (which stores service.name as service), take that tag when the ServiceNameTagInterceptor rule is on, then apply DD_SERVICE_MAPPING with the TraceCollector.mapServiceName lookup. For example, DD_SERVICE=checkout with DD_SERVICE_MAPPING=checkout:store now sends store, and DD_SERVICE=app with DD_TRACE_SPAN_TAGS=service.name:checkout now sends checkout. The backend test checks each case against the service of a span from a real CoreTracer with the same Config. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
/merge |
|
View all feedbacks in Devflow UI.
It will be processed automatically as soon as GitHub reports it as mergeable. View in MergeQueue UI.
The expected merge time in
|
# 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>
748275a
into
master
What Does This Do
The base branch sends no
DD-Serviceheader. With this change, the SDK sends its service in aDD-Serviceheader on each agentless Feature Flags configuration poll,304polls included. The value is the service name that APM shows. If that name is empty, the SDK sends no header. For a set service, it also writes one debug log. The poll still runs.DD-ServiceheadercheckoutcheckoutcheckoutMy Servicemy_servicemy_servicesvc_svc_svccafé-apicafé-apicafé-api, which the JDK client sends ascaf?-api支付支付支付, which the JDK client refuses___or emptydd-java-agent, the value is the service of the agent's spans.DD_TAGS=service:checkoutwith noDD_SERVICEsendscheckout, because the agent sets that service on every span.The SDK also sends
DD-Client-Library-Language: javaandDD-Client-Library-Version: <SDK version>on the same request.With
dd-java-agent, the Feature Flags service setting is the service of the spans. It follows aserviceorservice.nametag inDD_TAGSorDD_TRACE_SPAN_TAGS, and it appliesDD_SERVICE_MAPPING, as the spans do. On the base branch, it ignores the tags and the mapping. The exposure events use this setting, so theirservicealso matches the spans.DD-ServiceDD_SERVICE=checkoutcheckoutDD_TAGS=service:checkout, noDD_SERVICEcheckoutDD_SERVICE=app,DD_TRACE_SPAN_TAGS=service.name:checkoutcheckoutDD_SERVICE=checkout,DD_SERVICE_MAPPING=checkout:storestoreDD_SERVICE=checkout,DD_SERVICE_MAPPING=mysql:checkout-dbcheckoutNo other behavior changes. The Remote Configuration path, the event intake and the ETag handling stay the same.
Motivation
The Feature Flags CDN uses
DD-Serviceto attribute each configuration request to a service. Customers can then break down their Feature Flags usage by service.The usage must show the same service name as APM. Otherwise, customers cannot match their usage to their APM services. Thus the header is the APM name or nothing.
The SDK does not check the CDN's format. The CDN copies the value to its usage logs, and metering-api normalizes every tag again.
The CDN logs the requesting SDK from the
DD-Client-Library-*headers. The base branch does not send them.This is the same change as DataDog/dd-trace-js#11166 for Node.js.
Additional Notes
NormalizeServicein the Datadog Agent v0.82.3. The Agent applies these rules to the span service, so the result is the name that APM shows.TraceUtils.normalizeServiceName. That helper is ininternal-api, anddd-openfeaturedoes not depend on it. The helper also follows older Agent rules. ThusCdnConfigurationSourcehas a small port of the Agent rules.svcas_svc.HttpClientdecides how it sends a non-ASCII value. It sendséas?, socafé-apiarrives ascaf?-api. It throwsIllegalArgumentException: invalid header valueon支付, so for such a name each agentless poll fails, and flags do not load.dd-java-agent,FeatureFlagsBackendgives the SDK its service. On the base branch, it givesConfig.getServiceName(), which ignores theservicetags andDD_SERVICE_MAPPING. Thus withDD_TAGS=service:checkout, the spans showcheckout, butConfig.getServiceName()gives the inferred name, for exampleapp.TagMap, asCoreTracerdoes. The span tags win.TagMapstoresservice.nameasservice.ServiceNameTagInterceptorrule is on, asTagInterceptordoes. Else it returnsConfig.getServiceName().DD_SERVICE_MAPPINGwith the lookup ofTraceCollector.mapServiceName.Configdrops aservicetag fromDD_TAGSwhenDD_SERVICEis set, soDD_SERVICEwins over it.Configdoes not dropservice.name, so aDD_TAGSservice.namewins overDD_SERVICE, on spans and in the header.The normalization rules and other design notes
The rules, in order:
a-z,0-9,:,.,/,-, and the non-ASCII letters and decimal digits._. Remove a run at the end.Other notes:
café-apistayscafé-api.___, APM shows a fallback name. The SDK sends no header.tracing_service_mapping,tracing_tags). The header does not follow those changes.DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_BASE_URL). A service name is not a secret, unlike the API key.javainDD-Client-Library-LanguagematchesDatadog-Meta-Lang.How it was tested, in
CdnConfigurationSourceTest, against a local HTTP server. The SDK builds the source from the settings.dd.service. The expected headers come from the real Agent code (NormalizeServicev0.82.3). Each case sends a real request and applies the configuration. A set service without a header logs one debug message.My Servicesendsmy_service,_svcsends_svc, and___sends no header. The request is sent, and the SDK settings still show the configured service.304. It is not sent if the service is unset, empty or blank.sendsApiKeyAndMetadataHeadersalso checks the twoDD-Client-Library-*headers.FeatureFlagsBackendTest.resolvesTheServiceOfTheTracerSpansuses the realConfigwith 11 cases:DD_SERVICEonly, aDD_TAGSservice only,DD_SERVICEwith aDD_TAGSservice, aDD_TRACE_SPAN_TAGSservice, the tag interceptor turned off, a mapping of another service, a mapping ofDD_SERVICE, a mapping of aDD_TAGSservice, aservice.namespan tag, aservice.nameinDD_TAGSwithDD_SERVICE, and a mapping of aservice.namespan tag. For each case, the test also starts a span on a realCoreTracerwith the sameConfig, and checks that the span has the same service as the header._svc,DD_SERVICE_MAPPINGorservice.name; the unit tests cover them.Results, run locally
./gradlew :dd-openfeature:spotlessCheck :dd-openfeature:test --tests 'com.datadog.openfeature.internal.delivery.*': passes, 143 tests (93 inCdnConfigurationSourceTest)../gradlew :dd-openfeature:test: 985 of 989 pass. The 4 failures areCanonicalFixtureTest. It needs theffe-system-test-datasubmodule, which is not checked out locally. These failures are not related to this change../gradlew :products:feature-flagging:feature-flagging-lib:spotlessCheck :products:feature-flagging:feature-flagging-lib:test: passes, 108 tests (29 inFeatureFlagsBackendTest). Run with JDK 21 in Docker.FeatureFlagsBackendof the base branch, 2 of the first 5 cases fail: theDD_TAGSservice and theDD_TRACE_SPAN_TAGSservice.FeatureFlagsBackendof the previous commit (no mapping, noservice.name), 5 of the 6 new cases fail: the 3 mappings and the 2service.namecases. The mapping of another service passes, as it must.Dogfooding results (ffe-dogfooding, staging CDN)
The app ran
dd-java-agentanddd-openfeaturefrom this branch, in agentless mode. A proxy recorded theDD-Serviceheader of each poll. The span service is from the agent debug log.DD-ServiceDD_TAGS=service:tagged-svc,team:ffe, noDD_SERVICEtagged-svctagged-svcDD_SERVICE=dd-wins,DD_TAGS=service:tagged-svcdd-winsdd-winsDD_SERVICE=dd-svc,DD_TRACE_SPAN_TAGS=service:span-svcspan-svcspan-svcDD_TRACE_SPAN_TAGS=service:span-svc, noDD_SERVICEspan-svcspan-svcDD_SERVICE=My Servicemy_serviceMy Service(APM showsmy_service)14 more cases passed. They ran before the
servicetag change, and they set noservicetag:My Service,checkout-dogfood,_svc,a b!, and an emptyDD_SERVICEsent the expected header or no header. The CDN logs had the same values. Thecafé-apiand支付cases of that run predate the current behavior. One more case polled the staging CDN directly, with no proxy.OTEL_SERVICE_NAMEonly, andDD_SERVICEwithOTEL_SERVICE_NAME, sent the expected service.503, 2 polls with429and 2 polls slower than the request timeout, the polls continued with the same header and the app recovered.Generated with Claude Code