Skip to content

feat(telemetry): add sampler config for OpenTelemetry tracing#8529

Open
codefromthecrypt wants to merge 3 commits intoenvoyproxy:mainfrom
codefromthecrypt:feat/otel-sampler
Open

feat(telemetry): add sampler config for OpenTelemetry tracing#8529
codefromthecrypt wants to merge 3 commits intoenvoyproxy:mainfrom
codefromthecrypt:feat/otel-sampler

Conversation

@codefromthecrypt
Copy link
Copy Markdown
Contributor

@codefromthecrypt codefromthecrypt commented Mar 16, 2026

What type of PR is this?
feat(telemetry): add new feature

What this PR does / why we need it:
Adds sampler to OpenTelemetryTracingProvider, supporting the standard OTEL sampler types as a discriminated union:

sampler.type Discriminated fields
AlwaysOn
AlwaysOff
TraceIdRatioBased samplingPercentage (default 100%)
ParentBasedAlwaysOn
ParentBasedAlwaysOff
ParentBasedTraceIdRatioBased samplingPercentage (default 100%)

Example (respect parent, drop all root spans):

openTelemetry:
  sampler:
    type: ParentBasedTraceIdRatioBased
    samplingPercentage:
      numerator: 0

Notes

samplingPercentage uses Envoy's native FractionalPercent arg type for parity, even though SDKs are not uniform in the parameter name for TraceIdRatioBased. This does not support automatic coercion of the
OTEL_TRACES_SAMPLER_ARG env var value, but maintains value consistency with the sampler name.

When a sampler is configured, HCM RandomSampling is set to 100% so the sampler alone decides whether to record spans. Otherwise, HCM would drop requests before the sampler runs, making configurations like AlwaysOff or ParentBased behave incorrectly.

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

Release Notes: Yes

@codefromthecrypt codefromthecrypt requested a review from a team as a code owner March 16, 2026 02:38
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 16, 2026

Deploy Preview for cerulean-figolla-1f9435 ready!

Name Link
🔨 Latest commit fc4af84
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/69ca73b44ff89d0008dc25ba
😎 Deploy Preview https://deploy-preview-8529--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
Copy link
Copy Markdown

codecov bot commented Mar 16, 2026

Codecov Report

❌ Patch coverage is 81.33333% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.37%. Comparing base (4768ca7) to head (fc4af84).

Files with missing lines Patch % Lines
internal/xds/translator/tracing.go 81.33% 7 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8529      +/-   ##
==========================================
- Coverage   74.38%   74.37%   -0.02%     
==========================================
  Files         243      243              
  Lines       38164    38238      +74     
==========================================
+ Hits        28390    28441      +51     
- Misses       7789     7806      +17     
- Partials     1985     1991       +6     

☔ View full report in Codecov by Sentry.
📢 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.

@codefromthecrypt codefromthecrypt marked this pull request as draft March 16, 2026 23:02
@codefromthecrypt codefromthecrypt marked this pull request as ready for review March 17, 2026 00:56
// SamplingPercentage controls the percentage of traces to sample.
// Defaults to 100% when not set.
// +optional
SamplingPercentage *gwapiv1.Fraction `json:"samplingPercentage,omitempty"`
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.

this name and type doesn't match otel, but it does match envoy. good enough as we need to map otel env externally anyway now

@zhaohuabing
Copy link
Copy Markdown
Member

Two more nits - sorry I didn't mention them in the previous comment.

Otherwise LGTM!

zirain
zirain previously approved these changes Mar 19, 2026
@codefromthecrypt
Copy link
Copy Markdown
Contributor Author

/retest

@codefromthecrypt codefromthecrypt force-pushed the feat/otel-sampler branch 2 times, most recently from 2371ec8 to d22468c Compare March 25, 2026 22:54
Add OTelSampler to OpenTelemetryTracingProvider, supporting the standard
OTEL sampler types. The type field maps to OTEL_TRACES_SAMPLER, with CEL
validation ensuring samplingPercentage is only set for ratio-based types:

- AlwaysOn, AlwaysOff, ParentBasedAlwaysOn, ParentBasedAlwaysOff: no
  additional config
- TraceIdRatioBased, ParentBasedTraceIdRatioBased: optional
  samplingPercentage (gwapiv1.Fraction, defaults to 100%)

samplingPercentage uses Envoy native FractionalPercent arg type for
parity. This does not support automatic coercion of the
OTEL_TRACES_SAMPLER_ARG env var value, but maintains value consistency
with the sampler name.

When a sampler is configured, HCM RandomSampling is set to 100% so the
sampler alone decides whether to record spans.

Fixes envoyproxy#8476

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
@codefromthecrypt
Copy link
Copy Markdown
Contributor Author

hey folks.. could this be the day sampling is merged? 🚢

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.

Envoy Gateway - support tracing sampler configuration

3 participants