Skip to content

Commit 7971769

Browse files
authored
feat: support OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG settings (#1534) (#1577)
Add support for configuring interceptor trace sampling via OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG. Signed-off-by: Mikhail Fedosin <[email protected]>
1 parent 4b082d7 commit 7971769

4 files changed

Lines changed: 5 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ This changelog keeps track of work items that have been completed and are ready
3939
### Improvements
4040

4141
- **General**: TODO ([#TODO](https://github.com/kedacore/http-add-on/issues/TODO))
42+
- **Interceptor**: Support `OTEL_TRACES_SAMPLER` and `OTEL_TRACES_SAMPLER_ARG` for trace sampling configuration ([#1534](https://github.com/kedacore/http-add-on/issues/1534))
4243

4344
### Fixes
4445

interceptor/config/tracing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
type Tracing struct {
99
// States whether tracing should be enabled, False by default
1010
Enabled bool `env:"OTEL_EXPORTER_OTLP_TRACES_ENABLED" envDefault:"false"`
11-
// Sets what tracing export to use, must be one of: console,http/protobuf, grpc
11+
// Sets what tracing export to use, must be one of: console, http/protobuf, grpc
1212
Exporter string `env:"OTEL_EXPORTER_OTLP_TRACES_PROTOCOL" envDefault:"console"`
1313
}
1414

interceptor/tracing/tracing.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/kedacore/http-add-on/interceptor/config"
1818
)
1919

20-
var serviceName = "keda-http-interceptor"
20+
const serviceName = "keda-http-interceptor"
2121

2222
func SetupOTelSDK(ctx context.Context, tCfg config.Tracing) (shutdown func(context.Context) error, err error) {
2323
var shutdownFuncs []func(context.Context) error
@@ -79,7 +79,6 @@ func newTraceProvider(ctx context.Context, res *resource.Resource, tCfg config.T
7979
}
8080

8181
traceProvider := trace.NewTracerProvider(
82-
trace.WithSampler(trace.AlwaysSample()),
8382
trace.WithBatcher(traceExporter),
8483
trace.WithResource(res),
8584
)

interceptor/tracing/tracing_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import (
99
)
1010

1111
func TestTracingConfig(t *testing.T) {
12+
t.Setenv("OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", "console")
13+
1214
tracingCfg := config.MustParseTracing()
1315
tracingCfg.Enabled = true
1416

15-
// check defaults are set correctly
1617
assert.Equal(t, "console", tracingCfg.Exporter)
1718
assert.True(t, tracingCfg.Enabled)
1819
}

0 commit comments

Comments
 (0)