Skip to content

Commit

Permalink
add propagation parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Eliott Bouhana <[email protected]>
  • Loading branch information
eliottness committed Dec 18, 2024
1 parent 417acf0 commit ab2ab40
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 16 additions & 1 deletion ddtrace/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,14 @@ func (t *tracer) Inject(ctx ddtrace.SpanContext, carrier interface{}) error {
if !t.config.enabled.current {
return nil
}

if t.config.tracingAsTransport {
// in tracing as transport mode, only propagate when there is an upstream appsec event
if ctx, ok := ctx.(*spanContext); ok && ctx.trace != nil && ctx.trace.propagatingTag("_dd.p.appsec") == "" {
return nil
}
}

t.updateSampling(ctx)
return t.config.propagator.Inject(ctx, carrier)
}
Expand Down Expand Up @@ -773,7 +781,14 @@ func (t *tracer) Extract(carrier interface{}) (ddtrace.SpanContext, error) {
if !t.config.enabled.current {
return internal.NoopSpanContext{}, nil
}
return t.config.propagator.Extract(carrier)
ctx, err := t.config.propagator.Extract(carrier)
if t.config.tracingAsTransport {
// in tracing as transport mode, reset upstream sampling decision to make sure we keep 1 trace/minute
if ctx, ok := ctx.(*spanContext); ok && ctx.trace != nil && ctx.trace.propagatingTag("_dd.p.appsec") == "" {
ctx.trace.priority = nil
}
}
return ctx, err
}

// sampleRateMetricKey is the metric key holding the applied sample rate. Has to be the same as the Agent.
Expand Down
2 changes: 2 additions & 0 deletions internal/appsec/listener/waf/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ func SetEventSpanTags(span trace.TagSetter, events []any) error {
span.SetTag("_dd.origin", "appsec")
// Set the appsec.event tag needed by the appsec backend
span.SetTag("appsec.event", true)
span.SetTag("_dd.p.appsec", "1")
span.SetTag("_sampling_priority_v1", "2")
return nil
}

Expand Down

0 comments on commit ab2ab40

Please sign in to comment.