Skip to content

feat: support client and overall tracing sampling#9402

Merged
arkodg merged 14 commits into
envoyproxy:mainfrom
Ri7ay:client-overall-tracing-sampling
Jul 18, 2026
Merged

feat: support client and overall tracing sampling#9402
arkodg merged 14 commits into
envoyproxy:mainfrom
Ri7ay:client-overall-tracing-sampling

Conversation

@Ri7ay

@Ri7ay Ri7ay commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:
This PR adds support for configuring Envoy tracing client_sampling and overall_sampling in addition to the existing random_sampling support.

Envoy Gateway already exposes samplingRate / samplingFraction, which maps to Envoy HCM random_sampling. This change adds new optional client and overall sampling settings so users
can control traces requested by clients and the final overall trace volume sent to collectors.

The PR updates:

  • EnvoyProxy tracing API with clientSamplingRate, overallSamplingRate, clientSamplingFraction, and overallSamplingFraction
  • BackendTrafficPolicy route tracing with clientSamplingFraction and overallSamplingFraction
  • IR and xDS translation for HCM and route-level tracing sampling
  • CEL validation, unit/golden tests, generated CRDs/docs/Helm outputs, and release notes

Which issue(s) this PR fixes:
Fixes #9372


PR Checklist

  • Authorship & ownership: Coding agents / AI assistants are welcome, but I have reviewed every change, understand how and why it works, can explain and maintain it, and take full responsibility for this PR. I have not submitted generated output I do not understand.
  • DCO: All commits are signed off (git commit -s). See DCO: Sign your work.
  • API agreed first: If this PR contains API changes (changes under /api), the API was discussed and agreed before the implementation. The API change can be in a separate PR, or in the same PR, but the API must be agreed before implementation. N/A if this PR does not contain API changes.
  • Required checks pass: make generate gen-check, make lint, and the unit-test/coverage build pass. (Flaky e2e failures are not considered breakages, but gen-check, lint, and coverage MUST pass.)
  • Tests added/updated: New/changed code is covered by appropriate tests. N/A if this PR does not contain code changes.
  • Docs: User-facing changes update the docs, either in this PR or a follow-up PR. N/A if this PR does not contain user-facing changes.
  • Release notes: For any non-trivial change, added a release-note fragment under release-notes/current/<section>/<pr-number>-<slug>.md (see release-notes/current/README.md for sections and naming). N/A if this PR does not contain non-trivial changes.
  • Generated files committed: Ran make gen-check and committed the result if API/helm charts/modules changed.
  • Scope & compatibility: The PR is reasonably scoped (no unrelated changes) and preserves backward compatibility, or any breaking change is called out above and documented in release-notes/current/breaking_changes/.
  • Codex review: Requested a Codex review and addressed all of its comments.
  • Copilot review: Requested a Copilot review and addressed all of its comments.

@Ri7ay
Ri7ay requested a review from a team as a code owner July 1, 2026 21:27
@netlify

netlify Bot commented Jul 1, 2026

Copy link
Copy Markdown

Deploy Preview for cerulean-figolla-1f9435 ready!

Name Link
🔨 Latest commit e2124f9
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/6a5a88939ce8b7000818c5d5
😎 Deploy Preview https://deploy-preview-9402--cerulean-figolla-1f9435.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.45%. Comparing base (a094082) to head (e2124f9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9402      +/-   ##
==========================================
+ Coverage   75.44%   75.45%   +0.01%     
==========================================
  Files         252      252              
  Lines       41642    41659      +17     
==========================================
+ Hits        31417    31434      +17     
- Misses       8086     8089       +3     
+ Partials     2139     2136       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Ri7ay
Ri7ay force-pushed the client-overall-tracing-sampling branch from c4b0557 to 5629244 Compare July 1, 2026 21:38
Comment thread api/v1alpha1/envoyproxy_tracing_types.go Outdated
@Ri7ay
Ri7ay requested a review from zirain July 2, 2026 07:12
zirain
zirain previously approved these changes Jul 2, 2026

@zirain zirain left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, would be better if we could have e2e.

@Ri7ay
Ri7ay force-pushed the client-overall-tracing-sampling branch from 32e7073 to dcc1994 Compare July 6, 2026 10:54
@Ri7ay

Ri7ay commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

I added E2E tests, but I still can't beat several CI tests. Maybe you can help me with this?

@Ri7ay
Ri7ay requested a review from zirain July 6, 2026 11:57
@zirain

zirain commented Jul 6, 2026

Copy link
Copy Markdown
Member

it looks more like a flake test.

/retest

Comment thread test/e2e/tests/tracing.go Outdated

observed := false
deadline := time.Now().Add(15 * time.Second)
for time.Now().Before(deadline) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use same wait-until pattern?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad, fixed

@Ri7ay
Ri7ay requested a review from zirain July 6, 2026 18:46
@Ri7ay

Ri7ay commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

all tests success

zirain
zirain previously approved these changes Jul 6, 2026
// selected for tracing when requested by the client.
//
// +optional
ClientSamplingFraction *gwapiv1.Fraction `json:"clientSamplingFraction,omitempty"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • can we change the defaults of disabling clientSamplingFraction to 0, so users need to opt in to this feature ? we'll need to note this in the breaking changes section
  • can we avoid overallSamplingFraction ?

wdyt @envoyproxy/gateway-maintainers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asked below about the default value 0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@arkodg arkodg added this to the v1.9.0-rc.1 Release milestone Jul 6, 2026
Comment thread internal/xds/translator/tracing.go Outdated
return &hcm.HttpConnectionManager_Tracing{
ClientSampling: &xdstype.Percent{
Value: 100.0,
Value: ptr.Deref(tracing.ClientSamplingRate, 100),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As pointed out by @arkodg , please document this default to 100 if not settings, same behavior as before.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we change the default client sampling value to 0 as suggested above?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to make a breaking change to default to 0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Ri7ay
Ri7ay requested review from arkodg and zirain July 7, 2026 07:51
@Ri7ay
Ri7ay force-pushed the client-overall-tracing-sampling branch from f6d80d7 to 32a43f5 Compare July 8, 2026 08:29
Ri7ay and others added 5 commits July 8, 2026 21:54
Signed-off-by: Zakhar Zakharov <zakhar.zakharov.zz16@gmail.com>
Signed-off-by: Zakhar Zakharov <zakhar.zakharov.zz16@gmail.com>
Signed-off-by: z.s.zakharov <z.s.zakharov@tinkoff.ru>
Signed-off-by: Zakhar Zakharov <zakhar.zakharov.zz16@gmail.com>
Signed-off-by: z.s.zakharov <z.s.zakharov@tinkoff.ru>
@zirain
zirain force-pushed the client-overall-tracing-sampling branch from 268a3d2 to c9adef9 Compare July 8, 2026 13:54
@@ -0,0 +1 @@
Added support for configuring Envoy tracing client and overall sampling fractions on EnvoyProxy and BackendTrafficPolicy tracing settings.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should also documented the breaking change of clientSamplingRate.

@Ri7ay Ri7ay Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create file in breaking_changes

Signed-off-by: z.s.zakharov <z.s.zakharov@tinkoff.ru>
@Ri7ay
Ri7ay requested a review from zirain July 8, 2026 14:28
@zirain

zirain commented Jul 10, 2026

Copy link
Copy Markdown
Member

/retest

zirain
zirain previously approved these changes Jul 10, 2026
@Ri7ay

Ri7ay commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

/retest

// selected for tracing after all other sampling checks have been applied.
//
// +optional
OverallSamplingFraction *gwapiv1.Fraction `json:"overallSamplingFraction,omitempty"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we avoid OverallSamplingFraction since ClientSamplingFraction now defaults to 0 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d keep OverallSamplingFraction. ClientSamplingFraction=0 only disables client-triggered tracing via x-client-trace-id, while OverallSamplingFraction is still useful as the final cap on total trace volume across all sampling paths.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok lets keep it, if we think this is a legit use case,

      samplingRate: 1
      clientSamplingRate: 50
      overallSamplingRate: 10

my preference would be to set explicit individual rates, vs a global cap, wdyt @envoyproxy/gateway-maintainers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ri7ay
Ri7ay requested a review from arkodg July 12, 2026 22:50
Comment thread internal/xds/translator/route.go Outdated
op, upstreamOp := buildTracingOperation(tracing.SpanName)

return &routev3.Tracing{
ClientSampling: fractionalpercent.FromFraction(tracing.ClientSamplingFraction),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be set to 0 if val is nil

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Signed-off-by: Zakhar Zakharov <zakhar.zakharov.zz16@gmail.com>
@zirain

zirain commented Jul 17, 2026

Copy link
Copy Markdown
Member

/retest

@Ri7ay

Ri7ay commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@arkodg
arkodg merged commit 3c50bdd into envoyproxy:main Jul 18, 2026
108 of 120 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support configuring client_sampling and overall_sampling for tracing in EnvoyProxy

3 participants