From d80074c5d22f43869e7d1cfac48d6070c7dde896 Mon Sep 17 00:00:00 2001 From: Ashley Jeffs Date: Wed, 14 Feb 2024 17:00:24 +0000 Subject: [PATCH] Tidy up some fields --- CHANGELOG.md | 1 + internal/impl/otlp/tracer_otlp.go | 19 ++++++++++--------- .../tracers/open_telemetry_collector.md | 13 +++++++++++-- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5187ab2c91..629338ad65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file. - Field `read_header` added to the `amqp_1` input. - A debug endpoint `/debug/pprof/allocs` has been added for profiling allocations. - New `cockroachdb_changefeed` input. +- The `open_telemetry_collector` tracer now supports sampling. ### Fixed diff --git a/internal/impl/otlp/tracer_otlp.go b/internal/impl/otlp/tracer_otlp.go index 9e87fcddcf..460e211dc8 100644 --- a/internal/impl/otlp/tracer_otlp.go +++ b/internal/impl/otlp/tracer_otlp.go @@ -39,19 +39,18 @@ func init() { ).Description("A list of grpc collectors.")). Field(service.NewStringMapField("tags"). Description("A map of tags to add to all tracing spans."). - Default(map[string]string{}). + Default(map[string]any{}). Advanced()). Field(service.NewObjectField("sampling", service.NewBoolField("enabled"). Description("Whether to enable sampling."). - Default(false). - Optional(), + Default(false), service.NewFloatField("ratio"). Description("Sets the ratio of traces to sample."). - Default(1.0). - Advanced(). + Examples(0.85, 0.5). Optional()). - Description("Settings for trace sampling. Sampling is recommended for high-volume production workloads.")) + Description("Settings for trace sampling. Sampling is recommended for high-volume production workloads."). + Version("4.25.0")) err := service.RegisterOtelTracerProvider( "open_telemetry_collector", @@ -146,9 +145,11 @@ func sampleConfigFromParsed(conf *service.ParsedConfig) (sampleConfig, error) { return sampleConfig{}, err } - ratio, err := conf.FieldFloat("ratio") - if err != nil { - return sampleConfig{}, err + var ratio float64 + if conf.Contains("ratio") { + if ratio, err = conf.FieldFloat("ratio"); err != nil { + return sampleConfig{}, err + } } return sampleConfig{ diff --git a/website/docs/components/tracers/open_telemetry_collector.md b/website/docs/components/tracers/open_telemetry_collector.md index 7f5ac8a278..9cb6b42aa5 100644 --- a/website/docs/components/tracers/open_telemetry_collector.md +++ b/website/docs/components/tracers/open_telemetry_collector.md @@ -34,6 +34,7 @@ tracer: grpc: [] # No default (required) sampling: enabled: false + ratio: 0.85 # No default (optional) ``` @@ -48,7 +49,7 @@ tracer: tags: {} sampling: enabled: false - ratio: 1 + ratio: 0.85 # No default (optional) ``` @@ -116,6 +117,7 @@ Settings for trace sampling. Sampling is recommended for high-volume production Type: `object` +Requires version 4.25.0 or newer ### `sampling.enabled` @@ -131,6 +133,13 @@ Sets the ratio of traces to sample. Type: `float` -Default: `1` + +```yml +# Examples + +ratio: 0.85 + +ratio: 0.5 +```