Skip to content

Commit

Permalink
fix(instrumentation/httptrace): remove extra allocations from pre-app…
Browse files Browse the repository at this point in the history
…ending two tags by using options.Expand
  • Loading branch information
darccio committed Jan 23, 2025
1 parent d3d1f1f commit eab62f1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions instrumentation/httptrace/before_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/DataDog/dd-trace-go/v2/ddtrace/ext"
"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
"github.com/DataDog/dd-trace-go/v2/instrumentation/appsec/emitter/httpsec"
"github.com/DataDog/dd-trace-go/v2/instrumentation/options"
"github.com/DataDog/dd-trace-go/v2/internal/appsec"
)

Expand Down Expand Up @@ -45,8 +46,10 @@ func BeforeHandle(cfg *ServeConfig, w http.ResponseWriter, r *http.Request) (htt
if cfg == nil {
cfg = new(ServeConfig)
}
opts := make([]tracer.StartSpanOption, len(cfg.SpanOpts))
copy(opts, cfg.SpanOpts)
opts := options.Expand(cfg.SpanOpts, 2, 3)
// Pre-append span.kind and component tags to the options so that they can be overridden.
opts[0] = tracer.Tag(ext.SpanKind, ext.SpanKindServer)
opts[1] = tracer.Tag(ext.Component, "net/http")
if cfg.Service != "" {
opts = append(opts, tracer.ServiceName(cfg.Service))
}
Expand All @@ -56,8 +59,6 @@ func BeforeHandle(cfg *ServeConfig, w http.ResponseWriter, r *http.Request) (htt
if cfg.Route != "" {
opts = append(opts, tracer.Tag(ext.HTTPRoute, cfg.Route))
}
// Pre-append span.kind and component tags to the options so that they can be overridden.
opts = append([]tracer.StartSpanOption{tracer.Tag(ext.SpanKind, ext.SpanKindServer), tracer.Tag(ext.Component, "net/http")}, opts...)
span, ctx := StartRequestSpan(r, opts...)
rw, ddrw := wrapResponseWriter(w)
rt := r.WithContext(ctx)
Expand Down

0 comments on commit eab62f1

Please sign in to comment.