Skip to content

Commit

Permalink
issues/11: Add sampling. (#13)
Browse files Browse the repository at this point in the history
This adds head based sampling. 
In future we should probably add tail based sampling; #14
  • Loading branch information
komuw authored Sep 7, 2023
1 parent 5dc4395 commit 903452e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
}
defer func() {
err := tp.Shutdown(ctx)
_ = err
fmt.Println("error when shutting down tracingProvider. err: ", err)
}()

mp, err := setupMetrics(ctx, serviceName)
Expand All @@ -41,7 +41,7 @@ func main() {
}
defer func() {
err := mp.Shutdown(ctx)
_ = err
fmt.Println("error when shutting down metricsProvider. err: ", err)
}()
}

Expand Down
14 changes: 11 additions & 3 deletions tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,17 @@ func setupTracing(ctx context.Context, serviceName string) (*trace.TracerProvide
trace.WithBatcher(exporter), // use batch in prod.
trace.WithResource(resource),
trace.WithSpanProcessor(loggingSpanProcessor{}),
// see: https://github.com/komuw/otero/issues/11
// In prod, you should consider using the TraceIDRatioBased sampler with the ParentBased sampler.
// sdktrace.WithSampler(sdktrace.AlwaysSample()),
trace.WithSampler(
// Sample 30%
//
// There's head-based sampling and tail-based sampling.
// Tail based sampling would enable you to say something like;
// `Sample 5% of success but 100% of all the errors.`
//
// What we have implemented here is head-based sampling.
// See: https://github.com/komuw/otero/issues/11 (and the links therein)
trace.ParentBased(trace.TraceIDRatioBased(0.3)),
),
)

/*
Expand Down

0 comments on commit 903452e

Please sign in to comment.