Skip to content

Add configurable client_sampling and random_sampling for tracing#7373

Merged
tsaarni merged 3 commits into
projectcontour:mainfrom
WUMUXIAN:tracing-configurable-client-random-sampling
Jan 30, 2026
Merged

Add configurable client_sampling and random_sampling for tracing#7373
tsaarni merged 3 commits into
projectcontour:mainfrom
WUMUXIAN:tracing-configurable-client-random-sampling

Conversation

@WUMUXIAN
Copy link
Copy Markdown
Contributor

@WUMUXIAN WUMUXIAN commented Jan 14, 2026

Add configurable client_sampling and random_sampling for tracing
Pull Request Description:
This PR implements the feature requested in issue #7271, allowing users to configure clientSampling and randomSampling rates for Contour's tracing configuration in addition to the existing overallSampling.

Summary

  • Adds ClientSampling and RandomSampling fields to the TracingConfig API struct
  • Updates internal processing to parse and set these values with defaults of 100%
  • Modifies Envoy configuration generation to include the new sampling rates
  • Includes validation for the new fields
  • All tests updated and passing

Changes

  • API: apis/projectcontour/v1alpha1/contourconfig.go
  • Validation: apis/projectcontour/v1alpha1/contourconfig_helpers.go
  • Processing: cmd/contour/serve.go
  • Internal config: internal/xdscache/v3/listener.go, internal/envoy/v3/tracing.go
  • Tests: internal/envoy/v3/tracing_test.go
  • Code generation: Updated deepcopy and other generated files
  • Changelog: changelogs/unreleased/7271-luckyxkw-minor.md

Fixes #7271
Release note: release-note/minor (new feature for enhanced tracing control)

Signed-off-by: Muxian Wu wumuxian1988@gmail.com

@WUMUXIAN WUMUXIAN requested a review from a team as a code owner January 14, 2026 10:54
@WUMUXIAN WUMUXIAN requested review from sunjayBhatia and tsaarni and removed request for a team January 14, 2026 10:54
@sunjayBhatia sunjayBhatia requested review from a team, rajatvig and wilsonwu and removed request for a team January 14, 2026 10:54
@tsaarni tsaarni added the release-note/minor A minor change that needs about a paragraph of explanation in the release notes. label Jan 14, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 14, 2026

Codecov Report

❌ Patch coverage is 72.72727% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.18%. Comparing base (00812a4) to head (6f666eb).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
cmd/contour/serve.go 50.00% 5 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7373      +/-   ##
==========================================
- Coverage   81.85%   81.18%   -0.67%     
==========================================
  Files         130      130              
  Lines       15747    15803      +56     
==========================================
- Hits        12889    12829      -60     
- Misses       2574     2613      +39     
- Partials      284      361      +77     
Files with missing lines Coverage Δ
cmd/contour/servecontext.go 83.88% <100.00%> (-2.75%) ⬇️
internal/envoy/v3/tracing.go 87.71% <100.00%> (-6.40%) ⬇️
internal/xdscache/v3/listener.go 77.31% <100.00%> (-14.62%) ⬇️
pkg/config/parameters.go 78.94% <ø> (-8.17%) ⬇️
cmd/contour/serve.go 22.05% <50.00%> (-1.56%) ⬇️
🚀 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.

@WUMUXIAN
Copy link
Copy Markdown
Contributor Author

hi @wilsonwu @tsaarni @sunjayBhatia, can I get this reviewed?

Copy link
Copy Markdown
Member

@tsaarni tsaarni left a comment

Choose a reason for hiding this comment

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

Thank you @WUMUXIAN for contributing!

It would be great to add more tests. I think you can add the new parameters to this file to help with the test coverage https://github.com/projectcontour/contour/blob/main/internal/featuretests/v3/tracing_test.go.

We should also add the new parameters to the tracing docs here:

Contour supports configuring envoy to export data to OpenTelemetry, and allows users to customize some configurations.
- Custom service name, the default is `contour`.
- Custom sampling rate, the default is `100`.
- Custom the maximum length of the request path, the default is `256`.
- Customize span tags from literal or request headers.
- Customize whether to include the pod's hostname and namespace.

The changelog check is failing. You need to rename the file to ./changelogs/unreleased/7373-WUMUXIAN-minor.md. Right now it uses a different name.

Also, the DCO check is failing. You can fix this by rewriting your git history to remove the extra opencode plan file from your first commit. Or, you can just add a sign-off to the commit that removes it. We squash the PR at the end anyway, but we need all commits to have a sign-off for the check to pass.

Comment thread internal/envoy/v3/tracing_test.go Outdated
@WUMUXIAN WUMUXIAN force-pushed the tracing-configurable-client-random-sampling branch from 0cb98e2 to 9957099 Compare January 21, 2026 10:04
@WUMUXIAN
Copy link
Copy Markdown
Contributor Author

@tsaarni thanks for the review! I have addressed your comments

Copy link
Copy Markdown
Member

@tsaarni tsaarni left a comment

Choose a reason for hiding this comment

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

Thank you @WUMUXIAN!

We should add parameters for the configuration file, for those who do not use ContourConfiguration CRD. Here is diff you could use, with some test changes as well

diff --git a/cmd/contour/servecontext.go b/cmd/contour/servecontext.go
index 8c4ee27d..e7f4a77e 100644
--- a/cmd/contour/servecontext.go
+++ b/cmd/contour/servecontext.go
@@ -413,6 +413,8 @@ func (ctx *serveContext) convertToContourConfigurationSpec() contour_v1alpha1.Co
                        IncludePodDetail: ctx.Config.Tracing.IncludePodDetail,
                        ServiceName:      ctx.Config.Tracing.ServiceName,
                        OverallSampling:  ctx.Config.Tracing.OverallSampling,
+                       ClientSampling:   ctx.Config.Tracing.ClientSampling,
+                       RandomSampling:   ctx.Config.Tracing.RandomSampling,
                        MaxPathTagLength: ctx.Config.Tracing.MaxPathTagLength,
                        CustomTags:       customTags,
                        ExtensionService: &contour_v1alpha1.NamespacedName{
diff --git a/cmd/contour/servecontext_test.go b/cmd/contour/servecontext_test.go
index b3dfee1f..a0678f8f 100644
--- a/cmd/contour/servecontext_test.go
+++ b/cmd/contour/servecontext_test.go
@@ -833,6 +833,8 @@ func TestConvertServeContext(t *testing.T) {
                                        IncludePodDetail: ptr.To(false),
                                        ServiceName:      ptr.To("contour"),
                                        OverallSampling:  ptr.To("100"),
+                                       ClientSampling:   ptr.To("75"),
+                                       RandomSampling:   ptr.To("50"),
                                        MaxPathTagLength: ptr.To(uint32(256)),
                                        CustomTags: []config.CustomTag{
                                                {
@@ -853,6 +855,8 @@ func TestConvertServeContext(t *testing.T) {
                                        IncludePodDetail: ptr.To(false),
                                        ServiceName:      ptr.To("contour"),
                                        OverallSampling:  ptr.To("100"),
+                                       ClientSampling:   ptr.To("75"),
+                                       RandomSampling:   ptr.To("50"),
                                        MaxPathTagLength: ptr.To(uint32(256)),
                                        CustomTags: []*contour_v1alpha1.CustomTag{
                                                {
diff --git a/pkg/config/parameters.go b/pkg/config/parameters.go
index 1e4c397d..afb0e09b 100644
--- a/pkg/config/parameters.go
+++ b/pkg/config/parameters.go
@@ -727,6 +727,14 @@ type Tracing struct {
        // the default value is 100.
        OverallSampling *string `yaml:"overallSampling,omitempty"`
 
+       // ClientSampling defines the sampling rate when x-client-trace-id header is set.
+       // the default value is 100.
+       ClientSampling *string `yaml:"clientSampling,omitempty"`
+
+       // RandomSampling defines the random sampling rate for all requests.
+       // the default value is 100.
+       RandomSampling *string `yaml:"randomSampling,omitempty"`
+
        // MaxPathTagLength defines maximum length of the request path
        // to extract and include in the HttpUrl tag.
        // the default value is 256.
diff --git a/pkg/config/parameters_test.go b/pkg/config/parameters_test.go
index 6d689619..0fd66f82 100644
--- a/pkg/config/parameters_test.go
+++ b/pkg/config/parameters_test.go
@@ -682,6 +682,8 @@ func TestTracingConfigValidation(t *testing.T) {
                IncludePodDetail: ptr.To(false),
                ServiceName:      ptr.To("contour"),
                OverallSampling:  ptr.To("100"),
+               ClientSampling:   ptr.To("50"),
+               RandomSampling:   ptr.To("75"),
                MaxPathTagLength: ptr.To(uint32(256)),
                CustomTags:       nil,
                ExtensionService: "projectcontour/otel-collector",
@@ -700,6 +702,8 @@ func TestTracingConfigValidation(t *testing.T) {
        trace = &Tracing{
                IncludePodDetail: ptr.To(false),
                OverallSampling:  ptr.To("100"),
+               ClientSampling:   ptr.To("75"),
+               RandomSampling:   ptr.To("50"),
                MaxPathTagLength: ptr.To(uint32(256)),
                CustomTags:       nil,
                ExtensionService: "projectcontour/otel-collector",

Comment thread changelogs/unreleased/7373-WUMUXIAN-minor.md
@WUMUXIAN WUMUXIAN force-pushed the tracing-configurable-client-random-sampling branch from ad61d6c to c2c907e Compare January 22, 2026 02:29
@WUMUXIAN
Copy link
Copy Markdown
Contributor Author

@tsaarni addressed the comments again! thank you

…or tracing

Add ClientSampling and RandomSampling fields to TracingConfig
to allow configurable client_sampling and random_sampling in Envoy tracing.

Updates projectcontour#7271

Signed-off-by: Muxian Wu <muxianw@twitter.com>
@WUMUXIAN WUMUXIAN force-pushed the tracing-configurable-client-random-sampling branch from fa30bc2 to f03ad29 Compare January 22, 2026 07:53
@WUMUXIAN
Copy link
Copy Markdown
Contributor Author

@tsaarni I also squashed everything into 1 commit as the number has grown quite a bit..

Signed-off-by: Muxian Wu <muxianw@twitter.com>
Copy link
Copy Markdown
Member

@tsaarni tsaarni left a comment

Choose a reason for hiding this comment

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

@WUMUXIAN Sorry it took me a while to get back to this. I've added a few more comments.

You can find a diff here that you can use if you want: https://gist.githubusercontent.com/tsaarni/ad3bea53a9ce621444e2caff368d146d/raw/a129a2e3eb44d30381173b5ff75e0a871ce4360b/gistfile0.txt

Comment thread cmd/contour/serve_test.go Outdated
Comment thread site/content/docs/main/config/tracing.md Outdated
Comment thread pkg/config/parameters.go Outdated
Comment thread pkg/config/parameters_test.go Outdated
Signed-off-by: Muxian Wu <muxianw@twitter.com>
@WUMUXIAN WUMUXIAN force-pushed the tracing-configurable-client-random-sampling branch from 6941803 to 6f666eb Compare January 30, 2026 05:23
@WUMUXIAN
Copy link
Copy Markdown
Contributor Author

@tsaarni addressed comments

Copy link
Copy Markdown
Member

@tsaarni tsaarni left a comment

Choose a reason for hiding this comment

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

@WUMUXIAN Thank You for contributing!

@tsaarni tsaarni merged commit 8a51282 into projectcontour:main Jan 30, 2026
25 of 26 checks passed
@WUMUXIAN
Copy link
Copy Markdown
Contributor Author

@tsaarni happy to do so! can you please take a look at #7372 too? I want to be able to se ja3/ja4, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/minor A minor change that needs about a paragraph of explanation in the release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracing should allow configurable client_sampling and random_sampling

3 participants