chore: revert dropping spans generated by gcs storage clients (#20133)

This commit is contained in:
Ashwanth
2025-12-05 14:13:37 +01:00
committed by GitHub
parent 635934869d
commit 9bd5d6a7d0
4 changed files with 5 additions and 65 deletions
+2 -17
View File
@@ -26,11 +26,9 @@ import (
"github.com/grafana/dskit/tracing"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/version"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
"github.com/grafana/loki/v3/pkg/loki"
loki_runtime "github.com/grafana/loki/v3/pkg/runtime"
loki_tracing "github.com/grafana/loki/v3/pkg/tracing"
"github.com/grafana/loki/v3/pkg/util"
_ "github.com/grafana/loki/v3/pkg/util/build"
"github.com/grafana/loki/v3/pkg/util/cfg"
@@ -107,21 +105,8 @@ func main() {
}
if config.Tracing.Enabled {
var opts []tracesdk.TracerProviderOption
if config.Tracing.FilterGCSSpans {
// We wrap the default sampler with a GCS span filter to drop spans from the GCS client,
// which creates one span per request with no built-in way to disable tracing.
opts = append(opts,
tracesdk.WithSampler(loki_tracing.NewGCSSpanFilter(tracesdk.ParentBased(tracesdk.AlwaysSample()))),
)
}
// Setting the environment variable JAEGER_AGENT_HOST enables tracing.
trace, err := tracing.NewOTelOrJaegerFromEnv(
fmt.Sprintf("loki-%s", config.Target),
util_log.Logger,
tracing.WithTracerProviderOptions(opts...),
)
// Setting the environment variable JAEGER_AGENT_HOST enables tracing
trace, err := tracing.NewOTelOrJaegerFromEnv(fmt.Sprintf("loki-%s", config.Target), util_log.Logger)
if err != nil {
level.Error(util_log.Logger).Log("msg", "error in initializing tracing. tracing will not be enabled", "err", err)
}
-6
View File
@@ -7846,12 +7846,6 @@ Configuration for `tracing`.
# Set to false to disable tracing.
# CLI flag: -tracing.enabled
[enabled: <boolean> | default = true]
# Set to true to drops all spans from the GCS client library. This prevents the
# GCS client from creating millions of spans in high-throughput production
# environments.
# CLI flag: -tracing.filter-gcs-spans
[filter_gcs_spans: <boolean> | default = true]
```
<!-- vale Grafana.Spelling = YES -->
+3 -5
View File
@@ -5,15 +5,13 @@ import (
)
type Config struct {
Enabled bool `yaml:"enabled"`
FilterGCSSpans bool `yaml:"filter_gcs_spans"`
Enabled bool `yaml:"enabled"`
}
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
cfg.RegisterFlagsWithPrefix("tracing.", f)
f.BoolVar(&cfg.Enabled, "tracing.enabled", true, "Set to false to disable tracing.")
}
func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
f.BoolVar(&cfg.Enabled, prefix+"enabled", true, "Set to false to disable tracing.")
f.BoolVar(&cfg.FilterGCSSpans, prefix+"filter-gcs-spans", true, "Set to true to drops all spans from the GCS client library. This prevents the GCS client from creating millions of spans in high-throughput production environments.")
f.BoolVar(&cfg.Enabled, prefix+"tracing.enabled", true, "Set to false to disable tracing.")
}
-37
View File
@@ -1,37 +0,0 @@
package tracing
import (
"strings"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
)
// GCSSpanFilter is a sampler that drops all spans from the GCS client library.
// This prevents the GCS client from creating millions of spans in high-throughput
// production environments, as the client creates one span per request with no
// built-in way to disable tracing.
type GCSSpanFilter struct {
inner tracesdk.Sampler
}
// NewGCSSpanFilter creates a new GCS span filter that wraps the provided inner sampler.
func NewGCSSpanFilter(inner tracesdk.Sampler) *GCSSpanFilter {
return &GCSSpanFilter{
inner: inner,
}
}
// ShouldSample implements tracesdk.Sampler interface.
// It drops all spans from the GCS client and delegates to the inner sampler for all other spans.
func (g *GCSSpanFilter) ShouldSample(parameters tracesdk.SamplingParameters) tracesdk.SamplingResult {
if strings.HasPrefix(parameters.Name, "cloud.google.com/go/storage") {
return tracesdk.SamplingResult{Decision: tracesdk.Drop}
}
return g.inner.ShouldSample(parameters)
}
// Description implements tracesdk.Sampler interface.
func (g *GCSSpanFilter) Description() string {
return "GCSSpanFilter - drops all spans from cloud.google.com/go/storage"
}