Skip to content

Commit

Permalink
remove spanID and nested event span_id
Browse files Browse the repository at this point in the history
Signed-off-by: Eliott Bouhana <eliott.bouhana@datadoghq.com>
  • Loading branch information
eliottness authored and Hellzy committed May 23, 2024
1 parent d5fa495 commit fb1fd87
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
14 changes: 3 additions & 11 deletions contrib/net/http/roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec"
"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/emitter/httpsec"
"math"
"math/rand"
"net/http"
"os"
"strconv"
Expand Down Expand Up @@ -43,11 +42,6 @@ func (rt *roundTripper) RoundTrip(req *http.Request) (res *http.Response, err er
tracer.Tag(ext.SpanKind, ext.SpanKindClient),
tracer.Tag(ext.NetworkDestinationName, url.Hostname()),
}
var appsecSpanID uint64
if appsec.Enabled() {
appsecSpanID = rand.Uint64()
opts = append(opts, tracer.WithSpanID(appsecSpanID))
}
if !math.IsNaN(rt.cfg.analyticsRate) {
opts = append(opts, tracer.Tag(ext.EventSampleRate, rt.cfg.analyticsRate))
}
Expand Down Expand Up @@ -85,11 +79,9 @@ func (rt *roundTripper) RoundTrip(req *http.Request) (res *http.Response, err er
}
if appsec.Enabled() {
res, err = httpsec.RoundTrip(httpsec.RoundTripArgs{
SpanID: appsecSpanID,
Span: span,
Ctx: ctx,
Req: r2,
Rt: rt.base,
Ctx: ctx,
Req: r2,
Rt: rt.base,
})
} else {
res, err = rt.base.RoundTrip(r2)
Expand Down
3 changes: 1 addition & 2 deletions internal/appsec/emitter/httpsec/roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ type RoundTripArgs struct {
func RoundTrip(args RoundTripArgs) (*http.Response, error) {
url := args.Req.URL.String()
opArgs := types.RoundTripOperationArgs{
URL: url,
SpanID: args.SpanID,
URL: url,
}

parent := fromContext(args.Ctx)
Expand Down
3 changes: 1 addition & 2 deletions internal/appsec/emitter/httpsec/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ type (
SDKBodyOperationRes struct{}

RoundTripOperationArgs struct {
URL string
SpanID uint64
URL string
}

RoundTripOperationRes struct{}
Expand Down
19 changes: 9 additions & 10 deletions internal/appsec/listener/sharedsec/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ package sharedsec

import (
"encoding/json"

"github.com/DataDog/appsec-internal-go/limiter"
waf "github.com/DataDog/go-libddwaf/v3"
"github.com/DataDog/go-libddwaf/v3/errors"
"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/dyngo"
"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/emitter/httpsec/types"
"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/emitter/sharedsec"
Expand All @@ -29,8 +31,8 @@ const (

func RunWAF(wafCtx *waf.Context, values waf.RunAddressData) waf.Result {
result, err := wafCtx.Run(values)
if err == waf.ErrTimeout {
log.Debug("appsec: waf timeout value of reached: %v", err)
if err == errors.ErrTimeout {
log.Debug("appsec: waf timeout value reached: %v", err)
} else if err != nil {
log.Error("appsec: unexpected waf error: %v", err)
}
Expand Down Expand Up @@ -132,14 +134,11 @@ func RegisterRoundTripper(op operationWithEvents, wafCtx *waf.Context, limiter l
wafResult := RunWAF(wafCtx, waf.RunAddressData{Persistent: map[string]any{ServerIoNetURLAddr: args.URL}})

// TODO: stacktrace
if wafResult.HasEvents() {
// TODO: put this in dyngo
for _, event := range wafResult.Events {
event.(map[string]any)["span_id"] = args.SpanID
}

AddSecurityEvents(op, limiter, wafResult.Events)
log.Debug("appsec: WAF detected a suspicious outgoing request URL: %s", args.URL)
if !wafResult.HasEvents() {
return
}

AddSecurityEvents(op, limiter, wafResult.Events)
log.Debug("appsec: WAF detected a suspicious outgoing request URL: %s", args.URL)
})
}

0 comments on commit fb1fd87

Please sign in to comment.