Skip to content

Commit

Permalink
feat: add trace sampler with configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
1995parham committed Sep 16, 2024
1 parent 90ec5b2 commit 1be209c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion internal/infra/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// Default return default configuration.
func Default() Config {
// nolint: exhaustruct
// nolint: exhaustruct, mnd
return Config{
Logger: logger.Config{
Level: "debug",
Expand All @@ -24,6 +24,7 @@ func Default() Config {
Trace: telemetry.Trace{
Enabled: true,
Endpoint: "127.0.0.1:4317",
Ratio: 0.1,
},
},
NATS: cmq.Config{
Expand Down
5 changes: 3 additions & 2 deletions internal/infra/telemetry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Meter struct {
}

type Trace struct {
Enabled bool `json:"enabled,omitempty" koanf:"enabled"`
Endpoint string `json:"endpoint,omitempty" koanf:"endpoint"`
Enabled bool `json:"enabled,omitempty" koanf:"enabled"`
Endpoint string `json:"endpoint,omitempty" koanf:"endpoint"`
Ratio float64 `json:"ratio,omitempty" koanf:"ratio"`
}
6 changes: 5 additions & 1 deletion internal/infra/telemetry/provide.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ func Provide(lc fx.Lifecycle, cfg Config) Telemetery {
}

bsp := trace.NewBatchSpanProcessor(exporter)
tp := trace.NewTracerProvider(trace.WithSpanProcessor(bsp), trace.WithResource(res))
tp := trace.NewTracerProvider(
trace.WithSpanProcessor(bsp),
trace.WithSampler(trace.ParentBased(trace.TraceIDRatioBased(cfg.Trace.Ratio))),
trace.WithResource(res),
)

mp := metric.NewMeterProvider(metric.WithResource(res), metric.WithReader(reader))

Expand Down

0 comments on commit 1be209c

Please sign in to comment.