Skip to content

Commit

Permalink
contrib/net/http: harmonize benchmarks for v2 (#2619)
Browse files Browse the repository at this point in the history
  • Loading branch information
darccio authored Mar 19, 2024
1 parent b4da5f8 commit a1de76b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
5 changes: 3 additions & 2 deletions contrib/net/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/mocktracer"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
"gopkg.in/DataDog/dd-trace-go.v1/internal/normalizer"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -496,8 +497,8 @@ func handler500(w http.ResponseWriter, _ *http.Request) {
}

func BenchmarkHttpServeTrace(b *testing.B) {
mt := mocktracer.Start()
defer mt.Stop()
tracer.Start(tracer.WithLogger(log.DiscardLogger{}))
defer tracer.Stop()
header, tag := normalizer.HeaderTag("3header")
globalconfig.SetHeaderTag(header, tag)

Expand Down
15 changes: 8 additions & 7 deletions contrib/net/http/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,15 @@ func BenchmarkTraceAndServe(b *testing.B) {
if err != nil {
b.Fatal(err)
}
cfg := ServeConfig{
Service: "service-name",
Resource: "resource-name",
FinishOpts: []ddtrace.FinishOption{},
SpanOpts: []ddtrace.StartSpanOption{},
QueryParams: false,
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
cfg := ServeConfig{
Service: "service-name",
Resource: "resource-name",
FinishOpts: []ddtrace.FinishOption{},
SpanOpts: []ddtrace.StartSpanOption{},
QueryParams: false,
}
TraceAndServe(handler, noopWriter{}, req, &cfg)
}
}
1 change: 1 addition & 0 deletions ddtrace/tracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2046,6 +2046,7 @@ func BenchmarkTracerAddSpans(b *testing.B) {
tracer, _, _, stop := startTestTracer(b, WithLogger(log.DiscardLogger{}), WithSampler(NewRateSampler(0)))
defer stop()

b.ResetTimer()
for n := 0; n < b.N; n++ {
span := tracer.StartSpan("pylons.request", ServiceName("pylons"), ResourceName("/"))
span.Finish()
Expand Down

0 comments on commit a1de76b

Please sign in to comment.