Skip to content

Commit

Permalink
adding support for sampling config for nr
Browse files Browse the repository at this point in the history
  • Loading branch information
ankurs committed Sep 10, 2022
1 parent 1e960c7 commit dcfb3cb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import "github.com/go-coldbrew/core/config"
- [type Config](<#type-config>)


## type [Config](<https://github.com/go-coldbrew/core/blob/main/config/config.go#L7-L77>)
## type [Config](<https://github.com/go-coldbrew/core/blob/main/config/config.go#L7-L79>)

```go
type Config struct {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions initializers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -145,7 +145,7 @@ func setupNROpenTelemetry(serviceName, license, version string) {
}

tracerProvider := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.ParentBased(sdktrace.TraceIDRatioBased(0.2))), // sample 20%
sdktrace.WithSampler(sdktrace.ParentBased(sdktrace.TraceIDRatioBased(ratio))), // sample 20%
sdktrace.WithBatcher(otlpExporter),
sdktrace.WithResource(r),
)
Expand Down

0 comments on commit dcfb3cb

Please sign in to comment.