diff --git a/config/README.md b/config/README.md index 46039ce..b0c47f8 100755 --- a/config/README.md +++ b/config/README.md @@ -13,7 +13,7 @@ import "github.com/go-coldbrew/core/config" - [type Config](<#type-config>) -## type [Config]() +## type [Config]() ```go type Config struct { @@ -45,6 +45,8 @@ type Config struct { NewRelicDistributedTracing bool `envconfig:"NEW_RELIC_DISTRIBUTED_TRACING" default:"true"` // Enable new relic opentelemetry NewRelicOpentelemetry bool `envconfig:"NEW_RELIC_OPENTELEMETRY" default:"true"` + // Sampling ratio for NR opentelemetry + NewRelicOpentelemetrySample float64 `envconfig:"NEW_RELIC_OPENTELEMETRY_SAMPLE" default:"0.2"` // DSN for reporting errors to sentry SentryDSN string `envconfig:"SENTRY_DSN" default:""` // Name of this release diff --git a/config/config.go b/config/config.go index 1ee00c7..e3c0b24 100644 --- a/config/config.go +++ b/config/config.go @@ -33,6 +33,8 @@ type Config struct { NewRelicDistributedTracing bool `envconfig:"NEW_RELIC_DISTRIBUTED_TRACING" default:"true"` // Enable new relic opentelemetry NewRelicOpentelemetry bool `envconfig:"NEW_RELIC_OPENTELEMETRY" default:"true"` + // Sampling ratio for NR opentelemetry + NewRelicOpentelemetrySample float64 `envconfig:"NEW_RELIC_OPENTELEMETRY_SAMPLE" default:"0.2"` // DSN for reporting errors to sentry SentryDSN string `envconfig:"SENTRY_DSN" default:""` // Name of this release diff --git a/core.go b/core.go index ba21981..82d17cf 100644 --- a/core.go +++ b/core.go @@ -76,7 +76,7 @@ func (c *cb) processConfig() { grpc_prometheus.EnableHandlingTimeHistogram() } if c.config.NewRelicOpentelemetry { - setupNROpenTelemetry(c.config.AppName, c.config.NewRelicLicenseKey, c.config.ReleaseName) + setupNROpenTelemetry(c.config.AppName, c.config.NewRelicLicenseKey, c.config.ReleaseName, c.config.NewRelicOpentelemetrySample) } } diff --git a/initializers.go b/initializers.go index d2bab81..e06b7ac 100644 --- a/initializers.go +++ b/initializers.go @@ -104,7 +104,7 @@ func setupJaeger(serviceName string) io.Closer { return closer } -func setupNROpenTelemetry(serviceName, license, version string) { +func setupNROpenTelemetry(serviceName, license, version string, ratio float64) { if serviceName == "" || license == "" { log.Info(context.Background(), "msg", "not initializing NR opentelemetry tracing") return @@ -145,7 +145,7 @@ func setupNROpenTelemetry(serviceName, license, version string) { } tracerProvider := sdktrace.NewTracerProvider( - sdktrace.WithSampler(sdktrace.AlwaysSample()), + sdktrace.WithSampler(sdktrace.ParentBased(sdktrace.TraceIDRatioBased(ratio))), // sample 20% sdktrace.WithBatcher(otlpExporter), sdktrace.WithResource(r), )