diff --git a/pkg/api/util/util.go b/pkg/api/util/util.go index ed0a216a80133..6aece9c03c648 100644 --- a/pkg/api/util/util.go +++ b/pkg/api/util/util.go @@ -88,7 +88,6 @@ func GetDCAAuthToken() string { // Validate validates an http request func Validate(w http.ResponseWriter, r *http.Request) error { - return nil var err error auth := r.Header.Get("Authorization") if auth == "" { diff --git a/pkg/trace/api/otlp.go b/pkg/trace/api/otlp.go index 1b35cfd8bf1cd..0bf2f22f2c032 100644 --- a/pkg/trace/api/otlp.go +++ b/pkg/trace/api/otlp.go @@ -49,13 +49,14 @@ var _ (ptraceotlp.GRPCServer) = (*OTLPReceiver)(nil) // data on two ports for both plain HTTP and gRPC. type OTLPReceiver struct { ptraceotlp.UnimplementedGRPCServer - wg sync.WaitGroup // waits for a graceful shutdown - grpcsrv *grpc.Server // the running GRPC server on a started receiver, if enabled - out chan<- *Payload // the outgoing payload channel - conf *config.AgentConfig // receiver config - cidProvider IDProvider // container ID provider - statsd statsd.ClientInterface - timing timing.Reporter + wg sync.WaitGroup // waits for a graceful shutdown + grpcsrv *grpc.Server // the running GRPC server on a started receiver, if enabled + out chan<- *Payload // the outgoing payload channel + conf *config.AgentConfig // receiver config + cidProvider IDProvider // container ID provider + statsd statsd.ClientInterface + timing timing.Reporter + ignoreResNames map[string]struct{} } // NewOTLPReceiver returns a new OTLPReceiver which sends any incoming traces down the out channel. @@ -64,8 +65,12 @@ func NewOTLPReceiver(out chan<- *Payload, cfg *config.AgentConfig, statsd statsd if cfg.HasFeature("enable_otlp_compute_top_level_by_span_kind") { computeTopLevelBySpanKindVal = 1.0 } + ignoreResNames := make(map[string]struct{}) + for _, resName := range cfg.Ignore["resource"] { + ignoreResNames[resName] = struct{}{} + } _ = statsd.Gauge("datadog.trace_agent.otlp.compute_top_level_by_span_kind", computeTopLevelBySpanKindVal, nil, 1) - return &OTLPReceiver{out: out, conf: cfg, cidProvider: NewIDProvider(cfg.ContainerProcRoot), statsd: statsd, timing: timing} + return &OTLPReceiver{out: out, conf: cfg, cidProvider: NewIDProvider(cfg.ContainerProcRoot), statsd: statsd, timing: timing, ignoreResNames: ignoreResNames} } // Start starts the OTLPReceiver, if any of the servers were configured as active. @@ -190,9 +195,8 @@ func (o *OTLPReceiver) SetOTelAttributeTranslator(attrstrans *attributes.Transla func (o *OTLPReceiver) ReceiveResourceSpans(ctx context.Context, rspans ptrace.ResourceSpans, httpHeader http.Header) source.Source { if o.conf.HasFeature("enable_receive_resource_spans_v2") { return o.receiveResourceSpansV2(ctx, rspans, httpHeader) - } else { - return o.receiveResourceSpansV1(ctx, rspans, httpHeader) } + return o.receiveResourceSpansV1(ctx, rspans, httpHeader) } func (o *OTLPReceiver) receiveResourceSpansV2(ctx context.Context, rspans ptrace.ResourceSpans, httpHeader http.Header) source.Source { @@ -225,10 +229,6 @@ func (o *OTLPReceiver) receiveResourceSpansV2(ctx context.Context, rspans ptrace // 2. Transform OTLP spans to DD spans. If metadata was missing in resource attributes, attempt to get it from spans topLevelByKind := o.conf.HasFeature("enable_otlp_compute_top_level_by_span_kind") - ignoreResNames := make(map[string]struct{}) - for _, resName := range o.conf.Ignore["resource"] { - ignoreResNames[resName] = struct{}{} - } tracesByID := make(map[uint64]pb.Trace) priorityByID := make(map[uint64]sampler.SamplingPriority) var spancount int64 @@ -236,7 +236,7 @@ func (o *OTLPReceiver) receiveResourceSpansV2(ctx context.Context, rspans ptrace libspans := rspans.ScopeSpans().At(j) for k := 0; k < libspans.Spans().Len(); k++ { otelspan := libspans.Spans().At(k) - if _, exists := ignoreResNames[traceutil.GetOTelResource(otelspan, otelres)]; exists { + if _, exists := o.ignoreResNames[traceutil.GetOTelResource(otelspan, otelres)]; exists { continue } @@ -251,8 +251,9 @@ func (o *OTLPReceiver) receiveResourceSpansV2(ctx context.Context, rspans ptrace } if env == "" { // no env at resource level, try the first span - if v := ddspan.Meta["env"]; v != "" { - env = v + // TODO(songy23): use AttributeDeploymentEnvironmentName once collector version upgrade is unblocked + if spanEnv := traceutil.GetOTelAttrVal(otelspan.Attributes(), false, "deployment.environment.name", semconv.AttributeDeploymentEnvironment); spanEnv != "" { + env = spanEnv } } if containerID == "" { diff --git a/pkg/trace/transform/transform.go b/pkg/trace/transform/transform.go index 9f1ae5928ad84..0748525799bac 100644 --- a/pkg/trace/transform/transform.go +++ b/pkg/trace/transform/transform.go @@ -88,7 +88,8 @@ func OtelSpanToDDSpan( for k, v := range rattr { if k == "service.name" || k == "operation.name" || k == "resource.name" || k == "span.type" { continue - } else if k == "analytics.event" { + } + if k == "analytics.event" { if v, err := strconv.ParseBool(v); err == nil { if v { traceutil.SetMetric(ddspan, sampler.KeySamplingRateEventExtraction, 1) @@ -160,12 +161,6 @@ func OtelSpanToDDSpan( return true }) - if _, ok := ddspan.Meta["env"]; !ok { - // TODO(songy23): use AttributeDeploymentEnvironmentName once collector version upgrade is unblocked - if _, env := GetFirstFromMap(ddspan.Meta, "deployment.environment.name", semconv.AttributeDeploymentEnvironment); env != "" { - traceutil.SetMeta(ddspan, "env", traceutil.NormalizeTag(env)) - } - } if otelspan.TraceState().AsRaw() != "" { traceutil.SetMeta(ddspan, "w3c.tracestate", otelspan.TraceState().AsRaw()) } @@ -368,7 +363,7 @@ func Status2Error(status ptrace.Status, events ptrace.SpanEventSlice, span *pb.S } } -// getFirstFromMap checks each key in the given keys in the map and returns the first key-value pair whose +// GetFirstFromMap checks each key in the given keys in the map and returns the first key-value pair whose // key matches, or empty strings if none matches. func GetFirstFromMap(m map[string]string, keys ...string) (string, string) { for _, key := range keys {